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