update working on cms users page,
This commit is contained in:
157
002_source/cms/src/app/dashboard/users/SampleCustomers.tsx
Normal file
157
002_source/cms/src/app/dashboard/users/SampleCustomers.tsx
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
// src/app/dashboard/customers/page.tsx
|
||||||
|
'use client';
|
||||||
|
import type { Customer } from '@/components/dashboard/customer/type.d';
|
||||||
|
import { dayjs } from '@/lib/dayjs';
|
||||||
|
|
||||||
|
export const SampleCustomers = [
|
||||||
|
{
|
||||||
|
id: 'USR-005',
|
||||||
|
name: 'Fran Perez',
|
||||||
|
avatar: '/assets/avatar-5.png',
|
||||||
|
email: 'fran.perez@domain.com',
|
||||||
|
phone: '(815) 704-0045',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-004',
|
||||||
|
name: 'Penjani Inyene',
|
||||||
|
avatar: '/assets/avatar-4.png',
|
||||||
|
email: 'penjani.inyene@domain.com',
|
||||||
|
phone: '(803) 937-8925',
|
||||||
|
quota: 100,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(3, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-003',
|
||||||
|
name: 'Carson Darrin',
|
||||||
|
avatar: '/assets/avatar-3.png',
|
||||||
|
email: 'carson.darrin@domain.com',
|
||||||
|
phone: '(715) 278-5041',
|
||||||
|
quota: 10,
|
||||||
|
status: 'blocked',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-002',
|
||||||
|
name: 'Siegbert Gottfried',
|
||||||
|
avatar: '/assets/avatar-2.png',
|
||||||
|
email: 'siegbert.gottfried@domain.com',
|
||||||
|
phone: '(603) 766-0431',
|
||||||
|
quota: 0,
|
||||||
|
status: 'pending',
|
||||||
|
createdAt: dayjs().subtract(7, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-001',
|
||||||
|
name: 'Miron Vitold',
|
||||||
|
avatar: '/assets/avatar-1.png',
|
||||||
|
email: 'miron.vitold@domain.com',
|
||||||
|
phone: '(425) 434-5535',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(2, 'hour').subtract(2, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-005',
|
||||||
|
name: 'Fran Perez',
|
||||||
|
avatar: '/assets/avatar-5.png',
|
||||||
|
email: 'fran.perez@domain.com',
|
||||||
|
phone: '(815) 704-0045',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-004',
|
||||||
|
name: 'Penjani Inyene',
|
||||||
|
avatar: '/assets/avatar-4.png',
|
||||||
|
email: 'penjani.inyene@domain.com',
|
||||||
|
phone: '(803) 937-8925',
|
||||||
|
quota: 100,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(3, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-003',
|
||||||
|
name: 'Carson Darrin',
|
||||||
|
avatar: '/assets/avatar-3.png',
|
||||||
|
email: 'carson.darrin@domain.com',
|
||||||
|
phone: '(715) 278-5041',
|
||||||
|
quota: 10,
|
||||||
|
status: 'blocked',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-002',
|
||||||
|
name: 'Siegbert Gottfried',
|
||||||
|
avatar: '/assets/avatar-2.png',
|
||||||
|
email: 'siegbert.gottfried@domain.com',
|
||||||
|
phone: '(603) 766-0431',
|
||||||
|
quota: 0,
|
||||||
|
status: 'pending',
|
||||||
|
createdAt: dayjs().subtract(7, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-001',
|
||||||
|
name: 'Miron Vitold',
|
||||||
|
avatar: '/assets/avatar-1.png',
|
||||||
|
email: 'miron.vitold@domain.com',
|
||||||
|
phone: '(425) 434-5535',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(2, 'hour').subtract(2, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-005',
|
||||||
|
name: 'Fran Perez',
|
||||||
|
avatar: '/assets/avatar-5.png',
|
||||||
|
email: 'fran.perez@domain.com',
|
||||||
|
phone: '(815) 704-0045',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-004',
|
||||||
|
name: 'Penjani Inyene',
|
||||||
|
avatar: '/assets/avatar-4.png',
|
||||||
|
email: 'penjani.inyene@domain.com',
|
||||||
|
phone: '(803) 937-8925',
|
||||||
|
quota: 100,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(3, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-003',
|
||||||
|
name: 'Carson Darrin',
|
||||||
|
avatar: '/assets/avatar-3.png',
|
||||||
|
email: 'carson.darrin@domain.com',
|
||||||
|
phone: '(715) 278-5041',
|
||||||
|
quota: 10,
|
||||||
|
status: 'blocked',
|
||||||
|
createdAt: dayjs().subtract(1, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-002',
|
||||||
|
name: 'Siegbert Gottfried',
|
||||||
|
avatar: '/assets/avatar-2.png',
|
||||||
|
email: 'siegbert.gottfried@domain.com',
|
||||||
|
phone: '(603) 766-0431',
|
||||||
|
quota: 0,
|
||||||
|
status: 'pending',
|
||||||
|
createdAt: dayjs().subtract(7, 'hour').subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'USR-001',
|
||||||
|
name: 'Miron Vitold',
|
||||||
|
avatar: '/assets/avatar-1.png',
|
||||||
|
email: 'miron.vitold@domain.com',
|
||||||
|
phone: '(425) 434-5535',
|
||||||
|
quota: 50,
|
||||||
|
status: 'active',
|
||||||
|
createdAt: dayjs().subtract(2, 'hour').subtract(2, 'day').toDate(),
|
||||||
|
},
|
||||||
|
] satisfies Customer[];
|
49
002_source/cms/src/app/dashboard/users/_GUIDELINES.md
Normal file
49
002_source/cms/src/app/dashboard/users/_GUIDELINES.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
# GUIDELINES
|
||||||
|
|
||||||
|
this folder is part of nextjs typescript project and containing page definition for `Customer` / `Customers` record:
|
||||||
|
|
||||||
|
- list (./page.tsx)
|
||||||
|
- view (./[customerId]/page.tsx)
|
||||||
|
- create (./create/page.tsx)
|
||||||
|
- edit (./[customerId]/page.tsx)
|
||||||
|
- translation provided by react-i18next
|
||||||
|
|
||||||
|
the `@` sign refer to `<base_dir>/002_source/002_source/cms/src`
|
||||||
|
|
||||||
|
## Assumption and Requirements
|
||||||
|
|
||||||
|
- let one file contains one component only.
|
||||||
|
- type information defined in `<base_dir>/002_source/cms/src/db/Customers/type.d.tsx`
|
||||||
|
- it mainly consume the db drivers `Customres` in `<base_dir>/002_source/cms/src/db/Customers`
|
||||||
|
|
||||||
|
simple template:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// src/app/dashboard/customers/page.tsx
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
// RULES:
|
||||||
|
// contains list page for customers (Customers)
|
||||||
|
// contain definition to collection only
|
||||||
|
//
|
||||||
|
import statements here ...
|
||||||
|
...
|
||||||
|
...
|
||||||
|
...
|
||||||
|
|
||||||
|
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||||
|
// ...content
|
||||||
|
// use direct return of pb.collection (e.g. return pb.collection(xxx))
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{* page content *}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface PageProps {
|
||||||
|
searchParams: { email?: string; phone?: string; sortDir?: 'asc' | 'desc'; status?: string };
|
||||||
|
}
|
||||||
|
```
|
48
002_source/cms/src/app/dashboard/users/create/page.tsx
Normal file
48
002_source/cms/src/app/dashboard/users/create/page.tsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
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';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
||||||
|
|
||||||
|
import { config } from '@/config';
|
||||||
|
import { paths } from '@/paths';
|
||||||
|
import { CustomerCreateForm } from '@/components/dashboard/student/student-create-form';
|
||||||
|
|
||||||
|
export const metadata = { title: `Create | Customers | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||||
|
|
||||||
|
export default function Page(): React.JSX.Element {
|
||||||
|
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.customers.list}
|
||||||
|
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||||
|
variant="subtitle2"
|
||||||
|
>
|
||||||
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
|
Customers
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography variant="h4">Create customer</Typography>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
<CustomerCreateForm />
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
# task
|
||||||
|
|
||||||
|
## instruction
|
||||||
|
|
||||||
|
with reference to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/_helloworld/page.tsx`
|
||||||
|
|
||||||
|
with reference to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/lesson_types/edit/[typeId]/page.tsx`
|
||||||
|
|
||||||
|
please modify `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/lesson_categories/edit/page.tsx`
|
||||||
|
|
||||||
|
please draft a tsx for showing error to user thanks,
|
@@ -0,0 +1,54 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import RouterLink from 'next/link';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Link from '@mui/material/Link';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
import { paths } from '@/paths';
|
||||||
|
import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form';
|
||||||
|
import { StudentEditForm } from '@/components/dashboard/student/student-edit-form';
|
||||||
|
|
||||||
|
export default function Page(): React.JSX.Element {
|
||||||
|
const { t } = useTranslation(['lp_categories']);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
// console.log('helloworld');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
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.students.list}
|
||||||
|
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||||
|
variant="subtitle2"
|
||||||
|
>
|
||||||
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
|
{t('edit.title')}
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Typography variant="h4">{t('edit.title')}</Typography>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
<StudentEditForm />
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
209
002_source/cms/src/app/dashboard/users/list/page.tsx
Normal file
209
002_source/cms/src/app/dashboard/users/list/page.tsx
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
// src/app/dashboard/customers/page.tsx
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
// RULES:
|
||||||
|
// contains list page for customers (Customers)
|
||||||
|
// contain definition to collection only
|
||||||
|
//
|
||||||
|
import * as React from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { COL_USERS } 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 { UsersFilters } from '@/components/dashboard/user/users-filters';
|
||||||
|
import { UsersPagination } from '@/components/dashboard/user/users-pagination';
|
||||||
|
import { UsersSelectionProvider } from '@/components/dashboard/user/users-selection-context';
|
||||||
|
import { UsersTable } from '@/components/dashboard/user/users-table';
|
||||||
|
import type { User } from '@/components/dashboard/user/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 { defaultUser } from '@/components/dashboard/user/_constants';
|
||||||
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
|
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||||
|
const { t } = useTranslation(['customers']);
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
const { email, phone, sortDir, status } = searchParams;
|
||||||
|
|
||||||
|
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<User[]>([]);
|
||||||
|
//
|
||||||
|
|
||||||
|
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<User[]>([]);
|
||||||
|
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
||||||
|
//
|
||||||
|
const [recordCount, setRecordCount] = React.useState<number>(0);
|
||||||
|
const [listOption, setListOption] = React.useState({});
|
||||||
|
|
||||||
|
//
|
||||||
|
const reloadRows = async (): Promise<void> => {
|
||||||
|
try {
|
||||||
|
const models: ListResult<RecordModel> = await pb.collection(COL_USERS).getList(currentPage + 1, rowsPerPage, {});
|
||||||
|
const { items, totalItems } = models;
|
||||||
|
|
||||||
|
const tempLessonTypes: User[] = items.map((lt) => {
|
||||||
|
return { ...defaultUser, ...lt };
|
||||||
|
});
|
||||||
|
|
||||||
|
setLessonCategoriesData(tempLessonTypes);
|
||||||
|
setRecordCount(totalItems);
|
||||||
|
setF(tempLessonTypes);
|
||||||
|
} 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 = {};
|
||||||
|
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.users.create);
|
||||||
|
}}
|
||||||
|
startIcon={<PlusIcon />}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
{t('list.add')}
|
||||||
|
</LoadingButton>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
<UsersSelectionProvider users={f}>
|
||||||
|
<Card>
|
||||||
|
<UsersFilters
|
||||||
|
filters={{ email, phone, status }}
|
||||||
|
fullData={lessonCategoriesData}
|
||||||
|
sortDir={sortDir}
|
||||||
|
/>
|
||||||
|
<Divider />
|
||||||
|
<Box sx={{ overflowX: 'auto' }}>
|
||||||
|
<UsersTable
|
||||||
|
reloadRows={reloadRows}
|
||||||
|
rows={f}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Divider />
|
||||||
|
<UsersPagination
|
||||||
|
count={recordCount}
|
||||||
|
page={currentPage}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
setPage={setCurrentPage}
|
||||||
|
setRowsPerPage={setRowsPerPage}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
</UsersSelectionProvider>
|
||||||
|
</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;
|
||||||
|
//
|
||||||
|
};
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import type { Metadata } from 'next';
|
||||||
|
|
||||||
|
import { config } from '@/config';
|
||||||
|
import { ThreadView } from '@/components/dashboard/mail/thread-view';
|
||||||
|
|
||||||
|
export const metadata = { title: `Thread | Mail | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||||
|
|
||||||
|
interface PageProps {
|
||||||
|
params: { threadId: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Page({ params }: PageProps): React.JSX.Element {
|
||||||
|
const { threadId } = params;
|
||||||
|
|
||||||
|
return <ThreadView threadId={threadId} />;
|
||||||
|
}
|
142
002_source/cms/src/app/dashboard/users/mail/[labelId]/layout.tsx
Normal file
142
002_source/cms/src/app/dashboard/users/mail/[labelId]/layout.tsx
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { dayjs } from '@/lib/dayjs';
|
||||||
|
import { MailProvider } from '@/components/dashboard/mail/mail-context';
|
||||||
|
import { MailView } from '@/components/dashboard/mail/mail-view';
|
||||||
|
import type { Label, Thread } from '@/components/dashboard/mail/types';
|
||||||
|
|
||||||
|
function filterThreads(threads: Thread[], labelId: string): Thread[] {
|
||||||
|
return threads.filter((thread) => {
|
||||||
|
if (['inbox', 'sent', 'drafts', 'spam', 'trash'].includes(labelId)) {
|
||||||
|
return thread.folder === labelId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (labelId === 'important') {
|
||||||
|
return thread.isImportant;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (labelId === 'starred') {
|
||||||
|
return thread.isStarred;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thread.labels.includes(labelId)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const labels = [
|
||||||
|
{ id: 'inbox', type: 'system', name: 'Inbox', unreadCount: 1, totalCount: 0 },
|
||||||
|
{ id: 'sent', type: 'system', name: 'Sent', unreadCount: 0, totalCount: 0 },
|
||||||
|
{ id: 'drafts', type: 'system', name: 'Drafts', unreadCount: 0, totalCount: 0 },
|
||||||
|
{ id: 'spam', type: 'system', name: 'Spam', unreadCount: 0, totalCount: 0 },
|
||||||
|
{ id: 'trash', type: 'system', name: 'Trash', unreadCount: 0, totalCount: 1 },
|
||||||
|
{ id: 'important', type: 'system', name: 'Important', unreadCount: 0, totalCount: 1 },
|
||||||
|
{ id: 'starred', type: 'system', name: 'Starred', unreadCount: 1, totalCount: 1 },
|
||||||
|
{ id: 'work', type: 'custom', name: 'Work', color: '#43A048', unreadCount: 0, totalCount: 1 },
|
||||||
|
{ id: 'business', type: 'custom', name: 'Business', color: '#1E88E5', unreadCount: 1, totalCount: 2 },
|
||||||
|
{ id: 'personal', type: 'custom', name: 'Personal', color: '#FB8A00', unreadCount: 0, totalCount: 1 },
|
||||||
|
] satisfies Label[];
|
||||||
|
|
||||||
|
const threads = [
|
||||||
|
{
|
||||||
|
id: 'TRD-004',
|
||||||
|
from: { avatar: '/assets/avatar-9.png', email: 'marcus.finn@domain.com', name: 'Marcus Finn' },
|
||||||
|
to: [{ avatar: '/assets/avatar.png', email: 'sofia@devias.io', name: 'Sofia Rivers' }],
|
||||||
|
subject: 'Website redesign. Interested in collaboration',
|
||||||
|
message: `Hey there,
|
||||||
|
|
||||||
|
I hope this email finds you well. I'm glad you liked my projects, and I would be happy to provide you with a quote for a similar project.
|
||||||
|
|
||||||
|
Please let me know your requirements and any specific details you have in mind, so I can give you an accurate quote.
|
||||||
|
|
||||||
|
Looking forward to hearing from you soon.
|
||||||
|
|
||||||
|
Best regards,
|
||||||
|
|
||||||
|
Marcus Finn`,
|
||||||
|
attachments: [
|
||||||
|
{
|
||||||
|
id: 'ATT-001',
|
||||||
|
name: 'working-sketch.png',
|
||||||
|
size: '128.5 KB',
|
||||||
|
type: 'image',
|
||||||
|
url: '/assets/image-abstract-1.png',
|
||||||
|
},
|
||||||
|
{ id: 'ATT-002', name: 'summer-customers.pdf', size: '782.3 KB', type: 'file', url: '#' },
|
||||||
|
{
|
||||||
|
id: 'ATT-003',
|
||||||
|
name: 'desktop-coffee.png',
|
||||||
|
size: '568.2 KB',
|
||||||
|
type: 'image',
|
||||||
|
url: '/assets/image-minimal-1.png',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
folder: 'inbox',
|
||||||
|
labels: ['work', 'business'],
|
||||||
|
isImportant: true,
|
||||||
|
isStarred: false,
|
||||||
|
isUnread: true,
|
||||||
|
createdAt: dayjs().subtract(3, 'hour').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'TRD-003',
|
||||||
|
to: [{ name: 'Sofia Rivers', avatar: '/assets/avatar.png', email: 'sofia@devias.io' }],
|
||||||
|
from: { name: 'Miron Vitold', avatar: '/assets/avatar-1.png', email: 'miron.vitold@domain.com' },
|
||||||
|
subject: 'Amazing work',
|
||||||
|
message: `Hey, nice projects! I really liked the one in react. What's your quote on kinda similar project?`,
|
||||||
|
folder: 'spam',
|
||||||
|
labels: [],
|
||||||
|
isImportant: false,
|
||||||
|
isStarred: true,
|
||||||
|
isUnread: false,
|
||||||
|
createdAt: dayjs().subtract(1, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'TRD-002',
|
||||||
|
from: { name: 'Penjani Inyene', avatar: '/assets/avatar-4.png', email: 'penjani.inyene@domain.com' },
|
||||||
|
to: [{ name: 'Sofia Rivers', avatar: '/assets/avatar.png', email: 'sofia@devias.io' }],
|
||||||
|
subject: 'Flight reminder',
|
||||||
|
message: `Dear Sofia,
|
||||||
|
|
||||||
|
Your flight is coming up soon. Please don't forget to check in for your scheduled flight.`,
|
||||||
|
folder: 'inbox',
|
||||||
|
labels: ['business'],
|
||||||
|
isImportant: false,
|
||||||
|
isStarred: false,
|
||||||
|
isUnread: false,
|
||||||
|
createdAt: dayjs().subtract(2, 'day').toDate(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'TRD-001',
|
||||||
|
from: { name: 'Carson Darrin', avatar: '/assets/avatar-3.png', email: 'carson.darrin@domain.com' },
|
||||||
|
to: [{ name: 'Sofia Rivers', avatar: '/assets/avatar.png', email: 'sofia@devias.io' }],
|
||||||
|
subject: 'Possible candidates for the position',
|
||||||
|
message: `My market leading client has another fantastic opportunity for an experienced Software Developer to join them on a heavily remote basis`,
|
||||||
|
folder: 'trash',
|
||||||
|
labels: ['personal'],
|
||||||
|
isImportant: false,
|
||||||
|
isStarred: false,
|
||||||
|
isUnread: true,
|
||||||
|
createdAt: dayjs().subtract(2, 'day').toDate(),
|
||||||
|
},
|
||||||
|
] satisfies Thread[];
|
||||||
|
|
||||||
|
interface LayoutProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: { labelId: string };
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Layout({ children, params }: LayoutProps): React.JSX.Element {
|
||||||
|
const { labelId } = params;
|
||||||
|
|
||||||
|
const filteredThreads = filterThreads(threads, labelId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MailProvider currentLabelId={labelId} labels={labels} threads={filteredThreads}>
|
||||||
|
<MailView>{children}</MailView>
|
||||||
|
</MailProvider>
|
||||||
|
);
|
||||||
|
}
|
@@ -0,0 +1,11 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import type { Metadata } from 'next';
|
||||||
|
|
||||||
|
import { config } from '@/config';
|
||||||
|
import { ThreadsView } from '@/components/dashboard/mail/threads-view';
|
||||||
|
|
||||||
|
export const metadata = { title: `Mail | Dashboard | ${config.site.name}` } satisfies Metadata;
|
||||||
|
|
||||||
|
export default function Page(): React.JSX.Element {
|
||||||
|
return <ThreadsView />;
|
||||||
|
}
|
@@ -0,0 +1,80 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import Avatar from '@mui/material/Avatar';
|
||||||
|
import Card from '@mui/material/Card';
|
||||||
|
import CardHeader from '@mui/material/CardHeader';
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
import Divider from '@mui/material/Divider';
|
||||||
|
import IconButton from '@mui/material/IconButton';
|
||||||
|
import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';
|
||||||
|
import { User as UserIcon } from '@phosphor-icons/react/dist/ssr/User';
|
||||||
|
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 { User } from '@/components/dashboard/user/type.d';
|
||||||
|
|
||||||
|
export default function BasicDetailCard({
|
||||||
|
user: model,
|
||||||
|
handleEditClick,
|
||||||
|
}: {
|
||||||
|
user: User;
|
||||||
|
handleEditClick: () => void;
|
||||||
|
}): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader
|
||||||
|
action={
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
handleEditClick();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PencilSimpleIcon />
|
||||||
|
</IconButton>
|
||||||
|
}
|
||||||
|
avatar={
|
||||||
|
<Avatar>
|
||||||
|
<UserIcon fontSize="var(--Icon-fontSize)" />
|
||||||
|
</Avatar>
|
||||||
|
}
|
||||||
|
title={t('list.basic-details')}
|
||||||
|
/>
|
||||||
|
<PropertyList
|
||||||
|
divider={<Divider />}
|
||||||
|
orientation="vertical"
|
||||||
|
sx={{ '--PropertyItem-padding': '12px 24px' }}
|
||||||
|
>
|
||||||
|
{(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'Customer ID',
|
||||||
|
value: (
|
||||||
|
<Chip
|
||||||
|
label={model.id}
|
||||||
|
size="small"
|
||||||
|
variant="soft"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ key: 'Email', value: model.email },
|
||||||
|
{ key: 'Quota', value: model.quota },
|
||||||
|
{ key: 'Status', value: model.status },
|
||||||
|
] satisfies { key: string; value: React.ReactNode }[]
|
||||||
|
).map(
|
||||||
|
(item): React.JSX.Element => (
|
||||||
|
<PropertyItem
|
||||||
|
key={item.key}
|
||||||
|
name={item.key}
|
||||||
|
value={item.value}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</PropertyList>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
@@ -0,0 +1,76 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Button } from '@mui/material';
|
||||||
|
import Avatar from '@mui/material/Avatar';
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/CaretDown';
|
||||||
|
import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import type { Student } from '@/components/dashboard/student/type.d';
|
||||||
|
|
||||||
|
// import type { CrCategory } from '@/components/dashboard/cr/categories/type';
|
||||||
|
|
||||||
|
function getImageUrlFrRecord(record: Student): string {
|
||||||
|
// TODO: fix this
|
||||||
|
// `http://127.0.0.1:8090/api/files/${'record.collectionId'}/${'record.id'}/${'record.cat_image'}`;
|
||||||
|
return 'getImageUrlFrRecord(helloworld)';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SampleTitleCard({ user: lpModel }: { user: Student }): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
spacing={2}
|
||||||
|
sx={{ alignItems: 'center', flex: '1 1 auto' }}
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
variant="rounded"
|
||||||
|
src={getImageUrlFrRecord(lpModel)}
|
||||||
|
sx={{ '--Avatar-size': '64px' }}
|
||||||
|
>
|
||||||
|
{t('empty')}
|
||||||
|
</Avatar>
|
||||||
|
<div>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
spacing={2}
|
||||||
|
sx={{ alignItems: 'center', flexWrap: 'wrap' }}
|
||||||
|
>
|
||||||
|
<Typography variant="h4">{lpModel.email}</Typography>
|
||||||
|
<Chip
|
||||||
|
icon={
|
||||||
|
<CheckCircleIcon
|
||||||
|
color="var(--mui-palette-success-main)"
|
||||||
|
weight="fill"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={lpModel.quota}
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Typography
|
||||||
|
color="text.secondary"
|
||||||
|
variant="body1"
|
||||||
|
>
|
||||||
|
{lpModel.status}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
endIcon={<CaretDownIcon />}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
{t('list.action')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
144
002_source/cms/src/app/dashboard/users/view/[id]/page.tsx
Normal file
144
002_source/cms/src/app/dashboard/users/view/[id]/page.tsx
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
'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/user/notifications';
|
||||||
|
import FormLoading from '@/components/loading';
|
||||||
|
import BasicDetailCard from './BasicDetailCard';
|
||||||
|
import TitleCard from './TitleCard';
|
||||||
|
import { defaultUser } from '@/components/dashboard/user/_constants';
|
||||||
|
import type { User } from '@/components/dashboard/user/type.d';
|
||||||
|
import { COL_USERS } from '@/constants';
|
||||||
|
|
||||||
|
export default function Page(): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const router = useRouter();
|
||||||
|
//
|
||||||
|
const { id: userId } = useParams<{ id: string }>();
|
||||||
|
//
|
||||||
|
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||||
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
//
|
||||||
|
const [showUser, setShowUser] = React.useState<User>(defaultUser);
|
||||||
|
|
||||||
|
function handleEditClick(): void {
|
||||||
|
router.push(paths.dashboard.users.edit(showUser.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (userId) {
|
||||||
|
pb.collection(COL_USERS)
|
||||||
|
.getOne(userId)
|
||||||
|
.then((model: RecordModel) => {
|
||||||
|
setShowUser({ ...defaultUser, ...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
|
||||||
|
}, [userId]);
|
||||||
|
|
||||||
|
// 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.users.list}
|
||||||
|
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||||
|
variant="subtitle2"
|
||||||
|
>
|
||||||
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
|
Users
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<Stack
|
||||||
|
direction={{ xs: 'column', sm: 'row' }}
|
||||||
|
spacing={3}
|
||||||
|
sx={{ alignItems: 'flex-start' }}
|
||||||
|
>
|
||||||
|
<TitleCard user={showUser} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={4}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
lg={4}
|
||||||
|
xs={12}
|
||||||
|
>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<BasicDetailCard
|
||||||
|
user={showUser}
|
||||||
|
handleEditClick={handleEditClick}
|
||||||
|
/>
|
||||||
|
<SampleSecurityCard />
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
lg={8}
|
||||||
|
xs={12}
|
||||||
|
>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<SamplePaymentCard />
|
||||||
|
<SampleAddressCard />
|
||||||
|
<Notifications notifications={SampleNotifications} />
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
@@ -0,0 +1,80 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import Avatar from '@mui/material/Avatar';
|
||||||
|
import Card from '@mui/material/Card';
|
||||||
|
import CardHeader from '@mui/material/CardHeader';
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
import Divider from '@mui/material/Divider';
|
||||||
|
import IconButton from '@mui/material/IconButton';
|
||||||
|
import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple';
|
||||||
|
import { User as UserIcon } from '@phosphor-icons/react/dist/ssr/User';
|
||||||
|
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 { Student } from '@/components/dashboard/student/type.d';
|
||||||
|
|
||||||
|
export default function BasicDetailCard({
|
||||||
|
lpModel: model,
|
||||||
|
handleEditClick,
|
||||||
|
}: {
|
||||||
|
lpModel: Student;
|
||||||
|
handleEditClick: () => void;
|
||||||
|
}): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader
|
||||||
|
action={
|
||||||
|
<IconButton
|
||||||
|
onClick={() => {
|
||||||
|
handleEditClick();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PencilSimpleIcon />
|
||||||
|
</IconButton>
|
||||||
|
}
|
||||||
|
avatar={
|
||||||
|
<Avatar>
|
||||||
|
<UserIcon fontSize="var(--Icon-fontSize)" />
|
||||||
|
</Avatar>
|
||||||
|
}
|
||||||
|
title={t('list.basic-details')}
|
||||||
|
/>
|
||||||
|
<PropertyList
|
||||||
|
divider={<Divider />}
|
||||||
|
orientation="vertical"
|
||||||
|
sx={{ '--PropertyItem-padding': '12px 24px' }}
|
||||||
|
>
|
||||||
|
{(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'Customer ID',
|
||||||
|
value: (
|
||||||
|
<Chip
|
||||||
|
label={model.id}
|
||||||
|
size="small"
|
||||||
|
variant="soft"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{ key: 'Email', value: model.email },
|
||||||
|
{ key: 'Quota', value: model.quota },
|
||||||
|
{ key: 'Status', value: model.status },
|
||||||
|
] satisfies { key: string; value: React.ReactNode }[]
|
||||||
|
).map(
|
||||||
|
(item): React.JSX.Element => (
|
||||||
|
<PropertyItem
|
||||||
|
key={item.key}
|
||||||
|
name={item.key}
|
||||||
|
value={item.value}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</PropertyList>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
76
002_source/cms/src/app/dashboard/users/xxx/TitleCard.tsx
Normal file
76
002_source/cms/src/app/dashboard/users/xxx/TitleCard.tsx
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import { Button } from '@mui/material';
|
||||||
|
import Avatar from '@mui/material/Avatar';
|
||||||
|
import Chip from '@mui/material/Chip';
|
||||||
|
import Stack from '@mui/material/Stack';
|
||||||
|
import Typography from '@mui/material/Typography';
|
||||||
|
import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/CaretDown';
|
||||||
|
import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import type { Student } from '@/components/dashboard/student/type.d';
|
||||||
|
|
||||||
|
// import type { CrCategory } from '@/components/dashboard/cr/categories/type';
|
||||||
|
|
||||||
|
function getImageUrlFrRecord(record: Student): string {
|
||||||
|
// TODO: fix this
|
||||||
|
// `http://127.0.0.1:8090/api/files/${'record.collectionId'}/${'record.id'}/${'record.cat_image'}`;
|
||||||
|
return 'getImageUrlFrRecord(helloworld)';
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function SampleTitleCard({ lpModel }: { lpModel: Student }): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
spacing={2}
|
||||||
|
sx={{ alignItems: 'center', flex: '1 1 auto' }}
|
||||||
|
>
|
||||||
|
<Avatar
|
||||||
|
variant="rounded"
|
||||||
|
src={getImageUrlFrRecord(lpModel)}
|
||||||
|
sx={{ '--Avatar-size': '64px' }}
|
||||||
|
>
|
||||||
|
{t('empty')}
|
||||||
|
</Avatar>
|
||||||
|
<div>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
spacing={2}
|
||||||
|
sx={{ alignItems: 'center', flexWrap: 'wrap' }}
|
||||||
|
>
|
||||||
|
<Typography variant="h4">{lpModel.email}</Typography>
|
||||||
|
<Chip
|
||||||
|
icon={
|
||||||
|
<CheckCircleIcon
|
||||||
|
color="var(--mui-palette-success-main)"
|
||||||
|
weight="fill"
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={lpModel.quota}
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Typography
|
||||||
|
color="text.secondary"
|
||||||
|
variant="body1"
|
||||||
|
>
|
||||||
|
{lpModel.status}
|
||||||
|
</Typography>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
<div>
|
||||||
|
<Button
|
||||||
|
endIcon={<CaretDownIcon />}
|
||||||
|
variant="contained"
|
||||||
|
>
|
||||||
|
{t('list.action')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
142
002_source/cms/src/app/dashboard/users/xxx/page.tsx
Normal file
142
002_source/cms/src/app/dashboard/users/xxx/page.tsx
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
'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/student/notifications';
|
||||||
|
import FormLoading from '@/components/loading';
|
||||||
|
import BasicDetailCard from './BasicDetailCard';
|
||||||
|
import TitleCard from './TitleCard';
|
||||||
|
import { defaultStudent } from '@/components/dashboard/student/_constants';
|
||||||
|
import type { Student } from '@/components/dashboard/student/type.d';
|
||||||
|
import { COL_STUDENTS } from '@/constants';
|
||||||
|
|
||||||
|
export default function Page(): React.JSX.Element {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const router = useRouter();
|
||||||
|
//
|
||||||
|
const { customerId } = useParams<{ customerId: string }>();
|
||||||
|
//
|
||||||
|
const [showLoading, setShowLoading] = React.useState<boolean>(true);
|
||||||
|
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||||
|
//
|
||||||
|
const [showLessonCategory, setShowLessonCategory] = React.useState<Student>(defaultStudent);
|
||||||
|
|
||||||
|
function handleEditClick(): void {
|
||||||
|
router.push(paths.dashboard.students.edit(showLessonCategory.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (customerId) {
|
||||||
|
pb.collection(COL_STUDENTS)
|
||||||
|
.getOne(customerId)
|
||||||
|
.then((model: RecordModel) => {
|
||||||
|
setShowLessonCategory({ ...defaultStudent, ...model });
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
logger.error(err);
|
||||||
|
toast(t('list.error'));
|
||||||
|
|
||||||
|
setShowError({ show: true, detail: JSON.stringify(err) });
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
setShowLoading(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [customerId]);
|
||||||
|
|
||||||
|
// 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.students.list}
|
||||||
|
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||||
|
variant="subtitle2"
|
||||||
|
>
|
||||||
|
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
|
||||||
|
Students
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<Stack
|
||||||
|
direction={{ xs: 'column', sm: 'row' }}
|
||||||
|
spacing={3}
|
||||||
|
sx={{ alignItems: 'flex-start' }}
|
||||||
|
>
|
||||||
|
<TitleCard lpModel={showLessonCategory} />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={4}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
lg={4}
|
||||||
|
xs={12}
|
||||||
|
>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<BasicDetailCard
|
||||||
|
lpModel={showLessonCategory}
|
||||||
|
handleEditClick={handleEditClick}
|
||||||
|
/>
|
||||||
|
<SampleSecurityCard />
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
lg={8}
|
||||||
|
xs={12}
|
||||||
|
>
|
||||||
|
<Stack spacing={4}>
|
||||||
|
<SamplePaymentCard />
|
||||||
|
<SampleAddressCard />
|
||||||
|
<Notifications notifications={SampleNotifications} />
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
Reference in New Issue
Block a user