This commit is contained in:
louiscklaw
2025-05-08 17:19:43 +08:00
parent 7105bc85e3
commit 5640d4d4f6
46 changed files with 520 additions and 268 deletions

View File

@@ -1,18 +0,0 @@
please review and update all tsx files in folder `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Users` to make it handle `user` record thanks
---
please modify and update `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/students/edit/[customerId]/page.tsx.draft` to handle `Student` record thanks,
modify comments/variables/paths/functions name please
---
please help to update the tsx files inside folder `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/components/dashboard/student` to handle the `student` record
## steps
- list all `tsx` files inside directory, remember the list
- clone the original `<original>.tsx` files to `<original>.tsx.draft`
- do all your modification within `<original>.tsx.draft` files, leave `original.tsx` unchange
---

View File

@@ -1,33 +0,0 @@
Hi, i need your help.
## task
i am working on a `dbml` file
i got a `schema.json` which is exported from pocketbase
and i want to update it to my current `dbml` file (one way process for documentation usage)
## Rules
- the collection from `json` file started with `_` can be ignored. they are system collection and should not appear in `dbml`
- one collection from `json` file mapped with one table in `dbml` file
- the `presentable` field from `json` file should be ignored.
- the `id` of collection in `json` file should be jod down in the comment of `dbml` file as an reference.
- you can find the comments in `schema.dbml` contains `pb_xxx` and that is the reference to the table in `schema.json` file.
## steps
- list the collection
## information
json file: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.json`
dbml file: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.dbml`
## FAQ
1. 对于json中有但dbml中没有的表应该如何处理 添加为新表
1. 是否需要保留dbml文件中现有的注释和关系定义 完全保留
1. 字段类型映射是否有特殊规则? 沒有
1. please keep the existing comment
thanks

View File

@@ -1,7 +0,0 @@
# FAQ
Q: where is `dbml` file ?
A: dbml file located in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.dbml`
Q: when file not found, do i need to search it in `_ignore_this_directory` ?
A: No, you just stop there and voice out.

View File

@@ -1,8 +0,0 @@
Hi, i will send you the guideline,
plesae read it, prepare yourself and i will tell you the task afterwards
please read and understand the markdown files in directory
`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/_AI_WORKSPACE/greetings`,
it provides background information of project i want you to help.
thanks

View File

@@ -1,28 +0,0 @@
# guideline
## principles
- at any time, please keep your answer, solution, explaination simple and short (K.I.S.S. or 大道至簡)
- please divide the problem into small parts
- if you found youself cannot understand the problem, please stop and ask how to do
- if you found youself cannot solve the problem, plesae stop and ask how to do
- review the whole solution before you reply to user
- if code syntax is already there, do follow (e.g. naming convention, syntax) the existing code
- no need to explain the reason until you are told to do so
- no need to show me the code change, at the end just simple summary in point form is ok
## highlighted project directories and their meanings
- `_ignore_this_directory` please ignore this directory and any files inside it
- `001_documentation` documentation of this project
- `002_source` source code of this project
- `002_source/cms` home of Context management system of this project
- `002_source/ionic` home of mobile client of this project
- `002_source/pocketbase` home of pocketbase home directory this project
- `003_test` e2e test of this project (not yet implemented)
- `004_marketing` marketing page of this project (not yet implemented)
- `005_references` opensource refence of this project
- `006_lab` my test (POC) of this project
- `README.md` Readme of this project
- `TODO.md` todo list of this project

View File

@@ -1,12 +0,0 @@
# Knowledgebase
you can answer the question with below knowledge:
## frameworks and stacks
- if code syntax is already there, do follow (e.g. naming convention, syntax) the existing code
- make use of MCP `Context7` when you troubleshoot the problem with below topics:
- [pocketbase javascript SDK](https://context7.com/pocketbase/js-sdk/llms.txt)
- [DBML](https://context7.com/holistics/dbml/llms.txt)
- [ionic framework](https://context7.com/ionic-team/ionic-framework/llms.txt)
- [nextjs 14 app router](https://context7.com/nextjsargentina/next.js-docs/llms.txt)

View File

@@ -1,48 +0,0 @@
# AI GUIDELINE
## getting started
Imagine there is a:
1. developer (provide the modification)
2. QA engineer (provide the feedback, and testing)
3. software engineer
4. technical writer
they will:
- conclude and integrate the ideas from developer and QA engineer
- make decision to modify the code accordingly.
## project background and initial setup
- **IMPORTANT**: No need to reply me what you are going on and your digest in this phase.
No need to show me your code plan
Just reply me "OK" when done
- base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project`
- `schema.dbml`
- read `<base_dir>/001_documentation/Requirements/REQ0006/schema.dbml`
this is file in `dbml` format stating the main database structure
- `schema.json`
- read `<base_dir>/002_source/cms/src/db/schema.json`
this is the file of current pocketbase schema
- look into the md files in folder `<base_dir>/002_source/ionic_mobile/_AI_WORKSPACE/001_guideline`
- if the directory user provided contins `_GUIDELINES.md`, please read the file
- read the files, remember and link up the ideas in file stated above, i will tell them the task afterwards
- please review at least 3 times after you modified the code
## frameworks documentation and samples
- react
- ionic and capacitor
- pocketbase
- tanstack/react-query
- vite
- typescript

