update teachers,

This commit is contained in:
louiscklaw
2025-05-08 14:37:48 +08:00
parent 367e58a8cf
commit 30f494fc35
15 changed files with 72 additions and 59 deletions

View File

@@ -5,18 +5,18 @@
- default value (defaultValue)
- empty value (emptyValue)
- `customers-table.tsx`
- `teachers-table.tsx`
- `confirm-delete-modal.tsx` - delete modal component when click delete button on list
- `customers-filters.tsx`
- `customers-pagination.tsx`
- `teachers-filters.tsx`
- `teachers-pagination.tsx`
- `email-filter-popover.tsx`
- `phone-filter-popover.tsx`
- `customers-selection-context.tsx`
- `teachers-selection-context.tsx`
- `customer-create-form.tsx` - form to create a new customer
- `customer-edit-form.tsx` - form to edit a existing customer
- `teacher-create-form.tsx` - form to create a new teacher
- `teacher-edit-form.tsx` - form to edit an existing teacher
- `type.d.tsx` - contains type definition

View File

@@ -83,12 +83,12 @@ export default function ConfirmDeleteModal({
</Avatar>
<Stack spacing={3}>
<Stack spacing={1}>
<Typography variant="h5">{t('Delete Lesson Type ?')}</Typography>
<Typography variant="h5">{t('Delete Teacher ?')}</Typography>
<Typography
color="text.secondary"
variant="body2"
>
{t('Are you sure you want to delete lesson type ?')}
{t('Are you sure you want to delete this teacher ?')}
</Typography>
</Stack>
<Stack

View File

@@ -4,7 +4,7 @@ import * as React from 'react';
import RouterLink from 'next/link';
import { useParams, useRouter } from 'next/navigation';
//
import { COL_TEACHERS } from '@/constants';
import { COL_TEACHERS, COL_USER_METAS } from '@/constants';
import { zodResolver } from '@hookform/resolvers/zod';
import { LoadingButton } from '@mui/lab';
//
@@ -89,7 +89,7 @@ export function TeacherEditForm(): React.JSX.Element {
const router = useRouter();
const { t } = useTranslation(['lp_categories']);
const { customerId } = useParams<{ customerId: string }>();
const { id: teacherId } = useParams<{ id: string }>();
//
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
const [showLoading, setShowLoading] = React.useState<boolean>(false);
@@ -123,17 +123,17 @@ export function TeacherEditForm(): React.JSX.Element {
};
try {
await pb.collection(COL_TEACHERS).update(customerId, updateData);
toast.success('Customer updated successfully');
await pb.collection(COL_USER_METAS).update(teacherId, updateData);
toast.success('Teacher updated successfully');
router.push(paths.dashboard.teachers.list);
} catch (error) {
logger.error(error);
toast.error('Failed to update customer');
toast.error('Failed to update teacher');
} finally {
setIsUpdating(false);
}
},
[customerId, router]
[teacherId, router]
);
const avatarInputRef = React.useRef<HTMLInputElement>(null);
@@ -162,13 +162,13 @@ export function TeacherEditForm(): React.JSX.Element {
setShowLoading(true);
try {
const result = await pb.collection(COL_TEACHERS).getOne(id);
const result = await pb.collection(COL_USER_METAS).getOne(id);
reset({ ...defaultValues, ...result });
console.log({ result });
if (result.avatar_file) {
if (result.avatar) {
const fetchResult = await fetch(
`http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.avatar_file}`
`http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.avatar}`
);
const blob = await fetchResult.blob();
const url = await fileToBase64(blob);
@@ -176,7 +176,7 @@ export function TeacherEditForm(): React.JSX.Element {
}
} catch (error) {
logger.error(error);
toast.error('Failed to load customer data');
toast.error('Failed to load teacher data');
setShowError({ show: true, detail: JSON.stringify(error, null, 2) });
} finally {
setShowLoading(false);
@@ -186,9 +186,9 @@ export function TeacherEditForm(): React.JSX.Element {
);
React.useEffect(() => {
void loadExistingData(customerId);
void loadExistingData(teacherId);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [customerId]);
}, [teacherId]);
if (showLoading) return <FormLoading />;
if (showError.show)

View File

@@ -4,7 +4,7 @@
//
import * as React from 'react';
import { useRouter } from 'next/navigation';
import { getAllCustomersCount } from '@/db/Customers/GetAllCount';
import { getAllTeachersCount } from '@/db/Teachers/GetAllCount';
import Button from '@mui/material/Button';
import Chip from '@mui/material/Chip';
@@ -27,13 +27,15 @@ import GetPendingCount from '@/db/Customers/GetPendingCount';
import GetActiveCount from '@/db/Customers/GetActiveCount';
import PhoneFilterPopover from './phone-filter-popover';
import EmailFilterPopover from './email-filter-popover';
import type { CustomersFiltersProps, Filters, SortDir } from './type.d';
import type { TeachersFiltersProps, Filters, SortDir } from './type.d';
import { logger } from '@/lib/default-logger';
export function TeachersFilters({
filters = {},
sortDir = 'desc',
fullData,
}: CustomersFiltersProps): React.JSX.Element {
//
}: TeachersFiltersProps): React.JSX.Element {
const { t } = useTranslation();
const { email, phone, status } = filters;
@@ -129,7 +131,7 @@ export function TeachersFilters({
React.useEffect(() => {
const fetchCount = async (): Promise<void> => {
try {
const tc = await getAllCustomersCount();
const tc = await getAllTeachersCount();
setTotalCount(tc);
const bc = await GetBlockedCount();
@@ -140,6 +142,7 @@ export function TeachersFilters({
setActiveCount(ac);
} catch (error) {
//
logger.error(error);
}
};
void fetchCount();

View File

@@ -39,7 +39,10 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
spacing={1}
sx={{ alignItems: 'center' }}
>
<Avatar src={row.avatar} />{' '}
<Avatar
src={`http://127.0.0.1:8090/api/files/${row.collectionId}/${row.id}/${row.avatar}`}
variant="rounded"
/>
<div>
<Link
color="inherit"

View File

@@ -5,15 +5,24 @@ export type SortDir = 'asc' | 'desc';
// RULES: core teacher data structure
export interface Teacher {
id: string;
name: string;
//
// NOTE: obslete "avatar" and use "avatar_file"
avatar?: string;
avatar_file?: string;
//
email: string;
phone?: string;
quota: number;
// status is obsoleted, replace by state
status: 'pending' | 'active' | 'blocked';
state: 'pending' | 'active' | 'blocked';
//
id: string;
createdAt: Date;
updatedAt?: Date;
collectionId: string;
}
// RULES: form data structure for creating new teacher
@@ -63,7 +72,7 @@ export interface EditFormProps {
}
// RULES: filter props for teacher search and filtering
export interface CustomersFiltersProps {
export interface TeachersFiltersProps {
filters?: Filters;
sortDir?: SortDir;
fullData: Teacher[];