update init student,
This commit is contained in:
@@ -3,9 +3,9 @@
|
||||
// empty valur for customer
|
||||
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
import type { Customer } from './type.d';
|
||||
import type { Student } from './type.d';
|
||||
|
||||
export const defaultCustomer: Customer = {
|
||||
export const defaultStudent: Student = {
|
||||
id: '',
|
||||
name: '',
|
||||
avatar: undefined,
|
||||
@@ -16,6 +16,6 @@ export const defaultCustomer: Customer = {
|
||||
createdAt: dayjs().toDate(),
|
||||
};
|
||||
|
||||
export const emptyLpCategory: Customer = {
|
||||
...defaultCustomer,
|
||||
export const emptyLpCategory: Student = {
|
||||
...defaultStudent,
|
||||
};
|
||||
|
@@ -1,9 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_LESSON_TYPES } from '@/constants';
|
||||
import deleteQuizLPCategories from '@/db/QuizListenings/Delete';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import { Button, Container, Modal, Paper } from '@mui/material';
|
||||
import Avatar from '@mui/material/Avatar';
|
||||
@@ -11,12 +8,11 @@ import Box from '@mui/material/Box';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { Note as NoteIcon } from '@phosphor-icons/react/dist/ssr/Note';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import { deleteCustomer } from '@/db/Customers/Delete';
|
||||
import { deleteStudent } from '@/db/Students/Delete';
|
||||
|
||||
export default function ConfirmDeleteModal({
|
||||
open,
|
||||
@@ -49,7 +45,7 @@ export default function ConfirmDeleteModal({
|
||||
setIsDeleteing(true);
|
||||
|
||||
// RULES: delete<CollectionName>
|
||||
deleteCustomer(idToDelete)
|
||||
deleteStudent(idToDelete)
|
||||
.then(() => {
|
||||
reloadRows();
|
||||
handleClose();
|
||||
|
@@ -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 { Customer } 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;
|
||||
customers: Customer[];
|
||||
}
|
||||
|
||||
export function CustomersSelectionProvider({
|
||||
children,
|
||||
customers = [],
|
||||
}: CustomersSelectionProviderProps): React.JSX.Element {
|
||||
const customerIds = React.useMemo(() => customers.map((customer) => customer.id), [customers]);
|
||||
const selection = useSelection(customerIds);
|
||||
|
||||
return <CustomersSelectionContext.Provider value={{ ...selection }}>{children}</CustomersSelectionContext.Provider>;
|
||||
}
|
||||
|
||||
export function useCustomersSelection(): CustomersSelectionContextValue {
|
||||
return React.useContext(CustomersSelectionContext);
|
||||
}
|
@@ -104,7 +104,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
||||
// Use standard create method from db/Customers/Create
|
||||
const record = await createCustomer(values);
|
||||
toast.success('Customer created');
|
||||
router.push(paths.dashboard.customers.details(record.id));
|
||||
router.push(paths.dashboard.students.details(record.id));
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
toast.error('Failed to create customer');
|
||||
@@ -509,7 +509,7 @@ export function CustomerCreateForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.list}
|
||||
href={paths.dashboard.students.list}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
@@ -85,7 +85,7 @@ const defaultValues = {
|
||||
avatar: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function CustomerEditForm(): React.JSX.Element {
|
||||
export function StudentEditForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
||||
@@ -125,7 +125,7 @@ export function CustomerEditForm(): React.JSX.Element {
|
||||
try {
|
||||
await pb.collection(COL_CUSTOMERS).update(customerId, updateData);
|
||||
toast.success('Customer updated successfully');
|
||||
router.push(paths.dashboard.customers.list);
|
||||
router.push(paths.dashboard.students.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error('Failed to update customer');
|
||||
@@ -581,7 +581,7 @@ export function CustomerEditForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.list}
|
||||
href={paths.dashboard.students.list}
|
||||
>
|
||||
{t('edit.cancelButton')}
|
||||
</Button>
|
@@ -21,7 +21,7 @@ import { paths } from '@/paths';
|
||||
import { FilterButton } from '@/components/core/filter-button';
|
||||
import { Option } from '@/components/core/option';
|
||||
|
||||
import { useCustomersSelection } from './customers-selection-context';
|
||||
import { useStudentsSelection } from './students-selection-context';
|
||||
import GetBlockedCount from '@/db/Customers/GetBlockedCount';
|
||||
import GetPendingCount from '@/db/Customers/GetPendingCount';
|
||||
import GetActiveCount from '@/db/Customers/GetActiveCount';
|
||||
@@ -29,7 +29,7 @@ import PhoneFilterPopover from './phone-filter-popover';
|
||||
import EmailFilterPopover from './email-filter-popover';
|
||||
import type { CustomersFiltersProps, Filters, SortDir } from './type.d';
|
||||
|
||||
export function CustomersFilters({
|
||||
export function StudentsFilters({
|
||||
filters = {},
|
||||
sortDir = 'desc',
|
||||
fullData,
|
||||
@@ -45,7 +45,7 @@ export function CustomersFilters({
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const selection = useCustomersSelection();
|
||||
const selection = useStudentsSelection();
|
||||
|
||||
// function getVisible(): number {
|
||||
// return fullData.reduce((count, item: CrQuestion) => {
|
||||
@@ -87,7 +87,7 @@ export function CustomersFilters({
|
||||
searchParams.set('phone', newFilters.phone);
|
||||
}
|
||||
|
||||
router.push(`${paths.dashboard.customers.list}?${searchParams.toString()}`);
|
||||
router.push(`${paths.dashboard.students.list}?${searchParams.toString()}`);
|
||||
},
|
||||
[router]
|
||||
);
|
@@ -7,7 +7,7 @@ function noop(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
interface CustomersPaginationProps {
|
||||
interface StudentsPaginationProps {
|
||||
count: number;
|
||||
page: number;
|
||||
//
|
||||
@@ -16,14 +16,14 @@ interface CustomersPaginationProps {
|
||||
rowsPerPage: number;
|
||||
}
|
||||
|
||||
export function CustomersPagination({
|
||||
export function StudentsPagination({
|
||||
count,
|
||||
page,
|
||||
//
|
||||
setPage,
|
||||
setRowsPerPage,
|
||||
rowsPerPage,
|
||||
}: CustomersPaginationProps): React.JSX.Element {
|
||||
}: StudentsPaginationProps): 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 { Student } from './type.d';
|
||||
|
||||
function noop(): void {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface StudentsSelectionContextValue extends Selection {}
|
||||
|
||||
export const StudentsSelectionContext = React.createContext<StudentsSelectionContextValue>({
|
||||
deselectAll: noop,
|
||||
deselectOne: noop,
|
||||
selectAll: noop,
|
||||
selectOne: noop,
|
||||
selected: new Set(),
|
||||
selectedAny: false,
|
||||
selectedAll: false,
|
||||
});
|
||||
|
||||
interface StudentsSelectionProviderProps {
|
||||
children: React.ReactNode;
|
||||
customers: Student[];
|
||||
}
|
||||
|
||||
export function StudentsSelectionProvider({
|
||||
children,
|
||||
customers = [],
|
||||
}: StudentsSelectionProviderProps): React.JSX.Element {
|
||||
const customerIds = React.useMemo(() => customers.map((customer) => customer.id), [customers]);
|
||||
const selection = useSelection(customerIds);
|
||||
|
||||
return <StudentsSelectionContext.Provider value={{ ...selection }}>{children}</StudentsSelectionContext.Provider>;
|
||||
}
|
||||
|
||||
export function useStudentsSelection(): StudentsSelectionContextValue {
|
||||
return React.useContext(StudentsSelectionContext);
|
||||
}
|
@@ -27,10 +27,10 @@ import { DataTable } from '@/components/core/data-table';
|
||||
import type { ColumnDef } from '@/components/core/data-table';
|
||||
|
||||
import ConfirmDeleteModal from './confirm-delete-modal';
|
||||
import { useCustomersSelection } from './customers-selection-context';
|
||||
import type { Customer } from './type.d';
|
||||
import { useStudentsSelection } from './students-selection-context';
|
||||
import type { Student } from './type.d';
|
||||
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Customer>[] {
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Student>[] {
|
||||
return [
|
||||
{
|
||||
formatter: (row): React.JSX.Element => (
|
||||
@@ -44,7 +44,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Custome
|
||||
<Link
|
||||
color="inherit"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.details(row.id)}
|
||||
href={paths.dashboard.students.details(row.id)}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -143,7 +143,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Custome
|
||||
//
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.customers.details(row.id)}
|
||||
href={paths.dashboard.students.details(row.id)}
|
||||
>
|
||||
<PencilSimpleIcon size={24} />
|
||||
</LoadingButton>
|
||||
@@ -166,14 +166,14 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Custome
|
||||
];
|
||||
}
|
||||
|
||||
export interface CustomersTableProps {
|
||||
rows: Customer[];
|
||||
export interface StudentsTableProps {
|
||||
rows: Student[];
|
||||
reloadRows: () => void;
|
||||
}
|
||||
|
||||
export function CustomersTable({ rows, reloadRows }: CustomersTableProps): React.JSX.Element {
|
||||
export function StudentsTable({ rows, reloadRows }: StudentsTableProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['customers']);
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useCustomersSelection();
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useStudentsSelection();
|
||||
|
||||
const [idToDelete, setIdToDelete] = React.useState('');
|
||||
const [open, setOpen] = React.useState(false);
|
||||
@@ -191,7 +191,7 @@ export function CustomersTable({ rows, reloadRows }: CustomersTableProps): React
|
||||
reloadRows={reloadRows}
|
||||
setOpen={setOpen}
|
||||
/>
|
||||
<DataTable<Customer>
|
||||
<DataTable<Student>
|
||||
columns={columns(handleDeleteClick)}
|
||||
onDeselectAll={deselectAll}
|
||||
onDeselectOne={(_, row) => {
|
@@ -2,7 +2,7 @@
|
||||
|
||||
export type SortDir = 'asc' | 'desc';
|
||||
|
||||
export interface Customer {
|
||||
export interface Student {
|
||||
id: string;
|
||||
name: string;
|
||||
avatar?: string;
|
||||
@@ -60,7 +60,7 @@ export interface EditFormProps {
|
||||
export interface CustomersFiltersProps {
|
||||
filters?: Filters;
|
||||
sortDir?: SortDir;
|
||||
fullData: Customer[];
|
||||
fullData: Student[];
|
||||
}
|
||||
export interface Filters {
|
||||
email?: string;
|
||||
|
Reference in New Issue
Block a user