diff --git a/002_source/cms/src/components/dashboard/lp_categories/_constants.ts b/002_source/cms/src/components/dashboard/lp_categories/_constants.ts index 5e48669..85a6380 100644 --- a/002_source/cms/src/components/dashboard/lp_categories/_constants.ts +++ b/002_source/cms/src/components/dashboard/lp_categories/_constants.ts @@ -17,6 +17,9 @@ export const LpCategoryCreateFormDefault: CreateForm = { export const defaultLpCategory: LpCategory = { id: '', name: '', + cat_name: '', + cat_image: '', + collectionId: '', description: '', isActive: true, order: 1, diff --git a/002_source/cms/src/components/dashboard/lp_categories/confirm-delete-modal.tsx b/002_source/cms/src/components/dashboard/lp_categories/confirm-delete-modal.tsx new file mode 100644 index 0000000..83f4787 --- /dev/null +++ b/002_source/cms/src/components/dashboard/lp_categories/confirm-delete-modal.tsx @@ -0,0 +1,124 @@ +'use client'; + +import * as React from 'react'; +import { useRouter } from 'next/navigation'; +import { COL_LESSON_TYPES } from '@/constants'; +import deleteQuizListening from '@/db/QuizListenings/Delete'; +import { LoadingButton } from '@mui/lab'; +import { Button, Container, Modal, Paper } from '@mui/material'; +import Avatar from '@mui/material/Avatar'; +import Box from '@mui/material/Box'; +import Stack from '@mui/material/Stack'; +import Typography from '@mui/material/Typography'; +import { Note as NoteIcon } from '@phosphor-icons/react/dist/ssr/Note'; +import PocketBase from 'pocketbase'; +import { useTranslation } from 'react-i18next'; + +import { logger } from '@/lib/default-logger'; +import { toast } from '@/components/core/toaster'; + +const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL); + +export default function ConfirmDeleteModal({ + open, + setOpen, + idToDelete, + reloadRows, +}: { + open: boolean; + setOpen: (b: boolean) => void; + idToDelete: string; + reloadRows: () => void; +}): React.JSX.Element { + const { t } = useTranslation(); + + // const handleClose = () => setOpen(false); + function handleClose(): void { + setOpen(false); + } + + const [isDeleteing, setIsDeleteing] = React.useState(false); + const style = { + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + }; + + function performDelete(id: string): Promise { + return deleteQuizListening(id) + .then(() => { + toast(t('dashboard.lessonTypes.delete.success')); + reloadRows(); + }) + .catch((err) => { + logger.error(err); + toast(t('dashboard.lessonTypes.delete.error')); + }) + .finally(() => {}); + } + + function handleUserConfirmDelete(): void { + if (idToDelete) { + setIsDeleteing(true); + performDelete(idToDelete) + .then(() => { + handleClose(); + }) + .catch((err) => { + // console.error(err) + logger.error(err); + toast(t('dashboard.lessonTypes.delete.error')); + }) + .finally(() => { + setIsDeleteing(false); + }); + } + } + + return ( +
+ + + + + + + + + + + {t('Delete Lesson Type ?')} + + {t('Are you sure you want to delete lesson type ?')} + + + + + { + handleUserConfirmDelete(); + }} + loading={isDeleteing} + > + {t('Delete')} + + + + + + + + +
+ ); +} diff --git a/002_source/cms/src/components/dashboard/lp_categories/lp-categories-table.tsx b/002_source/cms/src/components/dashboard/lp_categories/lp-categories-table.tsx index 448fd83..d797d94 100644 --- a/002_source/cms/src/components/dashboard/lp_categories/lp-categories-table.tsx +++ b/002_source/cms/src/components/dashboard/lp_categories/lp-categories-table.tsx @@ -46,9 +46,9 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef {' '}
- {row.name} + {row.cat_name} - slug: {row.name} + slug: {row.cat_name}
@@ -83,6 +83,8 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef }, pending: { label: 'Pending', icon: }, NA: { label: 'NA', icon: }, + visible: { label: 'visible', icon: }, + hidden: { label: 'hidden', icon: }, } as const; const { label, icon } = mapping[row.visible] ?? { label: 'Unknown', icon: null }; diff --git a/002_source/cms/src/db/QuizListenings/Delete.tsx b/002_source/cms/src/db/QuizListenings/Delete.tsx new file mode 100644 index 0000000..c90a061 --- /dev/null +++ b/002_source/cms/src/db/QuizListenings/Delete.tsx @@ -0,0 +1,8 @@ +import { COL_QUIZ_LISTENINGS } from '@/constants'; +import type { RecordModel } from 'pocketbase'; + +import { pb } from '@/lib/pb'; + +export default function deleteQuizListening(id: string): Promise { + return pb.collection(COL_QUIZ_LISTENINGS).delete(id); +} diff --git a/002_source/cms/src/types/LpCategory.tsx b/002_source/cms/src/types/LpCategory.tsx index 10ebafc..afb1076 100644 --- a/002_source/cms/src/types/LpCategory.tsx +++ b/002_source/cms/src/types/LpCategory.tsx @@ -40,7 +40,10 @@ export interface RestLpCategoryUpdateForm { export interface LpCategory { isEmpty?: boolean; id: string; - name: string; // corresponds to cat_name + collectionId: string; + name: string; + cat_name: string; // corresponds to cat_name + cat_image: string; // corresponds to cat_image description: string; // additional business field isActive: boolean; // additional business field order: number; // corresponds to pos @@ -48,7 +51,7 @@ export interface LpCategory { createdAt: Date; updatedAt: Date; // new field initAnswer?: any; // corresponds to init_answer - visible: 'active' | 'blocked' | 'pending' | 'NA'; // additional business field + visible: 'active' | 'blocked' | 'pending' | 'NA' | 'visible' | 'hidden'; // additional business field quota?: number; // email?: string;