View File

@@ -0,0 +1,3 @@
{
"back-to-list": "Teachers"
}

View File

@@ -1,3 +1,6 @@
{
"languageChanged": "Sprache geändert"
"languageChanged": "Sprache geändert",
"teachers": {
"back-to-list": "Lehrer"
}
}

View File

@@ -1,3 +1,4 @@
{
"hello": "world"
}
"hello": "world",
"teachers": "teachers"
}

View File

@@ -0,0 +1,3 @@
{
"back-to-list": "Teachers"
}

View File

@@ -0,0 +1,3 @@
{
"back-to-list": "Teachers"
}

View File

@@ -1,3 +1,7 @@
{
"languageChanged": "Language changed"
"languageChanged": "Language changed",
"teachers": {
"nav-title": "teachers",
"back-to-list": "Teachers"
}
}

View File

@@ -0,0 +1,3 @@
{
"back-to-list": "Teachers"
}

View File

@@ -1,3 +1,6 @@
{
"languageChanged": "Idioma cambiado"
"languageChanged": "Idioma cambiado",
"teachers": {
"back-to-list": "Profesores"
}
}

View File

@@ -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/app/dashboard/students/create/page.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please
e.g. why `lessonCategories` still exist ?

View File

@@ -0,0 +1 @@
this `tsx` file is clone from elsewhere, please understand, modify and update the content of `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/students/edit/[customerId]/page.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please

View File

@@ -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/app/dashboard/students/list/page.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please
e.g. why `lessonCategories` still exist ?

View File

@@ -3,11 +3,10 @@
// RULES:
// contains list page for students (Students)
// contain definition to collection only
//
import * as React from 'react';
import { useRouter } from 'next/navigation';
import { COL_STUDENTS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
import { LoadingButton } from '@mui/lab';
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
@@ -38,8 +37,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
const { email, phone, sortDir, status } = searchParams;
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<Student[]>([]);
//
const [studentsData, setStudentsData] = React.useState<Student[]>([]);
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
const [showLoading, setShowLoading] = React.useState<boolean>(true);
@@ -51,24 +49,31 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
const [currentPage, setCurrentPage] = React.useState<number>(0);
//
const [recordCount, setRecordCount] = React.useState<number>(0);
const [listOption, setListOption] = React.useState({});
const [listOption, setListOption] = React.useState({ filter: '' });
const [listSort, setListSort] = React.useState({});
function isListOptionChanged(): boolean {
return JSON.stringify(listOption) === JSON.stringify({ filter: '' });
}
//
const reloadRows = async (): Promise<void> => {
try {
const listOptionTeacherOnly = isListOptionChanged()
? { filter: `role = "student"` }
: { filter: [listOption.filter, `role = "student"`].join(' && ') };
const models: ListResult<RecordModel> = await pb
.collection(COL_STUDENTS)
.getList(currentPage + 1, rowsPerPage, listOption);
.collection(COL_USER_METAS)
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
const { items, totalItems } = models;
const tempLessonTypes: Student[] = items.map((lt) => {
const tempStudents: Student[] = items.map((lt) => {
return { ...defaultStudent, ...lt };
});
setLessonCategoriesData(tempLessonTypes);
setStudentsData(tempStudents);
setRecordCount(totalItems);
setF(tempLessonTypes);
setF(tempStudents);
} catch (error) {
//
logger.error(error);
setShowError({
//
@@ -110,11 +115,12 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
if (email) {
tempFilter.push(`email ~ "%${email}%"`);
}
if (phone) {
tempFilter.push(`phone ~ "%${phone}%"`);
}
let preFinalListOption = {};
let preFinalListOption = { filter: '' };
if (tempFilter.length > 0) {
preFinalListOption = { filter: tempFilter.join(' && ') };
}
@@ -158,7 +164,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.students.create);
}}
startIcon={<PlusIcon />}
variant="contained"
@@ -167,11 +173,11 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
</LoadingButton>
</Box>
</Stack>
<StudentsSelectionProvider customers={f}>
<StudentsSelectionProvider students={f}>
<Card>
<StudentsFilters
filters={{ email, phone, status }}
fullData={lessonCategoriesData}
fullData={studentsData}
sortDir={sortDir}
/>
<Divider />

View File

@@ -17,10 +17,10 @@ import { PropertyList } from '@/components/core/property-list';
import type { Student } from '@/components/dashboard/student/type.d';
export default function BasicDetailCard({
lpModel: model,
studentRecord: model,
handleEditClick,
}: {
lpModel: Student;
studentRecord: Student;
handleEditClick: () => void;
}): React.JSX.Element {
const { t } = useTranslation();

View File

@@ -13,13 +13,11 @@ 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)';
function getImageUrlForStudent(student: Student): string {
return `http://127.0.0.1:8090/api/files/${student.collectionId}/${student.id}/${student.avatar}`;
}
export default function SampleTitleCard({ lpModel }: { lpModel: Student }): React.JSX.Element {
export default function SampleTitleCard({ studentRecord }: { studentRecord: Student }): React.JSX.Element {
const { t } = useTranslation();
return (
@@ -31,7 +29,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Student }): Reac
>
<Avatar
variant="rounded"
src={getImageUrlFrRecord(lpModel)}
src={getImageUrlForStudent(studentRecord)}
sx={{ '--Avatar-size': '64px' }}
>
{t('empty')}
@@ -42,7 +40,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Student }): Reac
spacing={2}
sx={{ alignItems: 'center', flexWrap: 'wrap' }}
>
<Typography variant="h4">{lpModel.email}</Typography>
<Typography variant="h4">{studentRecord.name || studentRecord.email}</Typography>
<Chip
icon={
<CheckCircleIcon
@@ -50,17 +48,11 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Student }): Reac
weight="fill"
/>
}
label={lpModel.quota}
label={studentRecord.status}
size="small"
variant="outlined"
/>
</Stack>
<Typography
color="text.secondary"
variant="body1"
>
{lpModel.status}
</Typography>
</div>
</Stack>
<div>

