update teachers,
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user