diff --git a/002_source/cms/_AI_WORKSPACE/components/001_INIT.md b/002_source/cms/_AI_WORKSPACE/components/001_INIT.md deleted file mode 100644 index 746bc4e..0000000 --- a/002_source/cms/_AI_WORKSPACE/components/001_INIT.md +++ /dev/null @@ -1,39 +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 - -software engineer will: - -- conclude and integrate the ideas from developer and QA engineer -- make decision to modify the code accordingly. - -no need to reply me what you are going on and your digest in this phase. -just reply me "OK" when done - -base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project` - -- `schema.dbml` - - - read `/001_documentation/Requirements/REQ0006/schema.dbml` - this is file in `dbml` format stating the main database structure - -- `schema.json` - - - read `/002_source/cms/src/db/schema.json` - this is the file of current pocketbase schema - -- read `/002_source/cms/src/constants.ts` - this is the content of `@/constants` - -- look into the md files in folder `/002_source/cms/_AI_WORKSPACE/001_guideline` - -- directory may contain `repomix-output.xml` file, that is a simple summary of all files inside the directory - -- read, remember and link up the ideas in file stated above, - i will tell them the task afterwards diff --git a/002_source/cms/_AI_WORKSPACE/components/002_PROMPT.md b/002_source/cms/_AI_WORKSPACE/components/002_PROMPT.md deleted file mode 100644 index 3d8a8f6..0000000 --- a/002_source/cms/_AI_WORKSPACE/components/002_PROMPT.md +++ /dev/null @@ -1,22 +0,0 @@ -Hi, i need your help. - -i am working on a nextjs react typescript project - -i've already copied the code(and it sub-directories) from -`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/components/dashboard/lp` (a.k.a. `lp`) -to -`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/components/dashboard/cr` (a.k.a. `cr`) - -i want you to: - -- understand the relations (e.g. `lp` -> `lp_categories`, `lp` -> `COL_QUIZ_LP_CATEGORIES`) -- review if any remaining `lp` or `mf` exist in `cr` directory and please help to do replace it to `cr`. (e.g. `COL_QUIZ_LP_CATEGORIES` -> `COL_QUIZ_CR_CATEGORIES` ) -- please create if you find any missing files/codes/constants - -thank you - ---- - -- compare the difference between `lp` and `mf`, -- remember the differences and -- draft the new type `cr` (e.g. modify the `import` locations, variables, functions, classes, constants name etc.) diff --git a/002_source/cms/_AI_WORKSPACE/components/DB_PROMPT.MD b/002_source/cms/_AI_WORKSPACE/components/DB_PROMPT.MD deleted file mode 100644 index ba93847..0000000 --- a/002_source/cms/_AI_WORKSPACE/components/DB_PROMPT.MD +++ /dev/null @@ -1,66 +0,0 @@ -The software engineer will provide solutions, -while QA engineer will feedback the opinion. - -this is now not in debug phase, -so, no need to reply me what they are going on or their insight throught the prompt. -just reply me "OK" when done - ---- - -clone `GetVisibleCount.tsx` and `GetHiddenCount.tsx` from `LessonTypes` to `LessonCategories` and update it - -please draft `GetHiddenCount.tsx` for COL_LESSON_TYPES and `status = hidden` - -well done !, please proceed to another request - -working directory: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db` - -according information from `schema.json`, get the collection of `Students` - -pleaes clone the `tsx` files from `LessonTypes` and `LessonCategories` to `Students` and update the content - -when you draft coding, review file and append with `.tsx.draft` - ---- - -- this is part of react typescript project, with pocketbase -- `schema.dbml`, describe the collections(tables) -- folder `LessonCategories`, the correct references -- folder `LessonTypes`, the correct references -- you can find the `schema.dbml` and schema information from `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006` -- do not read root directory, assume it is a fresh copy of nextjs project is ok - -## instruction - -- break the questions into smaller parts -- review file append with `.draft`, see if the content aligned with the correct references -- read and understand `dbml` file -- lookup the every folder - -## tasks - -Thanks - ---- - ---- - -please revise - -please revise -`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/types/LpCategory.tsx` `interface LpCategory` - -to the collection `QuizLPCategories` align the dbml file in the previous prompt - -please modify `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/components/dashboard/lp_categories/_constants.tsx` - -to follow the type definition in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/types/LpCategory.tsx`, the constant `defaultLpCategory` - ---- - -the constants file (`@/constants`) was `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/constants.ts` - -please help to fix the `tsx` files in folder `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/QuizMFCategories`, -the `COL` constants is wrongly used, it should refer to `COL_QUIZ_MF_CATEGORIES`. thanks - -please update the `COL_XXXX` TO COL_MF_CATEGORIES diff --git a/002_source/cms/_AI_WORKSPACE/db/001_INIT.md b/002_source/cms/_AI_WORKSPACE/db/001_INIT.md index 7b9d15c..d794e3d 100644 --- a/002_source/cms/_AI_WORKSPACE/db/001_INIT.md +++ b/002_source/cms/_AI_WORKSPACE/db/001_INIT.md @@ -2,19 +2,24 @@ ## getting started -Imagine there is a +Imagine there is a: -1. software developer and a -2. QA engineer +1. developer (provide the modification) +2. QA engineer (provide the feedback, and testing) +3. software engineer +4. technical writer -to solve the problems together +they will: -They will: +- conclude and integrate the ideas from developer and QA engineer +- make decision to modify the code accordingly. -no need to reply me what you are going on and your digest in this phase. -just reply me "OK" when done +## project background and initial setup -base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project` +- No need to reply me what you are going on and your digest in this phase. + Just reply me "OK" when done + +- base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project` - `schema.dbml` @@ -33,5 +38,7 @@ base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/letterso - directory may contain `repomix-output.xml` file, that is a simple summary of all files inside the directory -- read, remember and link up the ideas in file stated above, +- 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 diff --git a/002_source/cms/_AI_WORKSPACE/db/002_PROMPT_questions.md b/002_source/cms/_AI_WORKSPACE/db/002_PROMPT_questions.md index 9cf28f6..0bb7a43 100644 --- a/002_source/cms/_AI_WORKSPACE/db/002_PROMPT_questions.md +++ b/002_source/cms/_AI_WORKSPACE/db/002_PROMPT_questions.md @@ -10,7 +10,7 @@ i want you to: - understand the relations (e.g. `lp` -> `lp_Questions`, `lp` -> `COL_QUIZ_LP_QUESTIONS`) - review if any remaining `lp` or `mf` exist in `cr` directory and please help to do replace it to `cr`. (e.g. `COL_QUIZ_LP_QUESTIONS` -> `COL_QUIZ_CR_Questions` ) - please create if you find any missing files/codes/constants -- using template, create the similar code for `cr` named `QuizCRQuestions` +- using template, create the similar code for `customer` named `Customers` thank you diff --git a/002_source/cms/_AI_WORKSPACE/db/003_update_dbml_from_schema.md b/002_source/cms/_AI_WORKSPACE/db/003_update_dbml_from_schema.md new file mode 100644 index 0000000..40b1daf --- /dev/null +++ b/002_source/cms/_AI_WORKSPACE/db/003_update_dbml_from_schema.md @@ -0,0 +1,20 @@ +Hi, i need your help. + +## task + +i am working on a dbml file +i got a schema.json from exported from pocketbase +and i want to update it to my current dbml file (for documentation) + +## 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. + +## information + +json file: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/schema.json` +dbml file: `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.dbml` + +thanks diff --git a/002_source/cms/_AI_WORKSPACE/db/004_clone_db_driver.md b/002_source/cms/_AI_WORKSPACE/db/004_clone_db_driver.md new file mode 100644 index 0000000..fba94ae --- /dev/null +++ b/002_source/cms/_AI_WORKSPACE/db/004_clone_db_driver.md @@ -0,0 +1,10 @@ +--- +tags: db, driver +--- + +# clone db driver + +please understand the tsx files in folder +`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Teachers` + +change all occurrence of `customer` to `teacher` thanks. diff --git a/002_source/cms/_AI_WORKSPACE/db/009_draft_db_drivers.md b/002_source/cms/_AI_WORKSPACE/db/009_draft_db_drivers.md new file mode 100644 index 0000000..df19de6 --- /dev/null +++ b/002_source/cms/_AI_WORKSPACE/db/009_draft_db_drivers.md @@ -0,0 +1,18 @@ +# task + +update `dbml` from `schema.json` + +## things to note + +1. please skip `presentable` properties from `schema.json` + +## steps + +1. read file `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/schema.json`. this is the export from `pocketbase`. +1. read file `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.dbml`. this is file written in dbml format. +1. currently the collection in `schama.json` is mapped to table in `schema.dbml` +1. compare the `schema.json` and `schema.dbml`, remember the differences +1. you may found some comment already exist in `schema.dbml`, please keep them +1. while keeping `schema.json` content unchanged. write file to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/001_documentation/Requirements/REQ0006/schema.dbml` content based on `schema.json`. + +thanks. diff --git a/002_source/cms/_AI_WORKSPACE/db/010_extend_function_by_clone_and_updating_exist_code.md.md b/002_source/cms/_AI_WORKSPACE/db/010_extend_function_by_clone_and_updating_exist_code.md.md new file mode 100644 index 0000000..6a3a3ef --- /dev/null +++ b/002_source/cms/_AI_WORKSPACE/db/010_extend_function_by_clone_and_updating_exist_code.md.md @@ -0,0 +1,10 @@ +# task + +extend function by clone and updating exist code + +## steps + +please read file +`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/QuizListenings/GetAllCount.tsx` + +duplicate it to cover `GetActiveCount`, `GetPendingCount` and `GetBlockedCount`. create them in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers` directory thanks. diff --git a/002_source/cms/_AI_WORKSPACE/db/Code_XE50rE8nMK.mp4 b/002_source/cms/_AI_WORKSPACE/db/Code_XE50rE8nMK.mp4 new file mode 100644 index 0000000..10e2f17 Binary files /dev/null and b/002_source/cms/_AI_WORKSPACE/db/Code_XE50rE8nMK.mp4 differ diff --git a/002_source/cms/_AI_WORKSPACE/pages/DB_PROMPT.MD b/002_source/cms/_AI_WORKSPACE/db/DB_AI_GUIDELINE.MD similarity index 69% rename from 002_source/cms/_AI_WORKSPACE/pages/DB_PROMPT.MD rename to 002_source/cms/_AI_WORKSPACE/db/DB_AI_GUIDELINE.MD index ba93847..b2a12a6 100644 --- a/002_source/cms/_AI_WORKSPACE/pages/DB_PROMPT.MD +++ b/002_source/cms/_AI_WORKSPACE/db/DB_AI_GUIDELINE.MD @@ -1,3 +1,32 @@ +# AI GUIDELINE + +## getting started + +Imagine there is a software developer and a QA engineer to solve the problems together + +They will: + +no need to reply me what you are going on and your digest in this phase. +just reply me "OK" when done + +base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project` + +- read `/001_documentation/Requirements/REQ0006/schema.dbml` +this is file in dbml syntax state the main database + +- read `/002_source/cms/src/db/schema.json` +this is the file of live pocketbase schema output + +- read `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/constants.ts` +this is the content of `@/constants` + +- look into the md files in folder `/002_source/cms/_AI_GUIDELINE` + +- read, remember and link up the ideas in file stated above, +i will tell them the task afterwards + +--- + The software engineer will provide solutions, while QA engineer will feedback the opinion. @@ -41,8 +70,19 @@ when you draft coding, review file and append with `.tsx.draft` Thanks + + --- + +please take a look in `schema.dbml` and `schema.json`, +associate the collection from json file to the table in dbml file + +please modify the `schema.dbml` to align with `schema.json` + +to the collection `QuizLPCategories` align the dbml file in the previous prompt + + --- please revise @@ -52,6 +92,7 @@ please revise to the collection `QuizLPCategories` align the dbml file in the previous prompt + please modify `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/components/dashboard/lp_categories/_constants.tsx` to follow the type definition in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/types/LpCategory.tsx`, the constant `defaultLpCategory` @@ -63,4 +104,5 @@ the constants file (`@/constants`) was `/home/logic/_wsl_workspace/001_github_ws please help to fix the `tsx` files in folder `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/QuizMFCategories`, the `COL` constants is wrongly used, it should refer to `COL_QUIZ_MF_CATEGORIES`. thanks + please update the `COL_XXXX` TO COL_MF_CATEGORIES diff --git a/002_source/cms/_AI_WORKSPACE/pages/001_INIT.md b/002_source/cms/_AI_WORKSPACE/pages/001_INIT.md deleted file mode 100644 index 7b9d15c..0000000 --- a/002_source/cms/_AI_WORKSPACE/pages/001_INIT.md +++ /dev/null @@ -1,37 +0,0 @@ -# AI GUIDELINE - -## getting started - -Imagine there is a - -1. software developer and a -2. QA engineer - -to solve the problems together - -They will: - -no need to reply me what you are going on and your digest in this phase. -just reply me "OK" when done - -base_dir=`/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project` - -- `schema.dbml` - - - read `/001_documentation/Requirements/REQ0006/schema.dbml` - this is file in `dbml` format stating the main database structure - -- `schema.json` - - - read `/002_source/cms/src/db/schema.json` - this is the file of current pocketbase schema - -- read `/002_source/cms/src/constants.ts` - this is the content of `@/constants` - -- look into the md files in folder `/002_source/cms/_AI_WORKSPACE/001_guideline` - -- directory may contain `repomix-output.xml` file, that is a simple summary of all files inside the directory - -- read, remember and link up the ideas in file stated above, - i will tell them the task afterwards diff --git a/002_source/cms/_AI_WORKSPACE/pages/002_PROMPT.md b/002_source/cms/_AI_WORKSPACE/pages/002_PROMPT.md deleted file mode 100644 index 706bb64..0000000 --- a/002_source/cms/_AI_WORKSPACE/pages/002_PROMPT.md +++ /dev/null @@ -1,25 +0,0 @@ -Hi, i need your help. - -i am working on a nextjs react typescript project - -i've already copied the code(and it sub-directories) from `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/lp` (a.k.a. `lp`) to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/cr` (a.k.a. `cr`) - -i want you to: - -- list files from directory - - - `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/lp` - - `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/app/dashboard/cr` - -- understand the relations (e.g. `lp` -> `lp_categories`, `lp` -> `COL_QUIZ_LP_CATEGORIES`) -- review if any remaining `lp` or `mf` exist in `cr` directory and please help to do replace it to `cr`. (e.g. `COL_QUIZ_LP_CATEGORIES` -> `COL_QUIZ_CR_CATEGORIES` ) -- please create if you find any missing files/codes/constants - -thank you - ---- - -- I proofed the code is working already, what you need to do is refactoring of the `variables`, `functions`, `classes`, `constants` (`lp` -> `cr`) -- compare the difference between `lp` and `mf`, -- remember the differences and -- draft the new type `cr` (e.g. modify the `import` locations, variables, functions, classes, constants name etc.) diff --git a/002_source/cms/src/app/dashboard/teachers/SampleCustomers.tsx b/002_source/cms/src/app/dashboard/teachers/SampleTeachers.tsx similarity index 99% rename from 002_source/cms/src/app/dashboard/teachers/SampleCustomers.tsx rename to 002_source/cms/src/app/dashboard/teachers/SampleTeachers.tsx index b991279..ba471dc 100644 --- a/002_source/cms/src/app/dashboard/teachers/SampleCustomers.tsx +++ b/002_source/cms/src/app/dashboard/teachers/SampleTeachers.tsx @@ -3,7 +3,7 @@ import type { Customer } from '@/components/dashboard/customer/type.d'; import { dayjs } from '@/lib/dayjs'; -export const SampleCustomers = [ +export const SampleTeachers = [ { id: 'USR-005', name: 'Fran Perez', diff --git a/002_source/cms/src/app/dashboard/teachers/[customerId]/page.tsx b/002_source/cms/src/app/dashboard/teachers/[customerId]/page.tsx index 6196a4a..eb77f8f 100644 --- a/002_source/cms/src/app/dashboard/teachers/[customerId]/page.tsx +++ b/002_source/cms/src/app/dashboard/teachers/[customerId]/page.tsx @@ -24,13 +24,13 @@ import { toast } from '@/components/core/toaster'; import ErrorDisplay from '@/components/dashboard/error'; -import { Notifications } from '@/components/dashboard/customer/notifications'; +import { Notifications } from '@/components/dashboard/teacher/notifications'; import FormLoading from '@/components/loading'; import BasicDetailCard from './BasicDetailCard'; import TitleCard from './TitleCard'; -import { defaultCustomer } from '@/components/dashboard/customer/_constants'; -import type { Customer } from '@/components/dashboard/customer/type.d'; -import { COL_CUSTOMERS } from '@/constants'; +import { defaultTeacher } from '@/components/dashboard/teacher/_constants'; +import type { Teacher } from '@/components/dashboard/teacher/type.d'; +import { COL_TEACHERS } from '@/constants'; export default function Page(): React.JSX.Element { const { t } = useTranslation(); @@ -41,18 +41,18 @@ export default function Page(): React.JSX.Element { const [showLoading, setShowLoading] = React.useState(true); const [showError, setShowError] = React.useState({ show: false, detail: '' }); // - const [showLessonCategory, setShowLessonCategory] = React.useState(defaultCustomer); + const [showLessonCategory, setShowLessonCategory] = React.useState(defaultTeacher); function handleEditClick(): void { - router.push(paths.dashboard.customers.edit(showLessonCategory.id)); + router.push(paths.dashboard.teachers.edit(showLessonCategory.id)); } React.useEffect(() => { if (customerId) { - pb.collection(COL_CUSTOMERS) + pb.collection(COL_TEACHERS) .getOne(customerId) .then((model: RecordModel) => { - setShowLessonCategory({ ...defaultCustomer, ...model }); + setShowLessonCategory({ ...defaultTeacher, ...model }); }) .catch((err) => { logger.error(err); @@ -93,12 +93,12 @@ export default function Page(): React.JSX.Element { - Customers + Teachers - Customers + Teachers
- Create customer + Create teacher
- + ); diff --git a/002_source/cms/src/app/dashboard/teachers/edit/[customerId]/page.tsx b/002_source/cms/src/app/dashboard/teachers/edit/[customerId]/page.tsx index e4e23bc..07ff3c1 100644 --- a/002_source/cms/src/app/dashboard/teachers/edit/[customerId]/page.tsx +++ b/002_source/cms/src/app/dashboard/teachers/edit/[customerId]/page.tsx @@ -11,7 +11,7 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { CrCategoryEditForm } from '@/components/dashboard/cr/categories/cr-category-edit-form'; -import { CustomerEditForm } from '@/components/dashboard/customer/customer-edit-form'; +import { TeacherEditForm } from '@/components/dashboard/teacher/teacher-edit-form'; export default function Page(): React.JSX.Element { const { t } = useTranslation(['lp_categories']); @@ -47,7 +47,7 @@ export default function Page(): React.JSX.Element { {t('edit.title')} - + ); diff --git a/002_source/cms/src/app/dashboard/teachers/page.tsx b/002_source/cms/src/app/dashboard/teachers/page.tsx index 4137d42..bc86dd1 100644 --- a/002_source/cms/src/app/dashboard/teachers/page.tsx +++ b/002_source/cms/src/app/dashboard/teachers/page.tsx @@ -1,13 +1,13 @@ -// src/app/dashboard/customers/page.tsx +// src/app/dashboard/teachers/page.tsx 'use client'; // RULES: -// contains list page for customers (Customers) +// contains list page for teachers (Teachers) // contain definition to collection only // import * as React from 'react'; import { useRouter } from 'next/navigation'; -import { COL_CUSTOMERS } from '@/constants'; +import { COL_TEACHERS } from '@/constants'; import { LoadingButton } from '@mui/lab'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; @@ -19,13 +19,13 @@ import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus'; import type { ListResult, RecordModel } from 'pocketbase'; import { config } from '@/config'; -import { CustomersFilters } from '@/components/dashboard/customer/customers-filters'; -// import type { Filters } from '@/components/dashboard/customer/customers-filters'; -import { CustomersPagination } from '@/components/dashboard/customer/customers-pagination'; -import { CustomersSelectionProvider } from '@/components/dashboard/customer/customers-selection-context'; -import { CustomersTable } from '@/components/dashboard/customer/customers-table'; -import type { Customer, Filters } from '@/components/dashboard/customer/type.d'; -import { SampleCustomers } from './SampleCustomers'; +import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters'; +// import type { Filters } from '@/components/dashboard/teacher/customers-filters'; +import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination'; +import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context'; +import { TeachersTable } from '@/components/dashboard/teacher/teachers-table'; +import type { Teacher, Filters } from '@/components/dashboard/teacher/type.d'; +import { SampleTeachers } from './SampleTeachers'; import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; @@ -34,16 +34,16 @@ import { logger } from '@/lib/default-logger'; import { pb } from '@/lib/pb'; import { toast } from '@/components/core/toaster'; import ErrorDisplay from '@/components/dashboard/error'; -import { defaultCustomer } from '@/components/dashboard/customer/_constants'; +import { defaultTeacher } from '@/components/dashboard/teacher/_constants'; import FormLoading from '@/components/loading'; export default function Page({ searchParams }: PageProps): React.JSX.Element { - const { t } = useTranslation(['customers']); + const { t } = useTranslation(['teachers']); const router = useRouter(); const { email, phone, sortDir, status } = searchParams; - const [lessonCategoriesData, setLessonCategoriesData] = React.useState([]); + const [lessonCategoriesData, setLessonCategoriesData] = React.useState([]); // const [isLoadingAddPage, setIsLoadingAddPage] = React.useState(false); @@ -52,26 +52,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { // const [rowsPerPage, setRowsPerPage] = React.useState(5); // - const [f, setF] = React.useState([]); + const [f, setF] = React.useState([]); const [currentPage, setCurrentPage] = React.useState(0); // const [recordCount, setRecordCount] = React.useState(0); const [listOption, setListOption] = React.useState({}); const [listSort, setListSort] = React.useState({}); - // - // const sortedCustomers = applySort(SampleCustomers, sortDir); - // const filteredCustomers = applyFilters(sortedCustomers, { email, phone, status }); - // const reloadRows = async (): Promise => { try { const models: ListResult = await pb - .collection(COL_CUSTOMERS) + .collection(COL_TEACHERS) .getList(currentPage + 1, rowsPerPage, listOption); const { items, totalItems } = models; - const tempLessonTypes: Customer[] = items.map((lt) => { - return { ...defaultCustomer, ...lt }; + const tempLessonTypes: Teacher[] = items.map((lt) => { + return { ...defaultTeacher, ...lt }; }); setLessonCategoriesData(tempLessonTypes); @@ -174,7 +170,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { loading={isLoadingAddPage} onClick={(): void => { setIsLoadingAddPage(true); - router.push(paths.dashboard.customers.create); + router.push(paths.dashboard.teachers.create); }} startIcon={} variant="contained" @@ -183,22 +179,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { - + - - - - +
{JSON.stringify(f, null, 2)}
@@ -217,7 +213,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { // Sorting and filtering has to be done on the server. -function applySort(row: Customer[], sortDir: 'asc' | 'desc' | undefined): Customer[] { +function applySort(row: Teacher[], sortDir: 'asc' | 'desc' | undefined): Teacher[] { return row.sort((a, b) => { if (sortDir === 'asc') { return a.createdAt.getTime() - b.createdAt.getTime(); @@ -227,7 +223,7 @@ function applySort(row: Customer[], sortDir: 'asc' | 'desc' | undefined): Custom }); } -function applyFilters(row: Customer[], { email, phone, status }: Filters): Customer[] { +function applyFilters(row: Teacher[], { email, phone, status }: Filters): Teacher[] { return row.filter((item) => { if (email) { if (!item.email?.toLowerCase().includes(email.toLowerCase())) { diff --git a/002_source/cms/src/components/dashboard/teacher/_constants.ts b/002_source/cms/src/components/dashboard/teacher/_constants.ts index 503e5e3..0aa0baf 100644 --- a/002_source/cms/src/components/dashboard/teacher/_constants.ts +++ b/002_source/cms/src/components/dashboard/teacher/_constants.ts @@ -3,9 +3,9 @@ // empty valur for customer import { dayjs } from '@/lib/dayjs'; -import type { Customer } from './type.d'; +import type { Teacher } from './type.d'; -export const defaultCustomer: Customer = { +export const defaultTeacher: Teacher = { id: '', name: '', avatar: undefined, @@ -16,6 +16,6 @@ export const defaultCustomer: Customer = { createdAt: dayjs().toDate(), }; -export const emptyLpCategory: Customer = { - ...defaultCustomer, +export const emptyLpCategory: Teacher = { + ...defaultTeacher, }; diff --git a/002_source/cms/src/components/dashboard/teacher/confirm-delete-modal.tsx b/002_source/cms/src/components/dashboard/teacher/confirm-delete-modal.tsx index ba9aad5..d6ca213 100644 --- a/002_source/cms/src/components/dashboard/teacher/confirm-delete-modal.tsx +++ b/002_source/cms/src/components/dashboard/teacher/confirm-delete-modal.tsx @@ -16,7 +16,7 @@ import { useTranslation } from 'react-i18next'; import { logger } from '@/lib/default-logger'; import { toast } from '@/components/core/toaster'; -import { deleteCustomer } from '@/db/Customers/Delete'; +import { deleteTeacher } from '@/db/Teachers/Delete'; export default function ConfirmDeleteModal({ open, @@ -49,7 +49,7 @@ export default function ConfirmDeleteModal({ setIsDeleteing(true); // RULES: delete - deleteCustomer(idToDelete) + deleteTeacher(idToDelete) .then(() => { reloadRows(); handleClose(); diff --git a/002_source/cms/src/components/dashboard/teacher/customer-create-form.tsx b/002_source/cms/src/components/dashboard/teacher/teacher-create-form.tsx similarity index 98% rename from 002_source/cms/src/components/dashboard/teacher/customer-create-form.tsx rename to 002_source/cms/src/components/dashboard/teacher/teacher-create-form.tsx index 046f16e..c8b4242 100644 --- a/002_source/cms/src/components/dashboard/teacher/customer-create-form.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teacher-create-form.tsx @@ -29,7 +29,7 @@ import { paths } from '@/paths'; import { logger } from '@/lib/default-logger'; import { Option } from '@/components/core/option'; import { toast } from '@/components/core/toaster'; -import { createCustomer } from '@/db/Customers/Create'; +import { createTeacher } from '@/db/Teachers/Create'; import isDevelopment from '@/lib/check-is-development'; function fileToBase64(file: Blob): Promise { @@ -87,7 +87,7 @@ const defaultValues = { currency: 'USD', } satisfies Values; -export function CustomerCreateForm(): React.JSX.Element { +export function TeacherCreateForm(): React.JSX.Element { const router = useRouter(); const { @@ -102,9 +102,9 @@ export function CustomerCreateForm(): React.JSX.Element { async (values: Values): Promise => { try { // Use standard create method from db/Customers/Create - const record = await createCustomer(values); + const record = await createTeacher(values); toast.success('Customer created'); - router.push(paths.dashboard.customers.details(record.id)); + router.push(paths.dashboard.teachers.details(record.id)); } catch (err) { logger.error(err); toast.error('Failed to create customer'); @@ -509,7 +509,7 @@ export function CustomerCreateForm(): React.JSX.Element { @@ -517,7 +517,7 @@ export function CustomerCreateForm(): React.JSX.Element { type="submit" variant="contained" > - Create customer + Create teacher diff --git a/002_source/cms/src/components/dashboard/teacher/customer-edit-form.tsx b/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx similarity index 98% rename from 002_source/cms/src/components/dashboard/teacher/customer-edit-form.tsx rename to 002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx index 8e9d211..43a174b 100644 --- a/002_source/cms/src/components/dashboard/teacher/customer-edit-form.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import RouterLink from 'next/link'; import { useParams, useRouter } from 'next/navigation'; // -import { COL_CUSTOMERS } from '@/constants'; +import { COL_TEACHERS } from '@/constants'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoadingButton } from '@mui/lab'; // @@ -85,7 +85,7 @@ const defaultValues = { avatar: '', } satisfies Values; -export function CustomerEditForm(): React.JSX.Element { +export function TeacherEditForm(): React.JSX.Element { const router = useRouter(); const { t } = useTranslation(['lp_categories']); @@ -123,9 +123,9 @@ export function CustomerEditForm(): React.JSX.Element { }; try { - await pb.collection(COL_CUSTOMERS).update(customerId, updateData); + await pb.collection(COL_TEACHERS).update(customerId, updateData); toast.success('Customer updated successfully'); - router.push(paths.dashboard.customers.list); + router.push(paths.dashboard.teachers.list); } catch (error) { logger.error(error); toast.error('Failed to update customer'); @@ -162,7 +162,7 @@ export function CustomerEditForm(): React.JSX.Element { setShowLoading(true); try { - const result = await pb.collection(COL_CUSTOMERS).getOne(id); + const result = await pb.collection(COL_TEACHERS).getOne(id); reset({ ...defaultValues, ...result }); console.log({ result }); @@ -581,7 +581,7 @@ export function CustomerEditForm(): React.JSX.Element { diff --git a/002_source/cms/src/components/dashboard/teacher/customers-filters.tsx b/002_source/cms/src/components/dashboard/teacher/teachers-filters.tsx similarity index 96% rename from 002_source/cms/src/components/dashboard/teacher/customers-filters.tsx rename to 002_source/cms/src/components/dashboard/teacher/teachers-filters.tsx index 56a7e4f..03c87dd 100644 --- a/002_source/cms/src/components/dashboard/teacher/customers-filters.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teachers-filters.tsx @@ -21,7 +21,7 @@ import { paths } from '@/paths'; import { FilterButton } from '@/components/core/filter-button'; import { Option } from '@/components/core/option'; -import { useCustomersSelection } from './customers-selection-context'; +import { useTeachersSelection } from './teachers-selection-context'; import GetBlockedCount from '@/db/Customers/GetBlockedCount'; import GetPendingCount from '@/db/Customers/GetPendingCount'; import GetActiveCount from '@/db/Customers/GetActiveCount'; @@ -29,7 +29,7 @@ import PhoneFilterPopover from './phone-filter-popover'; import EmailFilterPopover from './email-filter-popover'; import type { CustomersFiltersProps, Filters, SortDir } from './type.d'; -export function CustomersFilters({ +export function TeachersFilters({ filters = {}, sortDir = 'desc', fullData, @@ -45,7 +45,7 @@ export function CustomersFilters({ const router = useRouter(); - const selection = useCustomersSelection(); + const selection = useTeachersSelection(); // function getVisible(): number { // return fullData.reduce((count, item: CrQuestion) => { @@ -87,7 +87,7 @@ export function CustomersFilters({ searchParams.set('phone', newFilters.phone); } - router.push(`${paths.dashboard.customers.list}?${searchParams.toString()}`); + router.push(`${paths.dashboard.teachers.list}?${searchParams.toString()}`); }, [router] ); diff --git a/002_source/cms/src/components/dashboard/teacher/customers-pagination.tsx b/002_source/cms/src/components/dashboard/teacher/teachers-pagination.tsx similarity index 96% rename from 002_source/cms/src/components/dashboard/teacher/customers-pagination.tsx rename to 002_source/cms/src/components/dashboard/teacher/teachers-pagination.tsx index a7a89b6..5aea10d 100644 --- a/002_source/cms/src/components/dashboard/teacher/customers-pagination.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teachers-pagination.tsx @@ -16,7 +16,7 @@ interface CustomersPaginationProps { rowsPerPage: number; } -export function CustomersPagination({ +export function TeachersPagination({ count, page, // diff --git a/002_source/cms/src/components/dashboard/teacher/customers-selection-context.tsx b/002_source/cms/src/components/dashboard/teacher/teachers-selection-context.tsx similarity index 74% rename from 002_source/cms/src/components/dashboard/teacher/customers-selection-context.tsx rename to 002_source/cms/src/components/dashboard/teacher/teachers-selection-context.tsx index 72cd8ba..1e92ad2 100644 --- a/002_source/cms/src/components/dashboard/teacher/customers-selection-context.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teachers-selection-context.tsx @@ -5,7 +5,7 @@ import * as React from 'react'; import { useSelection } from '@/hooks/use-selection'; import type { Selection } from '@/hooks/use-selection'; -import type { Customer } from './type.d'; +import type { Teacher } from './type.d'; function noop(): void { return undefined; @@ -25,19 +25,19 @@ export const CustomersSelectionContext = React.createContext customers.map((customer) => customer.id), [customers]); + const customerIds = React.useMemo(() => teachers.map((customer) => customer.id), [teachers]); const selection = useSelection(customerIds); return {children}; } -export function useCustomersSelection(): CustomersSelectionContextValue { +export function useTeachersSelection(): CustomersSelectionContextValue { return React.useContext(CustomersSelectionContext); } diff --git a/002_source/cms/src/components/dashboard/teacher/customers-table.tsx b/002_source/cms/src/components/dashboard/teacher/teachers-table.tsx similarity index 91% rename from 002_source/cms/src/components/dashboard/teacher/customers-table.tsx rename to 002_source/cms/src/components/dashboard/teacher/teachers-table.tsx index f064433..397d249 100644 --- a/002_source/cms/src/components/dashboard/teacher/customers-table.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teachers-table.tsx @@ -27,10 +27,10 @@ import { DataTable } from '@/components/core/data-table'; import type { ColumnDef } from '@/components/core/data-table'; import ConfirmDeleteModal from './confirm-delete-modal'; -import { useCustomersSelection } from './customers-selection-context'; -import type { Customer } from './type.d'; +import { useTeachersSelection } from './teachers-selection-context'; +import type { Teacher } from './type.d'; -function columns(handleDeleteClick: (testId: string) => void): ColumnDef[] { +function columns(handleDeleteClick: (testId: string) => void): ColumnDef[] { return [ { formatter: (row): React.JSX.Element => ( @@ -44,7 +44,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef @@ -89,8 +89,6 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef { - // eslint-disable-next-line react-hooks/rules-of-hooks - const mapping = { active: { label: 'Active', @@ -143,7 +141,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef @@ -167,13 +165,13 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef void; } -export function CustomersTable({ rows, reloadRows }: CustomersTableProps): React.JSX.Element { +export function TeachersTable({ rows, reloadRows }: CustomersTableProps): React.JSX.Element { const { t } = useTranslation(['customers']); - const { deselectAll, deselectOne, selectAll, selectOne, selected } = useCustomersSelection(); + const { deselectAll, deselectOne, selectAll, selectOne, selected } = useTeachersSelection(); const [idToDelete, setIdToDelete] = React.useState(''); const [open, setOpen] = React.useState(false); @@ -191,7 +189,7 @@ export function CustomersTable({ rows, reloadRows }: CustomersTableProps): React reloadRows={reloadRows} setOpen={setOpen} /> - + columns={columns(handleDeleteClick)} onDeselectAll={deselectAll} onDeselectOne={(_, row) => { @@ -213,7 +211,7 @@ export function CustomersTable({ rows, reloadRows }: CustomersTableProps): React variant="body2" > {/* TODO: update this */} - {t('no-record-found')} + {t('no-teachers-found')}
) : null} diff --git a/002_source/cms/src/components/dashboard/teacher/type.d.tsx b/002_source/cms/src/components/dashboard/teacher/type.d.tsx index a9c7cde..3b84aab 100644 --- a/002_source/cms/src/components/dashboard/teacher/type.d.tsx +++ b/002_source/cms/src/components/dashboard/teacher/type.d.tsx @@ -2,7 +2,7 @@ export type SortDir = 'asc' | 'desc'; -export interface Customer { +export interface Teacher { id: string; name: string; avatar?: string; @@ -60,7 +60,7 @@ export interface EditFormProps { export interface CustomersFiltersProps { filters?: Filters; sortDir?: SortDir; - fullData: Customer[]; + fullData: Teacher[]; } export interface Filters { email?: string; diff --git a/002_source/cms/src/db/Teachers/Create.tsx b/002_source/cms/src/db/Teachers/Create.tsx new file mode 100644 index 0000000..836aac6 --- /dev/null +++ b/002_source/cms/src/db/Teachers/Create.tsx @@ -0,0 +1,11 @@ +// api method for crate teacher record +// RULES: +// TBA +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; +import type { CreateFormProps } from '@/components/dashboard/teacher/type.d'; +import type { RecordModel } from 'pocketbase'; + +export async function createTeacher(data: CreateFormProps): Promise { + return pb.collection(COL_TEACHERS).create(data); +} diff --git a/002_source/cms/src/db/Teachers/Delete.tsx b/002_source/cms/src/db/Teachers/Delete.tsx new file mode 100644 index 0000000..b08db9e --- /dev/null +++ b/002_source/cms/src/db/Teachers/Delete.tsx @@ -0,0 +1,6 @@ +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; + +export async function deleteTeacher(id: string): Promise { + return pb.collection(COL_TEACHERS).delete(id); +} diff --git a/002_source/cms/src/db/Teachers/GetActiveCount.tsx b/002_source/cms/src/db/Teachers/GetActiveCount.tsx new file mode 100644 index 0000000..cf92c27 --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetActiveCount.tsx @@ -0,0 +1,9 @@ +import { COL_TEACHERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetActiveCount(): Promise { + const { totalItems: count } = await pb.collection(COL_TEACHERS).getList(1, 1, { + filter: 'status = "active"', + }); + return count; +} diff --git a/002_source/cms/src/db/Teachers/GetAll.tsx b/002_source/cms/src/db/Teachers/GetAll.tsx new file mode 100644 index 0000000..323a5c0 --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetAll.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; +import { RecordModel } from 'pocketbase'; + +export async function getAllTeachers(options = {}): Promise { + return pb.collection(COL_TEACHERS).getFullList(options); +} diff --git a/002_source/cms/src/db/Teachers/GetAllCount.tsx b/002_source/cms/src/db/Teachers/GetAllCount.tsx new file mode 100644 index 0000000..d2e86b4 --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetAllCount.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; + +export async function getAllTeachersCount(): Promise { + const result = await pb.collection(COL_TEACHERS).getList(1, 1); + return result.totalItems; +} diff --git a/002_source/cms/src/db/Teachers/GetBlockedCount.tsx b/002_source/cms/src/db/Teachers/GetBlockedCount.tsx new file mode 100644 index 0000000..67b983b --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetBlockedCount.tsx @@ -0,0 +1,9 @@ +import { COL_TEACHERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetBlockedCount(): Promise { + const { totalItems: count } = await pb.collection(COL_TEACHERS).getList(1, 1, { + filter: 'status = "blocked"', + }); + return count; +} diff --git a/002_source/cms/src/db/Teachers/GetById.tsx b/002_source/cms/src/db/Teachers/GetById.tsx new file mode 100644 index 0000000..db16c4d --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetById.tsx @@ -0,0 +1,7 @@ +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; +import { RecordModel } from 'pocketbase'; + +export async function getTeacherById(id: string): Promise { + return pb.collection(COL_TEACHERS).getOne(id); +} diff --git a/002_source/cms/src/db/Teachers/GetPendingCount.tsx b/002_source/cms/src/db/Teachers/GetPendingCount.tsx new file mode 100644 index 0000000..d6661ca --- /dev/null +++ b/002_source/cms/src/db/Teachers/GetPendingCount.tsx @@ -0,0 +1,9 @@ +import { COL_CUSTOMERS } from '@/constants'; +import { pb } from '@/lib/pb'; + +export default async function GetPendingCount(): Promise { + const { totalItems: count } = await pb.collection(COL_CUSTOMERS).getList(1, 1, { + filter: 'status = "pending"', + }); + return count; +} diff --git a/002_source/cms/src/db/Teachers/Helloworld.tsx b/002_source/cms/src/db/Teachers/Helloworld.tsx new file mode 100644 index 0000000..2487997 --- /dev/null +++ b/002_source/cms/src/db/Teachers/Helloworld.tsx @@ -0,0 +1,3 @@ +export function helloCustomer() { + return 'Hello from Customers module!'; +} diff --git a/002_source/cms/src/db/Teachers/Update.tsx b/002_source/cms/src/db/Teachers/Update.tsx new file mode 100644 index 0000000..f40054f --- /dev/null +++ b/002_source/cms/src/db/Teachers/Update.tsx @@ -0,0 +1,8 @@ +import { pb } from '@/lib/pb'; +import { COL_TEACHERS } from '@/constants'; +import type { RecordModel } from 'pocketbase'; +import type { EditFormProps } from '@/components/dashboard/teacher/type.d'; + +export async function updateTeacher(id: string, data: Partial): Promise { + return pb.collection(COL_TEACHERS).update(id, data); +} diff --git a/002_source/cms/src/db/Teachers/_GUIDELINES.md b/002_source/cms/src/db/Teachers/_GUIDELINES.md new file mode 100644 index 0000000..fc7391f --- /dev/null +++ b/002_source/cms/src/db/Teachers/_GUIDELINES.md @@ -0,0 +1,31 @@ +# GUIDELINES + +This folder contains drivers for `Teacher`/`Teachers` records using PocketBase: + +- create (Create.tsx) +- read (GetById.tsx) +- write (Update.tsx) +- count (GetAllCount.tsx, GetActiveCount.tsx, GetBlockedCount.tsx, GetPendingCount.tsx) +- misc (Helloworld.tsx) +- delete (Delete.tsx) +- list (GetAll.tsx) + +the `@` sign refer to `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src` + +## Assumption and Requirements + +- assume `pb` is located in `@/lib/pb` +- no need to handle error in this function, i'll handle it in the caller +- type information defined in `/home/logic/_wsl_workspace/001_github_ws/lettersoup-online-ws/lettersoup-online/project/002_source/cms/src/db/Customers/type.d.tsx` + +simple template: + +```typescript +import { pb } from '@/lib/pb'; +import { COL_CUSTOMERS } from '@/constants'; + +export async function createCustomer(data: CreateFormProps) { + // ...content + // use direct return of pb.collection (e.g. return pb.collection(xxx)) +} +```