update init teacher ,
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import type { Customer } from '@/components/dashboard/customer/type.d';
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
|
||||
export const SampleCustomers = [
|
||||
export const SampleTeachers = [
|
||||
{
|
||||
id: 'USR-005',
|
||||
name: 'Fran Perez',
|
@@ -24,13 +24,13 @@ import { toast } from '@/components/core/toaster';
|
||||
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
|
||||
import { Notifications } from '@/components/dashboard/customer/notifications';
|
||||
import { Notifications } from '@/components/dashboard/teacher/notifications';
|
||||
import FormLoading from '@/components/loading';
|
||||
import BasicDetailCard from './BasicDetailCard';
|
||||
import TitleCard from './TitleCard';
|
||||
import { defaultCustomer } from '@/components/dashboard/customer/_constants';
|
||||
import type { Customer } from '@/components/dashboard/customer/type.d';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
@@ -41,18 +41,18 @@ 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<Customer>(defaultCustomer);
|
||||
const [showLessonCategory, setShowLessonCategory] = React.useState<Teacher>(defaultTeacher);
|
||||
|
||||
function handleEditClick(): void {
|
||||
router.push(paths.dashboard.customers.edit(showLessonCategory.id));
|
||||
router.push(paths.dashboard.teachers.edit(showLessonCategory.id));
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (customerId) {
|
||||
pb.collection(COL_CUSTOMERS)
|
||||
pb.collection(COL_TEACHERS)
|
||||
.getOne(customerId)
|
||||
.then((model: RecordModel) => {
|
||||
setShowLessonCategory({ ...defaultCustomer, ...model });
|
||||
setShowLessonCategory({ ...defaultTeacher, ...model });
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
@@ -93,12 +93,12 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.list}
|
||||
href={paths.dashboard.teachers.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||
Customers
|
||||
Teachers
|
||||
</Link>
|
||||
</div>
|
||||
<Stack
|
||||
|
@@ -1,5 +1,5 @@
|
||||
'use client';
|
||||
import * as React from 'react';
|
||||
import type { Metadata } from 'next';
|
||||
import RouterLink from 'next/link';
|
||||
import Box from '@mui/material/Box';
|
||||
import Link from '@mui/material/Link';
|
||||
@@ -9,9 +9,7 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
||||
|
||||
import { config } from '@/config';
|
||||
import { paths } from '@/paths';
|
||||
import { CustomerCreateForm } from '@/components/dashboard/customer/customer-create-form';
|
||||
|
||||
export const metadata = { title: `Create | Customers | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||
import { TeacherCreateForm } from '@/components/dashboard/teacher/teacher-create-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
return (
|
||||
@@ -29,19 +27,19 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.list}
|
||||
href={paths.dashboard.teachers.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||
Customers
|
||||
Teachers
|
||||
</Link>
|
||||
</div>
|
||||
<div>
|
||||
<Typography variant="h4">Create customer</Typography>
|
||||
<Typography variant="h4">Create teacher</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<CustomerCreateForm />
|
||||
<TeacherCreateForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -11,7 +11,7 @@ import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||
import { CustomerEditForm } from '@/components/dashboard/customer/customer-edit-form';
|
||||
import { TeacherEditForm } from '@/components/dashboard/teacher/teacher-edit-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
@@ -47,7 +47,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Typography variant="h4">{t('edit.title')}</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<CustomerEditForm />
|
||||
<TeacherEditForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -1,13 +1,13 @@
|
||||
// src/app/dashboard/customers/page.tsx
|
||||
// src/app/dashboard/teachers/page.tsx
|
||||
'use client';
|
||||
|
||||
// RULES:
|
||||
// contains list page for customers (Customers)
|
||||
// contains list page for teachers (Teachers)
|
||||
// contain definition to collection only
|
||||
//
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_CUSTOMERS } from '@/constants';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
@@ -19,13 +19,13 @@ import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||
import type { ListResult, RecordModel } from 'pocketbase';
|
||||
|
||||
import { config } from '@/config';
|
||||
import { CustomersFilters } from '@/components/dashboard/customer/customers-filters';
|
||||
// import type { Filters } from '@/components/dashboard/customer/customers-filters';
|
||||
import { CustomersPagination } from '@/components/dashboard/customer/customers-pagination';
|
||||
import { CustomersSelectionProvider } from '@/components/dashboard/customer/customers-selection-context';
|
||||
import { CustomersTable } from '@/components/dashboard/customer/customers-table';
|
||||
import type { Customer, Filters } from '@/components/dashboard/customer/type.d';
|
||||
import { SampleCustomers } from './SampleCustomers';
|
||||
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
|
||||
// import type { Filters } from '@/components/dashboard/teacher/customers-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, Filters } from '@/components/dashboard/teacher/type.d';
|
||||
import { SampleTeachers } from './SampleTeachers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
@@ -34,16 +34,16 @@ import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultCustomer } from '@/components/dashboard/customer/_constants';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['customers']);
|
||||
const { t } = useTranslation(['teachers']);
|
||||
const router = useRouter();
|
||||
|
||||
const { email, phone, sortDir, status } = searchParams;
|
||||
|
||||
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<Customer[]>([]);
|
||||
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<Teacher[]>([]);
|
||||
//
|
||||
|
||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
||||
@@ -52,26 +52,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
//
|
||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
||||
//
|
||||
const [f, setF] = React.useState<Customer[]>([]);
|
||||
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({});
|
||||
const [listSort, setListSort] = React.useState({});
|
||||
|
||||
//
|
||||
// const sortedCustomers = applySort(SampleCustomers, sortDir);
|
||||
// const filteredCustomers = applyFilters(sortedCustomers, { email, phone, status });
|
||||
|
||||
//
|
||||
const reloadRows = async (): Promise<void> => {
|
||||
try {
|
||||
const models: ListResult<RecordModel> = await pb
|
||||
.collection(COL_CUSTOMERS)
|
||||
.collection(COL_TEACHERS)
|
||||
.getList(currentPage + 1, rowsPerPage, listOption);
|
||||
const { items, totalItems } = models;
|
||||
const tempLessonTypes: Customer[] = items.map((lt) => {
|
||||
return { ...defaultCustomer, ...lt };
|
||||
const tempLessonTypes: Teacher[] = items.map((lt) => {
|
||||
return { ...defaultTeacher, ...lt };
|
||||
});
|
||||
|
||||
setLessonCategoriesData(tempLessonTypes);
|
||||
@@ -174,7 +170,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
loading={isLoadingAddPage}
|
||||
onClick={(): void => {
|
||||
setIsLoadingAddPage(true);
|
||||
router.push(paths.dashboard.customers.create);
|
||||
router.push(paths.dashboard.teachers.create);
|
||||
}}
|
||||
startIcon={<PlusIcon />}
|
||||
variant="contained"
|
||||
@@ -183,22 +179,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
</LoadingButton>
|
||||
</Box>
|
||||
</Stack>
|
||||
<CustomersSelectionProvider customers={f}>
|
||||
<TeachersSelectionProvider teachers={f}>
|
||||
<Card>
|
||||
<CustomersFilters
|
||||
<TeachersFilters
|
||||
filters={{ email, phone, status }}
|
||||
fullData={lessonCategoriesData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
<Divider />
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<CustomersTable
|
||||
<TeachersTable
|
||||
reloadRows={reloadRows}
|
||||
rows={f}
|
||||
/>
|
||||
</Box>
|
||||
<Divider />
|
||||
<CustomersPagination
|
||||
<TeachersPagination
|
||||
count={recordCount}
|
||||
page={currentPage}
|
||||
rowsPerPage={rowsPerPage}
|
||||
@@ -206,7 +202,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
setRowsPerPage={setRowsPerPage}
|
||||
/>
|
||||
</Card>
|
||||
</CustomersSelectionProvider>
|
||||
</TeachersSelectionProvider>
|
||||
</Stack>
|
||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||
<pre>{JSON.stringify(f, null, 2)}</pre>
|
||||
@@ -217,7 +213,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
|
||||
// Sorting and filtering has to be done on the server.
|
||||
|
||||
function applySort(row: Customer[], sortDir: 'asc' | 'desc' | undefined): Customer[] {
|
||||
function applySort(row: Teacher[], sortDir: 'asc' | 'desc' | undefined): Teacher[] {
|
||||
return row.sort((a, b) => {
|
||||
if (sortDir === 'asc') {
|
||||
return a.createdAt.getTime() - b.createdAt.getTime();
|
||||
@@ -227,7 +223,7 @@ function applySort(row: Customer[], sortDir: 'asc' | 'desc' | undefined): Custom
|
||||
});
|
||||
}
|
||||
|
||||
function applyFilters(row: Customer[], { email, phone, status }: Filters): Customer[] {
|
||||
function applyFilters(row: Teacher[], { email, phone, status }: Filters): Teacher[] {
|
||||
return row.filter((item) => {
|
||||
if (email) {
|
||||
if (!item.email?.toLowerCase().includes(email.toLowerCase())) {
|
||||
|
Reference in New Issue
Block a user