View File

@@ -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/app/dashboard/students/view/[customerId]/page.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please
e.g. update `lpModel` names

View File

@@ -30,29 +30,29 @@ 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';
import { COL_USER_METAS } from '@/constants';
export default function Page(): React.JSX.Element {
const { t } = useTranslation();
const router = useRouter();
//
const { customerId } = useParams<{ customerId: string }>();
const { id: studentId } = useParams<{ id: string }>();
//
const [showLoading, setShowLoading] = React.useState<boolean>(true);
const [showError, setShowError] = React.useState({ show: false, detail: '' });
//
const [showLessonCategory, setShowLessonCategory] = React.useState<Student>(defaultStudent);
const [studentRecord, setStudentRecord] = React.useState<Student>(defaultStudent);
function handleEditClick(): void {
router.push(paths.dashboard.students.edit(showLessonCategory.id));
router.push(paths.dashboard.students.edit(studentRecord.id));
}
React.useEffect(() => {
if (customerId) {
pb.collection(COL_STUDENTS)
.getOne(customerId)
if (studentId) {
pb.collection(COL_USER_METAS)
.getOne(studentId)
.then((model: RecordModel) => {
setShowLessonCategory({ ...defaultStudent, ...model });
setStudentRecord({ ...defaultStudent, ...model });
})
.catch((err) => {
logger.error(err);
@@ -64,9 +64,9 @@ export default function Page(): React.JSX.Element {
setShowLoading(false);
});
}
}, [customerId]);
}, [studentId]);
// return <>{JSON.stringify({ showError, showLessonCategory }, null, 2)}</>;
// return <>{JSON.stringify({ showError, studentRecord }, null, 2)}</>;
if (showLoading) return <FormLoading />;
if (showError.show)
@@ -106,7 +106,7 @@ export default function Page(): React.JSX.Element {
spacing={3}
sx={{ alignItems: 'flex-start' }}
>
<TitleCard lpModel={showLessonCategory} />
<TitleCard studentRecord={studentRecord} />
</Stack>
</Stack>
<Grid
@@ -119,7 +119,7 @@ export default function Page(): React.JSX.Element {
>
<Stack spacing={4}>
<BasicDetailCard
lpModel={showLessonCategory}
studentRecord={studentRecord}
handleEditClick={handleEditClick}
/>
<SampleSecurityCard />

View File

@@ -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/app/dashboard/teachers/list/page.tsx.draft` to handle `Teacher` record thanks, modify comments/variables/paths/functions name please
e.g. why `lessonCategories` still exist ?

View File

@@ -37,7 +37,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
const { email, phone, sortDir, status } = searchParams;
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<Teacher[]>([]);
const [teacherData, setTeacherData] = React.useState<Teacher[]>([]);
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
const [showLoading, setShowLoading] = React.useState<boolean>(true);
@@ -53,7 +53,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
const [listSort, setListSort] = React.useState({});
function isListOptionChanged() {
return JSON.stringify(listOption) === '{}';
return JSON.stringify(listOption) === JSON.stringify({ filter: '' });
}
//
const reloadRows = async (): Promise<void> => {
@@ -62,6 +62,8 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
? { filter: `role = "teacher"` }
: { filter: [listOption.filter, `role = "teacher"`].join(' && ') };
console.log({ listOptionTeacherOnly });
const models: ListResult<RecordModel> = await pb
.collection(COL_USER_METAS)
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
@@ -70,12 +72,13 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
return { ...defaultTeacher, ...lt };
});
setLessonCategoriesData(tempTeacher);
setTeacherData(tempTeacher);
setRecordCount(totalItems);
setF(tempTeacher);
} catch (error) {
logger.error(error);
setShowError({
//
show: true,
detail: JSON.stringify(error, null, 2),
});
@@ -100,8 +103,8 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
}, [currentPage, rowsPerPage, listOption]);
React.useEffect(() => {
let tempFilter = [],
tempSortDir = '';
let tempFilter = [];
let tempSortDir = '';
if (status) {
tempFilter.push(`status = "${status}"`);
@@ -119,7 +122,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
tempFilter.push(`phone ~ "%${phone}%"`);
}
let preFinalListOption = {};
let preFinalListOption = { filter: '' };
if (tempFilter.length > 0) {
preFinalListOption = { filter: tempFilter.join(' && ') };
}
@@ -176,7 +179,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
<Card>
<TeachersFilters
filters={{ email, phone, status }}
fullData={lessonCategoriesData}
fullData={teacherData}
sortDir={sortDir}
/>
<Divider />
@@ -205,5 +208,11 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
}
interface PageProps {
searchParams: { email?: string; phone?: string; sortDir?: 'asc' | 'desc'; status?: string };
searchParams: {
email?: string;
phone?: string;
sortDir?: 'asc' | 'desc';
status?: string;
//
};
}

View File

@@ -0,0 +1,216 @@
// src/app/dashboard/teachers/list/page.tsx
'use client';
// RULES:
// contains list page for teachers (Teachers)
//
import * as React from 'react';
import { useRouter } from 'next/navigation';
import { COL_USER_METAS } from '@/constants';
import { LoadingButton } from '@mui/lab';
import Box from '@mui/material/Box';
import Card from '@mui/material/Card';
import Divider from '@mui/material/Divider';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
import type { ListResult, RecordModel } from 'pocketbase';
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination';
import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context';
import { TeachersTable } from '@/components/dashboard/teacher/teachers-table';
import type { Teacher } from '@/components/dashboard/teacher/type.d';
import { useTranslation } from 'react-i18next';
import { paths } from '@/paths';
import isDevelopment from '@/lib/check-is-development';
import { logger } from '@/lib/default-logger';
import { pb } from '@/lib/pb';
import ErrorDisplay from '@/components/dashboard/error';
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
import FormLoading from '@/components/loading';
export default function Page({ searchParams }: PageProps): React.JSX.Element {
const { t } = useTranslation(['teachers']);
const router = useRouter();
const { email, phone, sortDir, status } = searchParams;
const [teacherData, setTeacherData] = React.useState<Teacher[]>([]);
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
const [showLoading, setShowLoading] = React.useState<boolean>(true);
const [showError, setShowError] = React.useState({ show: false, detail: '' });
//
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
//
const [f, setF] = React.useState<Teacher[]>([]);
const [currentPage, setCurrentPage] = React.useState<number>(0);
//
const [recordCount, setRecordCount] = React.useState<number>(0);
const [listOption, setListOption] = React.useState({ filter: '' });
const [listSort, setListSort] = React.useState({});
function isListOptionChanged() {
return JSON.stringify(listOption) === '{}';
}
//
const reloadRows = async (): Promise<void> => {
try {
const listOptionTeacherOnly = isListOptionChanged()
? { filter: `role = "teacher"` }
: { filter: [listOption.filter, `role = "teacher"`].join(' && ') };
const models: ListResult<RecordModel> = await pb
.collection(COL_USER_METAS)
.getList(currentPage + 1, rowsPerPage, listOptionTeacherOnly);
const { items, totalItems } = models;
const tempTeacher: Teacher[] = items.map((lt) => {
return { ...defaultTeacher, ...lt };
});
setTeacherData(tempTeacher);
setRecordCount(totalItems);
setF(tempTeacher);
} catch (error) {
logger.error(error);
setShowError({
//
show: true,
detail: JSON.stringify(error, null, 2),
});
} finally {
setShowLoading(false);
}
};
const [lastListOption, setLastListOption] = React.useState({});
const isFirstRun = React.useRef(false);
React.useEffect(() => {
if (!isFirstRun.current) {
isFirstRun.current = true;
} else if (JSON.stringify(listOption) !== JSON.stringify(lastListOption)) {
// reset page number as tab changes
setLastListOption(listOption);
setCurrentPage(0);
void reloadRows();
} else {
void reloadRows();
}
}, [currentPage, rowsPerPage, listOption]);
React.useEffect(() => {
const tempFilter = [];
let tempSortDir = '';
if (status) {
tempFilter.push(`status = "${status}"`);
}
if (sortDir) {
tempSortDir = `-created`;
}
if (email) {
tempFilter.push(`email ~ "%${email}%"`);
}
if (phone) {
tempFilter.push(`phone ~ "%${phone}%"`);
}
let preFinalListOption = { filter: '' };
if (tempFilter.length > 0) {
preFinalListOption = { filter: tempFilter.join(' && ') };
}
if (tempSortDir.length > 0) {
preFinalListOption = { ...preFinalListOption, sort: tempSortDir };
}
setListOption(preFinalListOption);
}, [sortDir, email, phone, status]);
if (showLoading) return <FormLoading />;
if (showError.show)
return (
<ErrorDisplay
message={t('error.unable-to-process-request')}
code={-1}
details={showError.detail}
/>
);
return (
<Box
sx={{
maxWidth: 'var(--Content-maxWidth)',
m: 'var(--Content-margin)',
p: 'var(--Content-padding)',
width: 'var(--Content-width)',
}}
>
<Stack spacing={4}>
<Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={3}
sx={{ alignItems: 'flex-start' }}
>
<Box sx={{ flex: '1 1 auto' }}>
<Typography variant="h4">{t('list.title')}</Typography>
</Box>
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
<LoadingButton
loading={isLoadingAddPage}
onClick={(): void => {
setIsLoadingAddPage(true);
router.push(paths.dashboard.teachers.create);
}}
startIcon={<PlusIcon />}
variant="contained"
>
{t('list.add')}
</LoadingButton>
</Box>
</Stack>
<TeachersSelectionProvider teachers={f}>
<Card>
<TeachersFilters
filters={{ email, phone, status }}
fullData={teacherData}
sortDir={sortDir}
/>
<Divider />
<Box sx={{ overflowX: 'auto' }}>
<TeachersTable
reloadRows={reloadRows}
rows={f}
/>
</Box>
<Divider />
<TeachersPagination
count={recordCount}
page={currentPage}
rowsPerPage={rowsPerPage}
setPage={setCurrentPage}
setRowsPerPage={setRowsPerPage}
/>
</Card>
</TeachersSelectionProvider>
</Stack>
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
<pre>{JSON.stringify(f, null, 2)}</pre>
</Box>
</Box>
);
}
interface PageProps {
searchParams: {
email?: string;
phone?: string;
sortDir?: 'asc' | 'desc';
status?: string;
//
};
}

View File

@@ -9,18 +9,15 @@ 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 { Customer } from '@/components/dashboard/customer/type.d';
import { Teacher } from '@/components/dashboard/teacher/type.d';
// import type { CrCategory } from '@/components/dashboard/cr/categories/type';
function getImageUrlFrRecord(record: Teacher): string {
// TODO: fix this
// `http://127.0.0.1:8090/api/files/${'record.collectionId'}/${'record.id'}/${'record.cat_image'}`;
return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.avatar}`;
function getImageUrlFrRecord(teacher: Teacher): string {
return `http://127.0.0.1:8090/api/files/${teacher.collectionId}/${teacher.id}/${teacher.avatar}`;
}
export default function SampleTitleCard({ lpModel }: { lpModel: Customer }): React.JSX.Element {
export default function SampleTitleCard({ teacherRecord }: { teacherRecord: Teacher }): React.JSX.Element {
const { t } = useTranslation();
return (
@@ -32,7 +29,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Customer }): Rea
>
<Avatar
variant="rounded"
src={getImageUrlFrRecord(lpModel)}
src={getImageUrlFrRecord(teacherRecord)}
sx={{ '--Avatar-size': '64px' }}
>
{t('empty')}
@@ -43,7 +40,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Customer }): Rea
spacing={2}
sx={{ alignItems: 'center', flexWrap: 'wrap' }}
>
<Typography variant="h4">{lpModel.email}</Typography>
<Typography variant="h4">{teacherRecord.name || teacherRecord.email}</Typography>
<Chip
icon={
<CheckCircleIcon
@@ -51,17 +48,11 @@ export default function SampleTitleCard({ lpModel }: { lpModel: Customer }): Rea
weight="fill"
/>
}
label={lpModel.quota}
label={teacherRecord.status}
size="small"
variant="outlined"
/>
</Stack>
<Typography
color="text.secondary"
variant="body1"
>
{lpModel.status}
</Typography>
</div>
</Stack>
<div>

