From caa224cbb61c6deb534f1270dce50e186e6012ec Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sat, 26 Apr 2025 07:44:55 +0800 Subject: [PATCH] update, --- .../app/dashboard/vocabularies/list/page.tsx | 12 +++++----- .../components/dashboard/vocabulary/type.d.ts | 22 ++++++++++--------- .../vocabulary/vocabulary-create-form.tsx | 7 +++--- .../vocabulary/vocabulary-edit-form.tsx | 1 + 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/002_source/cms/src/app/dashboard/vocabularies/list/page.tsx b/002_source/cms/src/app/dashboard/vocabularies/list/page.tsx index f52e83c..db5f93f 100644 --- a/002_source/cms/src/app/dashboard/vocabularies/list/page.tsx +++ b/002_source/cms/src/app/dashboard/vocabularies/list/page.tsx @@ -48,7 +48,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { const [rowsPerPage, setRowsPerPage] = React.useState(5); // const [f, setF] = React.useState([]); - const [currentPage, setCurrentPage] = React.useState(1); + const [currentPage, setCurrentPage] = React.useState(0); // const [recordCount, setRecordCount] = React.useState(0); const [listOption, setListOption] = React.useState({}); @@ -57,12 +57,14 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element { // const reloadRows = async (): Promise => { try { - const models: ListResult = await pb.collection(COL_VOCABULARIES).getList(1, 5, { - expand: 'cat_id', - }); + const models: ListResult = await pb + .collection(COL_VOCABULARIES) + .getList(currentPage + 1, rowsPerPage, { + ...listOption, + expand: 'cat_id', + }); const { items, totalItems } = models; - const tempVocabularies: Vocabulary[] = items.map((v) => { return { ...defaultVocabulary, ...v }; }); diff --git a/002_source/cms/src/components/dashboard/vocabulary/type.d.ts b/002_source/cms/src/components/dashboard/vocabulary/type.d.ts index 6880170..1506e8e 100644 --- a/002_source/cms/src/components/dashboard/vocabulary/type.d.ts +++ b/002_source/cms/src/components/dashboard/vocabulary/type.d.ts @@ -27,16 +27,17 @@ export interface Vocabulary { // RULES: for use with vocabulary-create-form.tsx // when you update, please take a look into `vocabulary-create-form.tsx` -export interface CreateForm { - image?: string; - sound?: string; - word?: string; - word_c?: string; - sample_e?: string; - sample_c?: string; - cat_id?: string; - category?: string; - lesson_type_id?: string; +export interface CreateFormProps { + image: File[] | null; + sound: string; + word: string; + word_c: string; + sample_e: string; + sample_c: string; + cat_id: string; + category: string; + lesson_type_id: string; + visible: string; } // RULES: for use with vocabulary-edit-form.tsx @@ -51,6 +52,7 @@ export interface EditFormProps { cat_id: string; category: string; lesson_type_id: string; + visible: string; } // RULES: diff --git a/002_source/cms/src/components/dashboard/vocabulary/vocabulary-create-form.tsx b/002_source/cms/src/components/dashboard/vocabulary/vocabulary-create-form.tsx index 6a9dad3..5df3749 100644 --- a/002_source/cms/src/components/dashboard/vocabulary/vocabulary-create-form.tsx +++ b/002_source/cms/src/components/dashboard/vocabulary/vocabulary-create-form.tsx @@ -37,7 +37,7 @@ import { toast } from '@/components/core/toaster'; import FormLoading from '@/components/loading'; import ErrorDisplay from '../error'; -import type { EditFormProps } from './type'; +import type { CreateFormProps, EditFormProps } from './type'; import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories'; import isDevelopment from '@/lib/check-is-development'; @@ -94,7 +94,7 @@ export function VocabularyCreateForm(): React.JSX.Element { async (values: Values): Promise => { setIsCreating(true); - const tempUpdate: EditFormProps = { + const tempUpdate: CreateFormProps = { image: values.avatar ? [await base64ToFile(values.avatar)] : null, sound: '', word: values.word, @@ -104,13 +104,14 @@ export function VocabularyCreateForm(): React.JSX.Element { cat_id: values.cat_id, category: '', lesson_type_id: '', + visible: values.visible, }; try { const result = await pb.collection(COL_VOCABULARIES).create(tempUpdate); logger.debug(result); toast.success(t('create.success')); - // router.push(paths.dashboard.lesson_categories.details('1')); + router.push(paths.dashboard.vocabularies.list); } catch (err) { logger.error(err); toast.error(t('create.failed')); diff --git a/002_source/cms/src/components/dashboard/vocabulary/vocabulary-edit-form.tsx b/002_source/cms/src/components/dashboard/vocabulary/vocabulary-edit-form.tsx index 5363dc2..f67992b 100644 --- a/002_source/cms/src/components/dashboard/vocabulary/vocabulary-edit-form.tsx +++ b/002_source/cms/src/components/dashboard/vocabulary/vocabulary-edit-form.tsx @@ -101,6 +101,7 @@ export function VocabularyEditForm(): React.JSX.Element { cat_id: values.cat_id, category: '', lesson_type_id: '', + visible: values.visible, }; // try {