update user-meta,
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
'use client';
|
||||
// src/app/dashboard/students/edit/[customerId]/page.tsx
|
||||
|
||||
import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
|
@@ -1,3 +1,3 @@
|
||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/teachers/view/[id]/TitleCard.tsx.draft` to handle `Teacher` record thanks, modify comments/variables/paths/functions name please
|
||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/user_metas/edit/[id]/page.tsx.draft` to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||
|
||||
e.g. why `lessonCategories` still exist ?
|
@@ -1,4 +1,5 @@
|
||||
'use client';
|
||||
// src/app/dashboard/user_metas/edit/[id]/page.tsx
|
||||
|
||||
import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
@@ -11,7 +12,7 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||
import { TeacherEditForm } from '@/components/dashboard/teacher/teacher-edit-form';
|
||||
import { UserMetaEditForm } from '@/components/dashboard/user_meta/user-meta-edit-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
@@ -35,7 +36,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.teachers.list}
|
||||
href={paths.dashboard.user_metas.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -47,7 +48,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Typography variant="h4">{t('edit.title')}</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<TeacherEditForm />
|
||||
<UserMetaEditForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
@@ -1,3 +1,3 @@
|
||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/teachers/list/page.tsx.draft` to handle `Teacher` record thanks, modify comments/variables/paths/functions name please
|
||||
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/user_metas/list/page.tsx.draft` to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||
|
||||
e.g. why `lessonCategories` still exist ?
|
@@ -1,8 +1,8 @@
|
||||
// src/app/dashboard/teachers/list/page.tsx
|
||||
// src/app/dashboard/user_metas/list/page.tsx
|
||||
'use client';
|
||||
|
||||
// RULES:
|
||||
// contains list page for teachers (Teachers)
|
||||
// contains list page for user metas (UserMetas)
|
||||
//
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
@@ -16,11 +16,11 @@ import Typography from '@mui/material/Typography';
|
||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||
import type { ListResult, RecordModel } from 'pocketbase';
|
||||
|
||||
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
|
||||
import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination';
|
||||
import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context';
|
||||
import { TeachersTable } from '@/components/dashboard/teacher/teachers-table';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { UserMetasFilters } from '@/components/dashboard/user_meta/user-metas-filters';
|
||||
import { UserMetasPagination } from '@/components/dashboard/user_meta/user-metas-pagination';
|
||||
import { UserMetasSelectionProvider } from '@/components/dashboard/user_meta/user-metas-selection-context';
|
||||
import { UserMetasTable } from '@/components/dashboard/user_meta/user-metas-table';
|
||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
@@ -28,7 +28,7 @@ import isDevelopment from '@/lib/check-is-development';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
@@ -37,7 +37,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
|
||||
const { email, phone, sortDir, status } = searchParams;
|
||||
|
||||
const [teacherData, setTeacherData] = React.useState<Teacher[]>([]);
|
||||
const [userMetaData, setUserMetaData] = React.useState<UserMeta[]>([]);
|
||||
|
||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
||||
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||
@@ -45,7 +45,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
//
|
||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
||||
//
|
||||
const [f, setF] = React.useState<Teacher[]>([]);
|
||||
const [f, setF] = React.useState<UserMeta[]>([]);
|
||||
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
||||
//
|
||||
const [recordCount, setRecordCount] = React.useState<number>(0);
|
||||
@@ -58,23 +58,17 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
//
|
||||
const reloadRows = async (): Promise<void> => {
|
||||
try {
|
||||
const listOptionTeacherOnly = isListOptionChanged()
|
||||
? { filter: `role = "teacher"` }
|
||||
: { filter: [listOption.filter, `role = "teacher"`].join(' && ') };
|
||||
|
||||
console.log({ listOptionTeacherOnly });
|
||||
|
||||
const models: ListResult<RecordModel> = await pb
|
||||
.collection(COL_USER_METAS)
|
||||
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
|
||||
.getList(currentPage + 1, rowsPerPage, listOption);
|
||||
const { items, totalItems } = models;
|
||||
const tempTeacher: Teacher[] = items.map((lt) => {
|
||||
return { ...defaultTeacher, ...lt };
|
||||
const tempUserMeta: UserMeta[] = items.map((lt) => {
|
||||
return { ...defaultUserMeta, ...lt };
|
||||
});
|
||||
|
||||
setTeacherData(tempTeacher);
|
||||
setUserMetaData(tempUserMeta);
|
||||
setRecordCount(totalItems);
|
||||
setF(tempTeacher);
|
||||
setF(tempUserMeta);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
setShowError({
|
||||
@@ -166,7 +160,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
loading={isLoadingAddPage}
|
||||
onClick={(): void => {
|
||||
setIsLoadingAddPage(true);
|
||||
router.push(paths.dashboard.teachers.create);
|
||||
router.push(paths.dashboard.user_metas.create);
|
||||
}}
|
||||
startIcon={<PlusIcon />}
|
||||
variant="contained"
|
||||
@@ -175,22 +169,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
</LoadingButton>
|
||||
</Box>
|
||||
</Stack>
|
||||
<TeachersSelectionProvider teachers={f}>
|
||||
<UserMetasSelectionProvider userMetas={f}>
|
||||
<Card>
|
||||
<TeachersFilters
|
||||
<UserMetasFilters
|
||||
filters={{ email, phone, status }}
|
||||
fullData={teacherData}
|
||||
fullData={userMetaData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
<Divider />
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<TeachersTable
|
||||
<UserMetasTable
|
||||
reloadRows={reloadRows}
|
||||
rows={f}
|
||||
/>
|
||||
</Box>
|
||||
<Divider />
|
||||
<TeachersPagination
|
||||
<UserMetasPagination
|
||||
count={recordCount}
|
||||
page={currentPage}
|
||||
rowsPerPage={rowsPerPage}
|
||||
@@ -198,7 +192,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
setRowsPerPage={setRowsPerPage}
|
||||
/>
|
||||
</Card>
|
||||
</TeachersSelectionProvider>
|
||||
</UserMetasSelectionProvider>
|
||||
</Stack>
|
||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||
<pre>{JSON.stringify(f, null, 2)}</pre>
|
@@ -14,13 +14,13 @@ import { useTranslation } from 'react-i18next';
|
||||
import { PropertyItem } from '@/components/core/property-item';
|
||||
import { PropertyList } from '@/components/core/property-list';
|
||||
// import { CrCategory } from '@/components/dashboard/cr/categories/type';
|
||||
import type { Customer } from '@/components/dashboard/customer/type.d';
|
||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||
|
||||
export default function BasicDetailCard({
|
||||
lpModel: model,
|
||||
userMeta,
|
||||
handleEditClick,
|
||||
}: {
|
||||
lpModel: Customer;
|
||||
userMeta: UserMeta;
|
||||
handleEditClick: () => void;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
@@ -55,15 +55,15 @@ export default function BasicDetailCard({
|
||||
key: 'Customer ID',
|
||||
value: (
|
||||
<Chip
|
||||
label={model.id}
|
||||
label={userMeta.id}
|
||||
size="small"
|
||||
variant="soft"
|
||||
/>
|
||||
),
|
||||
},
|
||||
{ key: 'Email', value: model.email },
|
||||
{ key: 'Quota', value: model.quota },
|
||||
{ key: 'Status', value: model.status },
|
||||
{ key: 'Email', value: userMeta.email },
|
||||
{ key: 'Quota', value: userMeta.quota },
|
||||
{ key: 'Status', value: userMeta.status },
|
||||
] satisfies { key: string; value: React.ReactNode }[]
|
||||
).map(
|
||||
(item): React.JSX.Element => (
|
@@ -0,0 +1,7 @@
|
||||
working file: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/user_metas/view/[id]/page.tsx.draft`
|
||||
|
||||
this file is clone from elsewhere, please understand, modify and update the content of working file to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||
|
||||
restrict your modifications in this file only
|
||||
|
||||
e.g. why `lessonCategories` still exist ?
|
@@ -24,12 +24,12 @@ import { toast } from '@/components/core/toaster';
|
||||
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
|
||||
import { Notifications } from '@/components/dashboard/teacher/notifications';
|
||||
import { Notifications } from '@/components/dashboard/user_meta/notifications';
|
||||
import FormLoading from '@/components/loading';
|
||||
import BasicDetailCard from './BasicDetailCard';
|
||||
import TitleCard from './TitleCard';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { defaultUserMeta } from '@/components/dashboard/user_meta/_constants';
|
||||
import type { UserMeta } from '@/components/dashboard/user_meta/type.d';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
@@ -41,10 +41,10 @@ export default function Page(): React.JSX.Element {
|
||||
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||
//
|
||||
const [showLessonCategory, setShowLessonCategory] = React.useState<Teacher>(defaultTeacher);
|
||||
const [userMeta, setUserMeta] = React.useState<UserMeta>(defaultUserMeta);
|
||||
|
||||
function handleEditClick(): void {
|
||||
router.push(paths.dashboard.teachers.edit(showLessonCategory.id));
|
||||
router.push(paths.dashboard.user_metas.edit(userMeta.id));
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -52,7 +52,7 @@ export default function Page(): React.JSX.Element {
|
||||
pb.collection(COL_USER_METAS)
|
||||
.getOne(id)
|
||||
.then((model: RecordModel) => {
|
||||
setShowLessonCategory({ ...defaultTeacher, ...model });
|
||||
setUserMeta({ ...defaultUserMeta, ...model });
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
@@ -94,12 +94,12 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.teachers.list}
|
||||
href={paths.dashboard.user_metas.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||
Teachers
|
||||
User Metas
|
||||
</Link>
|
||||
</div>
|
||||
<Stack
|
||||
@@ -107,7 +107,7 @@ export default function Page(): React.JSX.Element {
|
||||
spacing={3}
|
||||
sx={{ alignItems: 'flex-start' }}
|
||||
>
|
||||
<TitleCard teacherRecord={showLessonCategory} />
|
||||
<TitleCard teacherRecord={userMeta} />
|
||||
</Stack>
|
||||
</Stack>
|
||||
<Grid
|
||||
@@ -120,7 +120,7 @@ export default function Page(): React.JSX.Element {
|
||||
>
|
||||
<Stack spacing={4}>
|
||||
<BasicDetailCard
|
||||
lpModel={showLessonCategory}
|
||||
userMeta={userMeta}
|
||||
handleEditClick={handleEditClick}
|
||||
/>
|
||||
<SampleSecurityCard />
|
@@ -1,216 +0,0 @@
|
||||
// src/app/dashboard/teachers/list/page.tsx
|
||||
'use client';
|
||||
|
||||
// RULES:
|
||||
// contains list page for teachers (Teachers)
|
||||
//
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import Box from '@mui/material/Box';
|
||||
import Card from '@mui/material/Card';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||
import type { ListResult, RecordModel } from 'pocketbase';
|
||||
|
||||
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
|
||||
import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination';
|
||||
import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context';
|
||||
import { TeachersTable } from '@/components/dashboard/teacher/teachers-table';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import isDevelopment from '@/lib/check-is-development';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['teachers']);
|
||||
const router = useRouter();
|
||||
|
||||
const { email, phone, sortDir, status } = searchParams;
|
||||
|
||||
const [teacherData, setTeacherData] = React.useState<Teacher[]>([]);
|
||||
|
||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
||||
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||
//
|
||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
||||
//
|
||||
const [f, setF] = React.useState<Teacher[]>([]);
|
||||
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
||||
//
|
||||
const [recordCount, setRecordCount] = React.useState<number>(0);
|
||||
const [listOption, setListOption] = React.useState({ filter: '' });
|
||||
const [listSort, setListSort] = React.useState({});
|
||||
|
||||
function isListOptionChanged() {
|
||||
return JSON.stringify(listOption) === '{}';
|
||||
}
|
||||
//
|
||||
const reloadRows = async (): Promise<void> => {
|
||||
try {
|
||||
const listOptionTeacherOnly = isListOptionChanged()
|
||||
? { filter: `role = "teacher"` }
|
||||
: { filter: [listOption.filter, `role = "teacher"`].join(' && ') };
|
||||
|
||||
const models: ListResult<RecordModel> = await pb
|
||||
.collection(COL_USER_METAS)
|
||||
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
|
||||
const { items, totalItems } = models;
|
||||
const tempTeacher: Teacher[] = items.map((lt) => {
|
||||
return { ...defaultTeacher, ...lt };
|
||||
});
|
||||
|
||||
setTeacherData(tempTeacher);
|
||||
setRecordCount(totalItems);
|
||||
setF(tempTeacher);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
setShowError({
|
||||
//
|
||||
show: true,
|
||||
detail: JSON.stringify(error, null, 2),
|
||||
});
|
||||
} finally {
|
||||
setShowLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const [lastListOption, setLastListOption] = React.useState({});
|
||||
const isFirstRun = React.useRef(false);
|
||||
React.useEffect(() => {
|
||||
if (!isFirstRun.current) {
|
||||
isFirstRun.current = true;
|
||||
} else if (JSON.stringify(listOption) !== JSON.stringify(lastListOption)) {
|
||||
// reset page number as tab changes
|
||||
setLastListOption(listOption);
|
||||
setCurrentPage(0);
|
||||
void reloadRows();
|
||||
} else {
|
||||
void reloadRows();
|
||||
}
|
||||
}, [currentPage, rowsPerPage, listOption]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const tempFilter = [];
|
||||
let tempSortDir = '';
|
||||
|
||||
if (status) {
|
||||
tempFilter.push(`status = "${status}"`);
|
||||
}
|
||||
|
||||
if (sortDir) {
|
||||
tempSortDir = `-created`;
|
||||
}
|
||||
|
||||
if (email) {
|
||||
tempFilter.push(`email ~ "%${email}%"`);
|
||||
}
|
||||
|
||||
if (phone) {
|
||||
tempFilter.push(`phone ~ "%${phone}%"`);
|
||||
}
|
||||
|
||||
let preFinalListOption = { filter: '' };
|
||||
if (tempFilter.length > 0) {
|
||||
preFinalListOption = { filter: tempFilter.join(' && ') };
|
||||
}
|
||||
if (tempSortDir.length > 0) {
|
||||
preFinalListOption = { ...preFinalListOption, sort: tempSortDir };
|
||||
}
|
||||
setListOption(preFinalListOption);
|
||||
}, [sortDir, email, phone, status]);
|
||||
|
||||
if (showLoading) return <FormLoading />;
|
||||
|
||||
if (showError.show)
|
||||
return (
|
||||
<ErrorDisplay
|
||||
message={t('error.unable-to-process-request')}
|
||||
code={-1}
|
||||
details={showError.detail}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
maxWidth: 'var(--Content-maxWidth)',
|
||||
m: 'var(--Content-margin)',
|
||||
p: 'var(--Content-padding)',
|
||||
width: 'var(--Content-width)',
|
||||
}}
|
||||
>
|
||||
<Stack spacing={4}>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
spacing={3}
|
||||
sx={{ alignItems: 'flex-start' }}
|
||||
>
|
||||
<Box sx={{ flex: '1 1 auto' }}>
|
||||
<Typography variant="h4">{t('list.title')}</Typography>
|
||||
</Box>
|
||||
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
|
||||
<LoadingButton
|
||||
loading={isLoadingAddPage}
|
||||
onClick={(): void => {
|
||||
setIsLoadingAddPage(true);
|
||||
router.push(paths.dashboard.teachers.create);
|
||||
}}
|
||||
startIcon={<PlusIcon />}
|
||||
variant="contained"
|
||||
>
|
||||
{t('list.add')}
|
||||
</LoadingButton>
|
||||
</Box>
|
||||
</Stack>
|
||||
<TeachersSelectionProvider teachers={f}>
|
||||
<Card>
|
||||
<TeachersFilters
|
||||
filters={{ email, phone, status }}
|
||||
fullData={teacherData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
<Divider />
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<TeachersTable
|
||||
reloadRows={reloadRows}
|
||||
rows={f}
|
||||
/>
|
||||
</Box>
|
||||
<Divider />
|
||||
<TeachersPagination
|
||||
count={recordCount}
|
||||
page={currentPage}
|
||||
rowsPerPage={rowsPerPage}
|
||||
setPage={setCurrentPage}
|
||||
setRowsPerPage={setRowsPerPage}
|
||||
/>
|
||||
</Card>
|
||||
</TeachersSelectionProvider>
|
||||
</Stack>
|
||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||
<pre>{JSON.stringify(f, null, 2)}</pre>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
interface PageProps {
|
||||
searchParams: {
|
||||
email?: string;
|
||||
phone?: string;
|
||||
sortDir?: 'asc' | 'desc';
|
||||
status?: string;
|
||||
//
|
||||
};
|
||||
}
|
@@ -1,143 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import SampleAddressCard from '@/app/dashboard/Sample/AddressCard';
|
||||
import { SampleNotifications } from '@/app/dashboard/Sample/Notifications';
|
||||
import SamplePaymentCard from '@/app/dashboard/Sample/PaymentCard';
|
||||
import SampleSecurityCard from '@/app/dashboard/Sample/SecurityCard';
|
||||
|
||||
import Box from '@mui/material/Box';
|
||||
import Link from '@mui/material/Link';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Grid from '@mui/material/Unstable_Grid2';
|
||||
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { config } from '@/config';
|
||||
import { paths } from '@/paths';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
|
||||
import { Notifications } from '@/components/dashboard/teacher/notifications';
|
||||
import FormLoading from '@/components/loading';
|
||||
import BasicDetailCard from './BasicDetailCard';
|
||||
import TitleCard from './TitleCard';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation(['teachers']);
|
||||
const router = useRouter();
|
||||
//
|
||||
const { id } = useParams<{ id: string }>();
|
||||
//
|
||||
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||
//
|
||||
const [teacherData, setTeacherData] = React.useState<Teacher>(defaultTeacher);
|
||||
|
||||
function handleEditClick(): void {
|
||||
router.push(paths.dashboard.teachers.edit(teacherData.id));
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (id) {
|
||||
pb.collection(COL_USER_METAS)
|
||||
.getOne(id)
|
||||
.then((model: RecordModel) => {
|
||||
setTeacherData({ ...defaultTeacher, ...model });
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
toast(t('list.error'));
|
||||
|
||||
setShowError({ show: true, detail: JSON.stringify(err) });
|
||||
})
|
||||
.finally(() => {
|
||||
setShowLoading(false);
|
||||
});
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [id]);
|
||||
|
||||
// return <>{JSON.stringify({ showError, showLessonCategory }, null, 2)}</>;
|
||||
|
||||
if (showLoading) return <FormLoading />;
|
||||
if (showError.show)
|
||||
return (
|
||||
<ErrorDisplay
|
||||
message={t('error.unable-to-process-request')}
|
||||
code="500"
|
||||
details={showError.detail}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Box
|
||||
sx={{
|
||||
maxWidth: 'var(--Content-maxWidth)',
|
||||
m: 'var(--Content-margin)',
|
||||
p: 'var(--Content-padding)',
|
||||
width: 'var(--Content-width)',
|
||||
}}
|
||||
>
|
||||
<Stack spacing={4}>
|
||||
<Stack spacing={3}>
|
||||
<div>
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.teachers.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||
{t('back-to-list')}
|
||||
</Link>
|
||||
</div>
|
||||
<Stack
|
||||
direction={{ xs: 'column', sm: 'row' }}
|
||||
spacing={3}
|
||||
sx={{ alignItems: 'flex-start' }}
|
||||
>
|
||||
<TitleCard lpModel={teacherData} />
|
||||
</Stack>
|
||||
</Stack>
|
||||
<Grid
|
||||
container
|
||||
spacing={4}
|
||||
>
|
||||
<Grid
|
||||
lg={4}
|
||||
xs={12}
|
||||
>
|
||||
<Stack spacing={4}>
|
||||
<BasicDetailCard
|
||||
lpModel={teacherData}
|
||||
handleEditClick={handleEditClick}
|
||||
/>
|
||||
<SampleSecurityCard />
|
||||
</Stack>
|
||||
</Grid>
|
||||
<Grid
|
||||
lg={8}
|
||||
xs={12}
|
||||
>
|
||||
<Stack spacing={4}>
|
||||
<SamplePaymentCard />
|
||||
<SampleAddressCard />
|
||||
<Notifications notifications={SampleNotifications} />
|
||||
</Stack>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user