View File

@@ -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/app/dashboard/teachers/view/[id]/TitleCard.tsx.draft` to handle `Teacher` record thanks, modify comments/variables/paths/functions name please
e.g. why `lessonCategories` still exist ?

View File

@@ -107,7 +107,7 @@ export default function Page(): React.JSX.Element {
spacing={3}
sx={{ alignItems: 'flex-start' }}
>
<TitleCard lpModel={showLessonCategory} />
<TitleCard teacherRecord={showLessonCategory} />
</Stack>
</Stack>
<Grid

View File

@@ -0,0 +1,143 @@
'use client';
import * as React from 'react';
import RouterLink from 'next/link';
import { useParams, useRouter } from 'next/navigation';
import SampleAddressCard from '@/app/dashboard/Sample/AddressCard';
import { SampleNotifications } from '@/app/dashboard/Sample/Notifications';
import SamplePaymentCard from '@/app/dashboard/Sample/PaymentCard';
import SampleSecurityCard from '@/app/dashboard/Sample/SecurityCard';
import Box from '@mui/material/Box';
import Link from '@mui/material/Link';
import Stack from '@mui/material/Stack';
import Grid from '@mui/material/Unstable_Grid2';
import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/ArrowLeft';
import type { RecordModel } from 'pocketbase';
import { useTranslation } from 'react-i18next';
import { config } from '@/config';
import { paths } from '@/paths';
import { logger } from '@/lib/default-logger';
import { pb } from '@/lib/pb';
import { toast } from '@/components/core/toaster';
import ErrorDisplay from '@/components/dashboard/error';
import { Notifications } from '@/components/dashboard/teacher/notifications';
import FormLoading from '@/components/loading';
import BasicDetailCard from './BasicDetailCard';
import TitleCard from './TitleCard';
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
import type { Teacher } from '@/components/dashboard/teacher/type.d';
import { COL_USER_METAS } from '@/constants';
export default function Page(): React.JSX.Element {
const { t } = useTranslation(['teachers']);
const router = useRouter();
//
const { id } = useParams<{ id: string }>();
//
const [showLoading, setShowLoading] = React.useState<boolean>(true);
const [showError, setShowError] = React.useState({ show: false, detail: '' });
//
const [teacherData, setTeacherData] = React.useState<Teacher>(defaultTeacher);
function handleEditClick(): void {
router.push(paths.dashboard.teachers.edit(teacherData.id));
}
React.useEffect(() => {
if (id) {
pb.collection(COL_USER_METAS)
.getOne(id)
.then((model: RecordModel) => {
setTeacherData({ ...defaultTeacher, ...model });
})
.catch((err) => {
logger.error(err);
toast(t('list.error'));
setShowError({ show: true, detail: JSON.stringify(err) });
})
.finally(() => {
setShowLoading(false);
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);
// return <>{JSON.stringify({ showError, showLessonCategory }, null, 2)}</>;
if (showLoading) return <FormLoading />;
if (showError.show)
return (
<ErrorDisplay
message={t('error.unable-to-process-request')}
code="500"
details={showError.detail}
/>
);
return (
<Box
sx={{
maxWidth: 'var(--Content-maxWidth)',
m: 'var(--Content-margin)',
p: 'var(--Content-padding)',
width: 'var(--Content-width)',
}}
>
<Stack spacing={4}>
<Stack spacing={3}>
<div>
<Link
color="text.primary"
component={RouterLink}
href={paths.dashboard.teachers.list}
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
variant="subtitle2"
>
<ArrowLeftIcon fontSize="var(--icon-fontSize-md)" />
{t('back-to-list')}
</Link>
</div>
<Stack
direction={{ xs: 'column', sm: 'row' }}
spacing={3}
sx={{ alignItems: 'flex-start' }}
>
<TitleCard lpModel={teacherData} />
</Stack>
</Stack>
<Grid
container
spacing={4}
>
<Grid
lg={4}
xs={12}
>
<Stack spacing={4}>
<BasicDetailCard
lpModel={teacherData}
handleEditClick={handleEditClick}
/>
<SampleSecurityCard />
</Stack>
</Grid>
<Grid
lg={8}
xs={12}
>
<Stack spacing={4}>
<SamplePaymentCard />
<SampleAddressCard />
<Notifications notifications={SampleNotifications} />
</Stack>
</Grid>
</Grid>
</Stack>
</Box>
);
}

View File

@@ -123,7 +123,7 @@ export const layoutConfig = {
},
{
key: 'teachers',
title: 'teachers',
title: 'teachers.nav-title',
icon: 'users',
items: [
{ key: 'teachers', title: 'List', href: paths.dashboard.teachers.list },
@@ -138,8 +138,8 @@ export const layoutConfig = {
icon: 'users',
items: [
{ key: 'students', title: 'List students', href: paths.dashboard.students.list },
{ key: 'students:create', title: 'Create student', href: paths.dashboard.students.create },
{ key: 'students:details', title: 'Student details', href: paths.dashboard.students.view('1') },
// { key: 'students:create', title: 'Create student', href: paths.dashboard.students.create },
// { key: 'students:details', title: 'Student details', href: paths.dashboard.students.view('1') },
],
},
// {

View File

@@ -0,0 +1 @@
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/student/confirm-delete-modal.tsx.draft` to handle `Student` record thanks, modify comments/variables/paths/functions name please

