update and bulid ok,

This commit is contained in:
louiscklaw
2025-04-20 03:23:04 +08:00
parent 0f90e0ae72
commit 790ec73e50
5 changed files with 144 additions and 4 deletions

View File

@@ -17,6 +17,9 @@ export const LpCategoryCreateFormDefault: CreateForm = {
export const defaultLpCategory: LpCategory = { export const defaultLpCategory: LpCategory = {
id: '', id: '',
name: '', name: '',
cat_name: '',
cat_image: '',
collectionId: '',
description: '', description: '',
isActive: true, isActive: true,
order: 1, order: 1,

View File

@@ -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<void> {
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 (
<div>
<Modal
open={open}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box sx={style}>
<Container maxWidth="sm">
<Paper sx={{ border: '1px solid var(--mui-palette-divider)', boxShadow: 'var(--mui-shadows-16)' }}>
<Stack direction="row" spacing={2} sx={{ display: 'flex', p: 3 }}>
<Avatar sx={{ bgcolor: 'var(--mui-palette-error-50)', color: 'var(--mui-palette-error-main)' }}>
<NoteIcon fontSize="var(--Icon-fontSize)" />
</Avatar>
<Stack spacing={3}>
<Stack spacing={1}>
<Typography variant="h5">{t('Delete Lesson Type ?')}</Typography>
<Typography color="text.secondary" variant="body2">
{t('Are you sure you want to delete lesson type ?')}
</Typography>
</Stack>
<Stack direction="row" spacing={2} sx={{ justifyContent: 'flex-end' }}>
<Button color="secondary" onClick={handleClose}>
{t('Cancel')}
</Button>
<LoadingButton
color="error"
variant="contained"
onClick={(e) => {
handleUserConfirmDelete();
}}
loading={isDeleteing}
>
{t('Delete')}
</LoadingButton>
</Stack>
</Stack>
</Stack>
</Paper>
</Container>
</Box>
</Modal>
</div>
);
}

View File

@@ -46,9 +46,9 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCateg
<ImagesIcon size={32} /> <ImagesIcon size={32} />
</Avatar>{' '} </Avatar>{' '}
<div> <div>
<Box sx={{ whiteSpace: 'nowrap' }}>{row.name}</Box> <Box sx={{ whiteSpace: 'nowrap' }}>{row.cat_name}</Box>
<Typography color="text.secondary" variant="body2"> <Typography color="text.secondary" variant="body2">
slug: {row.name} slug: {row.cat_name}
</Typography> </Typography>
</div> </div>
</Stack> </Stack>
@@ -83,6 +83,8 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCateg
blocked: { label: 'Blocked', icon: <MinusIcon color="var(--mui-palette-error-main)" /> }, blocked: { label: 'Blocked', icon: <MinusIcon color="var(--mui-palette-error-main)" /> },
pending: { label: 'Pending', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> }, pending: { label: 'Pending', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> },
NA: { label: 'NA', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> }, NA: { label: 'NA', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> },
visible: { label: 'visible', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> },
hidden: { label: 'hidden', icon: <ClockIcon color="var(--mui-palette-warning-main)" weight="fill" /> },
} as const; } as const;
const { label, icon } = mapping[row.visible] ?? { label: 'Unknown', icon: null }; const { label, icon } = mapping[row.visible] ?? { label: 'Unknown', icon: null };

View File

@@ -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<boolean> {
return pb.collection(COL_QUIZ_LISTENINGS).delete(id);
}

View File

@@ -40,7 +40,10 @@ export interface RestLpCategoryUpdateForm {
export interface LpCategory { export interface LpCategory {
isEmpty?: boolean; isEmpty?: boolean;
id: string; 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 description: string; // additional business field
isActive: boolean; // additional business field isActive: boolean; // additional business field
order: number; // corresponds to pos order: number; // corresponds to pos
@@ -48,7 +51,7 @@ export interface LpCategory {
createdAt: Date; createdAt: Date;
updatedAt: Date; // new field updatedAt: Date; // new field
initAnswer?: any; // corresponds to init_answer 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; quota?: number;
// //
email?: string; email?: string;