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>
|
||||
);
|
||||
}
|
@@ -116,9 +116,9 @@ export const layoutConfig = {
|
||||
title: 'users',
|
||||
icon: 'users',
|
||||
items: [
|
||||
{ key: 'users', title: 'List users', href: paths.dashboard.users.list },
|
||||
{ key: 'users:create', title: 'Create user', href: paths.dashboard.users.create },
|
||||
{ key: 'users:details', title: 'User details', href: paths.dashboard.users.view('1') },
|
||||
{ key: 'users', title: 'List users', href: paths.dashboard.user_metas.list },
|
||||
{ key: 'users:create', title: 'Create user', href: paths.dashboard.user_metas.create },
|
||||
{ key: 'users:details', title: 'User details', href: paths.dashboard.user_metas.view('1') },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@@ -6,6 +6,7 @@ export type SortDir = 'asc' | 'desc';
|
||||
// RULES: core student data structure
|
||||
export interface Student {
|
||||
id: string;
|
||||
collectionId: string;
|
||||
name: string;
|
||||
avatar?: string;
|
||||
email: string;
|
||||
|
@@ -104,7 +104,7 @@ export function UserCreateForm(): React.JSX.Element {
|
||||
// Use standard create method from db/Customers/Create
|
||||
const record = await createUser(values);
|
||||
toast.success('User created successfully');
|
||||
router.push(paths.dashboard.users.details(record.id));
|
||||
router.push(paths.dashboard.user_metas.details(record.id));
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
toast.error('Failed to create user. Please try again.');
|
||||
@@ -509,7 +509,7 @@ export function UserCreateForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.users.list}
|
||||
href={paths.dashboard.user_metas.list}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
|
@@ -125,7 +125,7 @@ export function UserEditForm(): React.JSX.Element {
|
||||
try {
|
||||
await pb.collection(COL_USERS).update(userId, updateData);
|
||||
toast.success('User updated successfully');
|
||||
router.push(paths.dashboard.users.list);
|
||||
router.push(paths.dashboard.user_metas.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error('Failed to update user');
|
||||
@@ -581,7 +581,7 @@ export function UserEditForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.users.list}
|
||||
href={paths.dashboard.user_metas.list}
|
||||
>
|
||||
{t('edit.cancelButton')}
|
||||
</Button>
|
||||
|
@@ -44,7 +44,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<User>[]
|
||||
<Link
|
||||
color="inherit"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.users.view(row.id)}
|
||||
href={paths.dashboard.user_metas.view(row.id)}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -143,7 +143,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<User>[]
|
||||
//
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.users.view(row.id)}
|
||||
href={paths.dashboard.user_metas.view(row.id)}
|
||||
>
|
||||
<PencilSimpleIcon size={24} />
|
||||
</LoadingButton>
|
||||
|
@@ -1,25 +0,0 @@
|
||||
# GUIDELINES & KEY COMPONENTS
|
||||
|
||||
- `_constants.ts` contains the constant for
|
||||
|
||||
- default value (defaultValue)
|
||||
- empty value (emptyValue)
|
||||
|
||||
- `teachers-table.tsx`
|
||||
|
||||
- `confirm-delete-modal.tsx` - delete modal component when click delete button on list
|
||||
|
||||
- `teachers-filters.tsx`
|
||||
- `teachers-pagination.tsx`
|
||||
- `email-filter-popover.tsx`
|
||||
- `phone-filter-popover.tsx`
|
||||
- `teachers-selection-context.tsx`
|
||||
|
||||
- `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
|
||||
|
||||
- `notifications.tsx` - constants used for demonstration
|
||||
- `payments.tsx` - constants used for demonstration
|
||||
- `shipping-address.tsx` - constants used for demonstration
|
@@ -1,43 +0,0 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
import { useSelection } from '@/hooks/use-selection';
|
||||
import type { Selection } from '@/hooks/use-selection';
|
||||
|
||||
import type { Teacher } from './type.d';
|
||||
|
||||
function noop(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface CustomersSelectionContextValue extends Selection {}
|
||||
|
||||
export const CustomersSelectionContext = React.createContext<CustomersSelectionContextValue>({
|
||||
deselectAll: noop,
|
||||
deselectOne: noop,
|
||||
selectAll: noop,
|
||||
selectOne: noop,
|
||||
selected: new Set(),
|
||||
selectedAny: false,
|
||||
selectedAll: false,
|
||||
});
|
||||
|
||||
interface CustomersSelectionProviderProps {
|
||||
children: React.ReactNode;
|
||||
teachers: Teacher[];
|
||||
}
|
||||
|
||||
export function TeachersSelectionProvider({
|
||||
children,
|
||||
teachers = [],
|
||||
}: CustomersSelectionProviderProps): React.JSX.Element {
|
||||
const customerIds = React.useMemo(() => teachers.map((customer) => customer.id), [teachers]);
|
||||
const selection = useSelection(customerIds);
|
||||
|
||||
return <CustomersSelectionContext.Provider value={{ ...selection }}>{children}</CustomersSelectionContext.Provider>;
|
||||
}
|
||||
|
||||
export function useTeachersSelection(): CustomersSelectionContextValue {
|
||||
return React.useContext(CustomersSelectionContext);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
# USER META GUIDELINES & KEY COMPONENTS
|
||||
|
||||
## Core Files
|
||||
|
||||
- `_constants.ts` - Contains default and empty values for UserMeta records
|
||||
- `user-meta-table.tsx` - Main table component for displaying UserMeta records
|
||||
- `type.d.tsx` - Type definitions for UserMeta
|
||||
|
||||
## CRUD Components
|
||||
|
||||
- `confirm-delete-modal.tsx` - Delete confirmation modal
|
||||
- `user-meta-create-form.tsx` - Form for creating new UserMeta records
|
||||
- `user-meta-edit-form.tsx` - Form for editing existing UserMeta records
|
||||
|
||||
## Supporting Components
|
||||
|
||||
- `user-meta-filters.tsx` - Filter controls for the table
|
||||
- `user-meta-pagination.tsx` - Pagination controls
|
||||
- `user-meta-selection-context.tsx` - Context for selected records
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
1. All components should work with the UserMeta type from `type.d.tsx`
|
||||
2. Follow existing patterns for API calls and state management
|
||||
3. Ensure proper validation for all UserMeta fields
|
||||
4. Maintain consistent naming conventions (userMeta prefix for components)
|
@@ -0,0 +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/components/dashboard/user_meta/confirm-delete-modal.tsx.draft` to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||
|
||||
e.g. why `lessonCategories` still exist ?
|
@@ -3,9 +3,9 @@
|
||||
// empty valur for customer
|
||||
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
import type { Teacher } from './type.d';
|
||||
import type { UserMeta } from './type.d';
|
||||
|
||||
export const defaultTeacher: Teacher = {
|
||||
export const defaultUserMeta: UserMeta = {
|
||||
id: '',
|
||||
name: '',
|
||||
avatar: undefined,
|
||||
@@ -16,6 +16,6 @@ export const defaultTeacher: Teacher = {
|
||||
createdAt: dayjs().toDate(),
|
||||
};
|
||||
|
||||
export const emptyLpCategory: Teacher = {
|
||||
...defaultTeacher,
|
||||
export const emptyLpCategory: UserMeta = {
|
||||
...defaultUserMeta,
|
||||
};
|
@@ -12,7 +12,7 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import { deleteTeacher } from '@/db/Teachers/Delete';
|
||||
import { deleteUserMeta } from '@/db/UserMetas/Delete';
|
||||
|
||||
export default function ConfirmDeleteModal({
|
||||
open,
|
||||
@@ -45,7 +45,7 @@ export default function ConfirmDeleteModal({
|
||||
setIsDeleteing(true);
|
||||
|
||||
// RULES: delete<CollectionName>
|
||||
deleteTeacher(idToDelete)
|
||||
deleteUserMeta(idToDelete)
|
||||
.then(() => {
|
||||
reloadRows();
|
||||
handleClose();
|
||||
@@ -83,12 +83,12 @@ export default function ConfirmDeleteModal({
|
||||
</Avatar>
|
||||
<Stack spacing={3}>
|
||||
<Stack spacing={1}>
|
||||
<Typography variant="h5">{t('Delete Teacher ?')}</Typography>
|
||||
<Typography variant="h5">{t('Delete This User ?')}</Typography>
|
||||
<Typography
|
||||
color="text.secondary"
|
||||
variant="body2"
|
||||
>
|
||||
{t('Are you sure you want to delete this teacher ?')}
|
||||
{t('Are you sure you want to delete this user ?')}
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Stack
|
@@ -4,7 +4,7 @@
|
||||
export type SortDir = 'asc' | 'desc';
|
||||
|
||||
// RULES: core teacher data structure
|
||||
export interface Teacher {
|
||||
export interface UserMeta {
|
||||
name: string;
|
||||
//
|
||||
// NOTE: obslete "avatar" and use "avatar_file"
|
||||
@@ -72,10 +72,10 @@ export interface EditFormProps {
|
||||
}
|
||||
|
||||
// RULES: filter props for teacher search and filtering
|
||||
export interface TeachersFiltersProps {
|
||||
export interface UserMetasFiltersProps {
|
||||
filters?: Filters;
|
||||
sortDir?: SortDir;
|
||||
fullData: Teacher[];
|
||||
fullData: UserMeta[];
|
||||
}
|
||||
export interface Filters {
|
||||
email?: string;
|
@@ -85,7 +85,7 @@ const defaultValues = {
|
||||
avatar: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function TeacherEditForm(): React.JSX.Element {
|
||||
export function UserMetaEditForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
@@ -4,7 +4,7 @@
|
||||
//
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { getAllTeachersCount } from '@/db/Teachers/GetAllCount';
|
||||
import getAllUserMetasCount from '@/db/UserMetas/GetAllCount';
|
||||
|
||||
import Button from '@mui/material/Button';
|
||||
import Chip from '@mui/material/Chip';
|
||||
@@ -21,21 +21,21 @@ import { paths } from '@/paths';
|
||||
import { FilterButton } from '@/components/core/filter-button';
|
||||
import { Option } from '@/components/core/option';
|
||||
|
||||
import { useTeachersSelection } from './teachers-selection-context';
|
||||
import GetBlockedCount from '@/db/Customers/GetBlockedCount';
|
||||
import GetPendingCount from '@/db/Customers/GetPendingCount';
|
||||
import GetActiveCount from '@/db/Customers/GetActiveCount';
|
||||
import { useUserMetasSelection } from './user-metas-selection-context';
|
||||
import GetBlockedCount from '@/db/UserMetas/GetBlockedCount';
|
||||
import GetPendingCount from '@/db/UserMetas/GetPendingCount';
|
||||
import GetActiveCount from '@/db/UserMetas/GetActiveCount';
|
||||
import PhoneFilterPopover from './phone-filter-popover';
|
||||
import EmailFilterPopover from './email-filter-popover';
|
||||
import type { TeachersFiltersProps, Filters, SortDir } from './type.d';
|
||||
import type { UserMetasFiltersProps, Filters, SortDir } from './type.d';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
|
||||
export function TeachersFilters({
|
||||
export function UserMetasFilters({
|
||||
filters = {},
|
||||
sortDir = 'desc',
|
||||
fullData,
|
||||
//
|
||||
}: TeachersFiltersProps): React.JSX.Element {
|
||||
}: UserMetasFiltersProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { email, phone, status } = filters;
|
||||
@@ -47,7 +47,7 @@ export function TeachersFilters({
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const selection = useTeachersSelection();
|
||||
const selection = useUserMetasSelection();
|
||||
|
||||
// function getVisible(): number {
|
||||
// return fullData.reduce((count, item: CrQuestion) => {
|
||||
@@ -89,7 +89,7 @@ export function TeachersFilters({
|
||||
searchParams.set('phone', newFilters.phone);
|
||||
}
|
||||
|
||||
router.push(`${paths.dashboard.teachers.list}?${searchParams.toString()}`);
|
||||
router.push(`${paths.dashboard.user_metas.list}?${searchParams.toString()}`);
|
||||
},
|
||||
[router]
|
||||
);
|
||||
@@ -131,7 +131,7 @@ export function TeachersFilters({
|
||||
React.useEffect(() => {
|
||||
const fetchCount = async (): Promise<void> => {
|
||||
try {
|
||||
const tc = await getAllTeachersCount();
|
||||
const tc = await getAllUserMetasCount();
|
||||
setTotalCount(tc);
|
||||
|
||||
const bc = await GetBlockedCount();
|
@@ -7,7 +7,7 @@ function noop(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface CustomersPaginationProps {
|
||||
interface UserMetasPaginationProps {
|
||||
count: number;
|
||||
page: number;
|
||||
//
|
||||
@@ -16,14 +16,14 @@ interface CustomersPaginationProps {
|
||||
rowsPerPage: number;
|
||||
}
|
||||
|
||||
export function TeachersPagination({
|
||||
export function UserMetasPagination({
|
||||
count,
|
||||
page,
|
||||
//
|
||||
setPage,
|
||||
setRowsPerPage,
|
||||
rowsPerPage,
|
||||
}: CustomersPaginationProps): React.JSX.Element {
|
||||
}: UserMetasPaginationProps): React.JSX.Element {
|
||||
// You should implement the pagination using a similar logic as the filters.
|
||||
// Note that when page change, you should keep the filter search params.
|
||||
const handleChangePage = (event: unknown, newPage: number) => {
|
@@ -0,0 +1,43 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
import { useSelection } from '@/hooks/use-selection';
|
||||
import type { Selection } from '@/hooks/use-selection';
|
||||
|
||||
import type { UserMeta } from './type.d';
|
||||
|
||||
function noop(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface UserMetasSelectionContextValue extends Selection {}
|
||||
|
||||
export const UserMetasSelectionContext = React.createContext<UserMetasSelectionContextValue>({
|
||||
deselectAll: noop,
|
||||
deselectOne: noop,
|
||||
selectAll: noop,
|
||||
selectOne: noop,
|
||||
selected: new Set(),
|
||||
selectedAny: false,
|
||||
selectedAll: false,
|
||||
});
|
||||
|
||||
interface UserMetasSelectionProviderProps {
|
||||
children: React.ReactNode;
|
||||
userMetas: UserMeta[];
|
||||
}
|
||||
|
||||
export function UserMetasSelectionProvider({
|
||||
children,
|
||||
userMetas: teachers = [],
|
||||
}: UserMetasSelectionProviderProps): React.JSX.Element {
|
||||
const customerIds = React.useMemo(() => teachers.map((customer) => customer.id), [teachers]);
|
||||
const selection = useSelection(customerIds);
|
||||
|
||||
return <UserMetasSelectionContext.Provider value={{ ...selection }}>{children}</UserMetasSelectionContext.Provider>;
|
||||
}
|
||||
|
||||
export function useUserMetasSelection(): UserMetasSelectionContextValue {
|
||||
return React.useContext(UserMetasSelectionContext);
|
||||
}
|
@@ -18,19 +18,16 @@ import { Images as ImagesIcon } from '@phosphor-icons/react/dist/ssr/Images';
|
||||
import { Minus as MinusIcon } from '@phosphor-icons/react/dist/ssr/Minus';
|
||||
import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';
|
||||
import { TrashSimple as TrashSimpleIcon } from '@phosphor-icons/react/dist/ssr/TrashSimple';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
import { DataTable } from '@/components/core/data-table';
|
||||
import type { ColumnDef } from '@/components/core/data-table';
|
||||
|
||||
import ConfirmDeleteModal from './confirm-delete-modal';
|
||||
import { useTeachersSelection } from './teachers-selection-context';
|
||||
import type { Teacher } from './type.d';
|
||||
import { useUserMetasSelection } from './user-metas-selection-context';
|
||||
import type { UserMeta } from './type.d';
|
||||
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher>[] {
|
||||
function columns(handleDeleteClick: (userMetaId: string) => void): ColumnDef<UserMeta>[] {
|
||||
return [
|
||||
{
|
||||
formatter: (row): React.JSX.Element => (
|
||||
@@ -47,7 +44,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
|
||||
<Link
|
||||
color="inherit"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.teachers.details(row.id)}
|
||||
href={paths.dashboard.user_metas.view(row.id)}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -144,14 +141,12 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
|
||||
//
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.teachers.view(row.id)}
|
||||
href={paths.dashboard.user_metas.view(row.id)}
|
||||
>
|
||||
<PencilSimpleIcon size={24} />
|
||||
</LoadingButton>
|
||||
<LoadingButton
|
||||
color="error"
|
||||
// TODO: originally it is row.isEmpty
|
||||
disabled={false}
|
||||
onClick={() => {
|
||||
handleDeleteClick(row.id);
|
||||
}}
|
||||
@@ -167,14 +162,13 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
|
||||
];
|
||||
}
|
||||
|
||||
export interface TeachersTableProps {
|
||||
rows: Teacher[];
|
||||
export interface UserMetasTableProps {
|
||||
rows: UserMeta[];
|
||||
reloadRows: () => void;
|
||||
}
|
||||
|
||||
export function TeachersTable({ rows, reloadRows }: TeachersTableProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['teachers']);
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useTeachersSelection();
|
||||
export function UserMetasTable({ rows, reloadRows }: UserMetasTableProps): React.JSX.Element {
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useUserMetasSelection();
|
||||
|
||||
const [idToDelete, setIdToDelete] = React.useState('');
|
||||
const [open, setOpen] = React.useState(false);
|
||||
@@ -192,7 +186,7 @@ export function TeachersTable({ rows, reloadRows }: TeachersTableProps): React.J
|
||||
reloadRows={reloadRows}
|
||||
setOpen={setOpen}
|
||||
/>
|
||||
<DataTable<Teacher>
|
||||
<DataTable<UserMeta>
|
||||
columns={columns(handleDeleteClick)}
|
||||
onDeselectAll={deselectAll}
|
||||
onDeselectOne={(_, row) => {
|
||||
@@ -213,8 +207,7 @@ export function TeachersTable({ rows, reloadRows }: TeachersTableProps): React.J
|
||||
sx={{ textAlign: 'center' }}
|
||||
variant="body2"
|
||||
>
|
||||
{/* TODO: update this */}
|
||||
{t('no-teachers-found')}
|
||||
No user metadata found
|
||||
</Typography>
|
||||
</Box>
|
||||
) : null}
|
@@ -2,10 +2,10 @@
|
||||
// RULES:
|
||||
// TBA
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import type { CreateFormProps } from '@/components/dashboard/customer/type.d';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import type { CreateFormProps } from '@/components/dashboard/user_meta/type.d';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function createCustomer(data: CreateFormProps): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).create(data);
|
||||
export async function createUserMeta(data: CreateFormProps): Promise<RecordModel> {
|
||||
return pb.collection(COL_USER_METAS).create(data);
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
|
||||
export async function deleteCustomer(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_CUSTOMERS).delete(id);
|
||||
export async function deleteUserMeta(id: string): Promise<boolean> {
|
||||
return pb.collection(COL_USER_METAS).delete(id);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetActiveCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||
filter: 'status = "active"',
|
||||
});
|
||||
return count;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getAllCustomers(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_CUSTOMERS).getFullList(options);
|
||||
export async function getAllUserMetas(options = {}): Promise<RecordModel[]> {
|
||||
return pb.collection(COL_USER_METAS).getFullList(options);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetBlockedCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||
filter: 'status = "blocked"',
|
||||
});
|
||||
return count;
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { RecordModel } from 'pocketbase';
|
||||
|
||||
export async function getCustomerById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).getOne(id);
|
||||
export async function getUserMetaById(id: string): Promise<RecordModel> {
|
||||
return pb.collection(COL_USER_METAS).getOne(id);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import { pb } from '@/lib/pb';
|
||||
|
||||
export default async function GetPendingCount(): Promise<number> {
|
||||
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
|
||||
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
|
||||
filter: 'status = "pending"',
|
||||
});
|
||||
return count;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { pb } from '@/lib/pb';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_USER_METAS } from '@/constants';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import type { EditFormProps } from '@/components/dashboard/customer/type.d';
|
||||
|
||||
export async function updateCustomer(id: string, data: Partial<EditFormProps>): Promise<RecordModel> {
|
||||
return pb.collection(COL_CUSTOMERS).update(id, data);
|
||||
return pb.collection(COL_USER_METAS).update(id, data);
|
||||
}
|
||||
|
11
002_source/cms/src/db/UserMetas/_PROMPT.md
Normal file
11
002_source/cms/src/db/UserMetas/_PROMPT.md
Normal file
@@ -0,0 +1,11 @@
|
||||
`working directory`: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/UserMetas`
|
||||
|
||||
these files are clone from elsewhere,
|
||||
please help to list `*.tsx.draft` files in `working directory` (e.g. `find`),
|
||||
iterate the files listed in the result.
|
||||
please understand, modify and update the content to handle `UserMeta` record thanks, modify comments/variables/paths/functions name please
|
||||
|
||||
restrict your modifications in working directory only,
|
||||
I will handle all the modification outside this direcotry
|
||||
|
||||
e.g. if `lessonCategories` exist in file, modify it to `userMetas`
|
@@ -149,13 +149,13 @@ export const paths = {
|
||||
// edit: (id: string) => `/dashboard/teachers/edit/${id}`,
|
||||
},
|
||||
},
|
||||
users: {
|
||||
list: '/dashboard/users/list',
|
||||
create: '/dashboard/users/create',
|
||||
view: (id: string) => `/dashboard/users/view/${id}`,
|
||||
user_metas: {
|
||||
list: '/dashboard/user_metas/list',
|
||||
create: '/dashboard/user_metas/create',
|
||||
view: (id: string) => `/dashboard/user_metas/view/${id}`,
|
||||
// RULES: details is obsoleted, use view instead
|
||||
details: (id: string) => `/dashboard/teachers/view/${id}`,
|
||||
edit: (id: string) => `/dashboard/users/edit/${id}`,
|
||||
// details: (id: string) => `/dashboard/teachers/view/${id}`,
|
||||
edit: (id: string) => `/dashboard/user_metas/edit/${id}`,
|
||||
},
|
||||
students: {
|
||||
list: '/dashboard/students/list',
|
||||
|
Reference in New Issue
Block a user