View File

@@ -83,12 +83,12 @@ export default function ConfirmDeleteModal({
</Avatar>
<Stack spacing={3}>
<Stack spacing={1}>
<Typography variant="h5">{t('Delete Lesson Type ?')}</Typography>
<Typography variant="h5">{t('Delete Student ?')}</Typography>
<Typography
color="text.secondary"
variant="body2"
>
{t('Are you sure you want to delete lesson type ?')}
{t('Are you sure you want to delete this student record?')}
</Typography>
</Stack>
<Stack

View File

@@ -4,7 +4,7 @@
//
import * as React from 'react';
import { useRouter } from 'next/navigation';
import { getAllCustomersCount } from '@/db/Customers/GetAllCount';
import { getAllStudentsCount } from '@/db/Students/GetAllCount';
import Button from '@mui/material/Button';
import Chip from '@mui/material/Chip';
@@ -22,18 +22,19 @@ import { FilterButton } from '@/components/core/filter-button';
import { Option } from '@/components/core/option';
import { useStudentsSelection } from './students-selection-context';
import GetBlockedCount from '@/db/Customers/GetBlockedCount';
import GetPendingCount from '@/db/Customers/GetPendingCount';
import GetActiveCount from '@/db/Customers/GetActiveCount';
import GetBlockedCount from '@/db/Students/GetBlockedCount';
import GetPendingCount from '@/db/Students/GetPendingCount';
import GetActiveCount from '@/db/Students/GetActiveCount';
import PhoneFilterPopover from './phone-filter-popover';
import EmailFilterPopover from './email-filter-popover';
import type { CustomersFiltersProps, Filters, SortDir } from './type.d';
import type { StudentFiltersProps, Filters, SortDir } from './type.d';
export function StudentsFilters({
filters = {},
sortDir = 'desc',
fullData,
}: CustomersFiltersProps): React.JSX.Element {
//
}: StudentFiltersProps): React.JSX.Element {
const { t } = useTranslation();
const { email, phone, status } = filters;
@@ -129,7 +130,7 @@ export function StudentsFilters({
React.useEffect(() => {
const fetchCount = async (): Promise<void> => {
try {
const tc = await getAllCustomersCount();
const tc = await getAllStudentsCount();
setTotalCount(tc);
const bc = await GetBlockedCount();

View File

@@ -25,12 +25,12 @@ export const StudentsSelectionContext = React.createContext<StudentsSelectionCon
interface StudentsSelectionProviderProps {
children: React.ReactNode;
customers: Student[];
students: Student[];
}
export function StudentsSelectionProvider({
children,
customers = [],
students: customers = [],
}: StudentsSelectionProviderProps): React.JSX.Element {
const customerIds = React.useMemo(() => customers.map((customer) => customer.id), [customers]);
const selection = useSelection(customerIds);

View File

@@ -39,7 +39,10 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Student
spacing={1}
sx={{ alignItems: 'center' }}
>
<Avatar src={row.avatar} />{' '}
<Avatar
src={`http://127.0.0.1:8090/api/files/${row.collectionId}/${row.id}/${row.avatar}`}
variant="rounded"
/>
<div>
<Link
color="inherit"
@@ -89,8 +92,6 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Student
{
formatter: (row): React.JSX.Element => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const mapping = {
active: {
label: 'Active',
@@ -172,7 +173,7 @@ export interface StudentsTableProps {
}
export function StudentsTable({ rows, reloadRows }: StudentsTableProps): React.JSX.Element {
const { t } = useTranslation(['customers']);
const { t } = useTranslation(['students']);
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useStudentsSelection();
const [idToDelete, setIdToDelete] = React.useState('');
@@ -213,7 +214,7 @@ export function StudentsTable({ rows, reloadRows }: StudentsTableProps): React.J
variant="body2"
>
{/* TODO: update this */}
{t('no-record-found')}
{t('no-student-found')}
</Typography>
</Box>
) : null}

View File

@@ -144,7 +144,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
//
color="secondary"
component={RouterLink}
href={paths.dashboard.teachers.details(row.id)}
href={paths.dashboard.teachers.view(row.id)}
>
<PencilSimpleIcon size={24} />
</LoadingButton>
@@ -167,13 +167,13 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<Teacher
];
}
export interface CustomersTableProps {
export interface TeachersTableProps {
rows: Teacher[];
reloadRows: () => void;
}
export function TeachersTable({ rows, reloadRows }: CustomersTableProps): React.JSX.Element {
const { t } = useTranslation(['customers']);
export function TeachersTable({ rows, reloadRows }: TeachersTableProps): React.JSX.Element {
const { t } = useTranslation(['teachers']);
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useTeachersSelection();
const [idToDelete, setIdToDelete] = React.useState('');

View File

@@ -1,6 +1,6 @@
import { pb } from '@/lib/pb';
import { COL_STUDENTS } from '@/constants';
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
export async function deleteStudent(id: string): Promise<boolean> {
return pb.collection(COL_STUDENTS).delete(id);
return pb.collection(COL_USER_METAS).delete(id);
}

View File

@@ -1,9 +1,9 @@
import { COL_STUDENTS } from '@/constants';
import { COL_STUDENTS, COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
export default async function GetActiveCount(): Promise<number> {
const { totalItems: count } = await pb.collection(COL_STUDENTS).getList(1, 1, {
filter: 'status = "active"',
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: 'status = "active" && role = "student"',
});
return count;
}

View File

@@ -1,7 +1,10 @@
import { pb } from '@/lib/pb';
import { COL_STUDENTS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
export async function getAllStudentsCount(): Promise<number> {
const result = await pb.collection(COL_STUDENTS).getList(1, 1);
const result = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: `role = "student"`,
//
});
return result.totalItems;
}

View File

@@ -1,9 +1,9 @@
import { COL_STUDENTS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
export default async function GetBlockedCount(): Promise<number> {
const { totalItems: count } = await pb.collection(COL_STUDENTS).getList(1, 1, {
filter: 'status = "blocked"',
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: 'status = "blocked" && role = "student"',
});
return count;
}

View File

@@ -1,9 +1,9 @@
import { COL_STUDENTS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
export default async function GetPendingCount(): Promise<number> {
const { totalItems: count } = await pb.collection(COL_STUDENTS).getList(1, 1, {
filter: 'status = "pending"',
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: 'status = "pending" && role = "student"',
});
return count;
}

View File

@@ -2,6 +2,9 @@ import { pb } from '@/lib/pb';
import { COL_USER_METAS } from '@/constants';
export async function getAllTeachersCount(): Promise<number> {
const result = await pb.collection(COL_USER_METAS).getList(1, 1, { filter: `role = "teacher"` });
const result = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: `role = "teacher"`,
//
});
return result.totalItems;
}

View File

@@ -1,8 +1,8 @@
import { COL_TEACHERS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
export default async function GetBlockedCount(): Promise<number> {
const { totalItems: count } = await pb.collection(COL_TEACHERS).getList(1, 1, {
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: 'status = "blocked"',
});
return count;

View File

@@ -1,9 +1,9 @@
import { COL_CUSTOMERS } from '@/constants';
import { COL_USER_METAS } from '@/constants';
import { pb } from '@/lib/pb';
export default async function GetPendingCount(): Promise<number> {
const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, {
filter: 'status = "pending"',
const { totalItems: count } = await pb.collection(COL_USER_METAS).getList(1, 1, {
filter: 'status = "pending" && role = "teacher"',
});
return count;
}

View File

@@ -140,6 +140,7 @@ export const paths = {
list: '/dashboard/teachers/list',
create: '/dashboard/teachers/create',
details: (id: string) => `/dashboard/teachers/view/${id}`,
view: (id: string) => `/dashboard/students/view/${id}`,
edit: (id: string) => `/dashboard/teachers/edit/${id}`,
mail: {
list: (id: string) => `/dashboard/teachers/mail/${id}/list`,