diff --git a/002_source/cms/src/app/dashboard/connectives/view/[cat_id]/page.tsx b/002_source/cms/src/app/dashboard/connectives/view/[cat_id]/page.tsx index cc14c52..0d7f505 100644 --- a/002_source/cms/src/app/dashboard/connectives/view/[cat_id]/page.tsx +++ b/002_source/cms/src/app/dashboard/connectives/view/[cat_id]/page.tsx @@ -34,6 +34,7 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; import { logger } from '@/lib/default-logger'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { pb } from '@/lib/pb'; import { PropertyItem } from '@/components/core/property-item'; import { PropertyList } from '@/components/core/property-list'; @@ -119,39 +120,72 @@ export default function Page(): React.JSX.Element { {t('dashboard.lessonCategorys.list.title')} - - + + empty
- + {showLessonCategory.name} } + icon={ + + } label={showLessonCategory.visible} size="small" variant="outlined" /> - + {showLessonCategory.id}
-
- - + + {( [ - { key: 'Customer ID', value: }, + { + key: 'Customer ID', + value: ( + + ), + }, { key: 'Name', value: showLessonCategory.name }, { key: 'Pos', value: showLessonCategory.pos }, { @@ -195,9 +238,20 @@ export default function Page(): React.JSX.Element { { key: 'Quota', value: ( - - - + + + 50% @@ -206,7 +260,11 @@ export default function Page(): React.JSX.Element { ] satisfies { key: string; value: React.ReactNode }[] ).map( (item): React.JSX.Element => ( - + ) )} @@ -223,11 +281,17 @@ export default function Page(): React.JSX.Element {
-
- + A deleted lesson category cannot be restored. All data will be permanently removed.
@@ -235,7 +299,10 @@ export default function Page(): React.JSX.Element {
- + }> + } @@ -294,8 +364,14 @@ export default function Page(): React.JSX.Element { title={t('billing-details', { ns: 'lesson_category' })} /> - - } sx={{ '--PropertyItem-padding': '16px' }}> + + } + sx={{ '--PropertyItem-padding': '16px' }} + > {( [ { key: 'Credit card', value: '**** 4142' }, @@ -307,7 +383,11 @@ export default function Page(): React.JSX.Element { ] satisfies { key: string; value: React.ReactNode }[] ).map( (item): React.JSX.Element => ( - + ) )} @@ -317,7 +397,10 @@ export default function Page(): React.JSX.Element { }> + } @@ -329,7 +412,10 @@ export default function Page(): React.JSX.Element { title={t('shipping-addresses', { ns: 'lesson_category' })} /> - + {( [ { @@ -351,7 +437,11 @@ export default function Page(): React.JSX.Element { }, ] satisfies Address[] ).map((address) => ( - + ))} diff --git a/002_source/cms/src/app/dashboard/cr/categories/view/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/cr/categories/view/[cat_id]/TitleCard.tsx index 9994060..37b6dea 100644 --- a/002_source/cms/src/app/dashboard/cr/categories/view/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/cr/categories/view/[cat_id]/TitleCard.tsx @@ -10,12 +10,9 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import type { CrCategory } from '@/components/dashboard/cr/categories/type'; -function getImageUrlFrRecord(record: CrCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} - export default function SampleTitleCard({ lpModel }: { lpModel: CrCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: CrCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/cr/questions/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/cr/questions/[cat_id]/TitleCard.tsx index 6e38fb6..553cbd0 100644 --- a/002_source/cms/src/app/dashboard/cr/questions/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/cr/questions/[cat_id]/TitleCard.tsx @@ -10,12 +10,9 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { LpCategory } from '@/components/dashboard/lp/categories/type'; -function getImageUrlFrRecord(record: LpCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} - export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/customers/[customerId]/TitleCard.tsx b/002_source/cms/src/app/dashboard/customers/[customerId]/TitleCard.tsx index 971bfa7..4c7bf8e 100644 --- a/002_source/cms/src/app/dashboard/customers/[customerId]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/customers/[customerId]/TitleCard.tsx @@ -9,14 +9,14 @@ 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 type { CrCategory } from '@/components/dashboard/cr/categories/type'; function getImageUrlFrRecord(record: Customer): string { - // TODO: fix this - // `http://127.0.0.1:8090/api/files/${'record.collectionId'}/${'record.id'}/${'record.cat_image'}`; - return 'getImageUrlFrRecord(helloworld)'; + // TODO: implement getImageUrlFrRecord + return 'not implemented'; } export default function SampleTitleCard({ lpModel }: { lpModel: Customer }): React.JSX.Element { diff --git a/002_source/cms/src/app/dashboard/lesson_categories/view/[cat_id]/page.tsx b/002_source/cms/src/app/dashboard/lesson_categories/view/[cat_id]/page.tsx index cc14c52..25c80a9 100644 --- a/002_source/cms/src/app/dashboard/lesson_categories/view/[cat_id]/page.tsx +++ b/002_source/cms/src/app/dashboard/lesson_categories/view/[cat_id]/page.tsx @@ -28,12 +28,13 @@ import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus'; import { ShieldWarning as ShieldWarningIcon } from '@phosphor-icons/react/dist/ssr/ShieldWarning'; import { User as UserIcon } from '@phosphor-icons/react/dist/ssr/User'; -import { RecordModel } from 'pocketbase'; +import type { RecordModel } from 'pocketbase'; import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; import { logger } from '@/lib/default-logger'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { pb } from '@/lib/pb'; import { PropertyItem } from '@/components/core/property-item'; import { PropertyList } from '@/components/core/property-list'; @@ -45,7 +46,7 @@ import { Notifications } from '@/components/dashboard/lesson_category/notificati import { Payments } from '@/components/dashboard/lesson_category/payments'; import type { Address } from '@/components/dashboard/lesson_category/shipping-address'; import { ShippingAddress } from '@/components/dashboard/lesson_category/shipping-address'; -import { LessonCategory } from '@/components/dashboard/lesson_category/type'; +import type { LessonCategory } from '@/components/dashboard/lesson_category/type'; // import type { LessonCategory } from '@/components/dashboard/lp_categories/type'; import FormLoading from '@/components/loading'; @@ -119,39 +120,72 @@ export default function Page(): React.JSX.Element { {t('dashboard.lessonCategorys.list.title')} - - + + empty
- + {showLessonCategory.name} } + icon={ + + } label={showLessonCategory.visible} size="small" variant="outlined" /> - + {showLessonCategory.id}
-
- - + + {( [ - { key: 'Customer ID', value: }, + { + key: 'Customer ID', + value: ( + + ), + }, { key: 'Name', value: showLessonCategory.name }, { key: 'Pos', value: showLessonCategory.pos }, { @@ -195,9 +238,20 @@ export default function Page(): React.JSX.Element { { key: 'Quota', value: ( - - - + + + 50% @@ -206,7 +260,11 @@ export default function Page(): React.JSX.Element { ] satisfies { key: string; value: React.ReactNode }[] ).map( (item): React.JSX.Element => ( - + ) )}
@@ -223,11 +281,17 @@ export default function Page(): React.JSX.Element {
-
- + A deleted lesson category cannot be restored. All data will be permanently removed.
@@ -235,7 +299,10 @@ export default function Page(): React.JSX.Element {
- + }> + } @@ -294,8 +364,14 @@ export default function Page(): React.JSX.Element { title={t('billing-details', { ns: 'lesson_category' })} /> - - } sx={{ '--PropertyItem-padding': '16px' }}> + + } + sx={{ '--PropertyItem-padding': '16px' }} + > {( [ { key: 'Credit card', value: '**** 4142' }, @@ -307,7 +383,11 @@ export default function Page(): React.JSX.Element { ] satisfies { key: string; value: React.ReactNode }[] ).map( (item): React.JSX.Element => ( - + ) )} @@ -317,7 +397,10 @@ export default function Page(): React.JSX.Element { }> + } @@ -329,7 +412,10 @@ export default function Page(): React.JSX.Element { title={t('shipping-addresses', { ns: 'lesson_category' })} /> - + {( [ { @@ -351,7 +437,11 @@ export default function Page(): React.JSX.Element { }, ] satisfies Address[] ).map((address) => ( - + ))} diff --git a/002_source/cms/src/app/dashboard/lp/categories/view/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/lp/categories/view/[cat_id]/TitleCard.tsx index 6e38fb6..5dfa618 100644 --- a/002_source/cms/src/app/dashboard/lp/categories/view/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/lp/categories/view/[cat_id]/TitleCard.tsx @@ -10,11 +10,8 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; -import { LpCategory } from '@/components/dashboard/lp/categories/type'; - -function getImageUrlFrRecord(record: LpCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; +import type { LpCategory } from '@/components/dashboard/lp/categories/type'; export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/lp/questions/view/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/lp/questions/view/[cat_id]/TitleCard.tsx index 6e38fb6..553cbd0 100644 --- a/002_source/cms/src/app/dashboard/lp/questions/view/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/lp/questions/view/[cat_id]/TitleCard.tsx @@ -10,12 +10,9 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { LpCategory } from '@/components/dashboard/lp/categories/type'; -function getImageUrlFrRecord(record: LpCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} - export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: LpCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/mf/categories/view/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/mf/categories/view/[cat_id]/TitleCard.tsx index 059baaf..77f36d2 100644 --- a/002_source/cms/src/app/dashboard/mf/categories/view/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/mf/categories/view/[cat_id]/TitleCard.tsx @@ -10,12 +10,9 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import type { MfCategory } from '@/components/dashboard/mf/categories/type'; -function getImageUrlFrRecord(record: MfCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} - export default function SampleTitleCard({ lpModel }: { lpModel: MfCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: MfCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/mf/questions/view/[cat_id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/mf/questions/view/[cat_id]/TitleCard.tsx index 059baaf..77f36d2 100644 --- a/002_source/cms/src/app/dashboard/mf/questions/view/[cat_id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/mf/questions/view/[cat_id]/TitleCard.tsx @@ -10,12 +10,9 @@ import { CaretDown as CaretDownIcon } from '@phosphor-icons/react/dist/ssr/Caret import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { useTranslation } from 'react-i18next'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import type { MfCategory } from '@/components/dashboard/mf/categories/type'; -function getImageUrlFrRecord(record: MfCategory): string { - return `http://127.0.0.1:8090/api/files/${record.collectionId}/${record.id}/${record.cat_image}`; -} - export default function SampleTitleCard({ lpModel }: { lpModel: MfCategory }): React.JSX.Element { const { t } = useTranslation(); @@ -28,7 +25,7 @@ export default function SampleTitleCard({ lpModel }: { lpModel: MfCategory }): R > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/students/view/[id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/students/view/[id]/TitleCard.tsx index 33aba02..0834068 100644 --- a/002_source/cms/src/app/dashboard/students/view/[id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/students/view/[id]/TitleCard.tsx @@ -9,14 +9,10 @@ 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 getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import type { Student } from '@/components/dashboard/student/type.d'; -// import type { CrCategory } from '@/components/dashboard/cr/categories/type'; - -function getImageUrlForStudent(student: Student): string { - return `http://127.0.0.1:8090/api/files/${student.collectionId}/${student.id}/${student.avatar}`; -} - export default function SampleTitleCard({ studentRecord }: { studentRecord: Student }): React.JSX.Element { const { t } = useTranslation(); @@ -29,7 +25,7 @@ export default function SampleTitleCard({ studentRecord }: { studentRecord: Stud > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/teachers/view/[id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/teachers/view/[id]/TitleCard.tsx index 066caab..81d361f 100644 --- a/002_source/cms/src/app/dashboard/teachers/view/[id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/teachers/view/[id]/TitleCard.tsx @@ -9,13 +9,9 @@ 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 { Teacher } from '@/components/dashboard/teacher/type.d'; -// import type { CrCategory } from '@/components/dashboard/cr/categories/type'; - -function getImageUrlFrRecord(teacher: Teacher): string { - return `http://127.0.0.1:8090/api/files/${teacher.collectionId}/${teacher.id}/${teacher.avatar}`; -} +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; +import type { Teacher } from '@/components/dashboard/teacher/type.d'; export default function SampleTitleCard({ teacherRecord }: { teacherRecord: Teacher }): React.JSX.Element { const { t } = useTranslation(); @@ -29,7 +25,7 @@ export default function SampleTitleCard({ teacherRecord }: { teacherRecord: Teac > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/user_metas/view/[id]/TitleCard.tsx b/002_source/cms/src/app/dashboard/user_metas/view/[id]/TitleCard.tsx index 066caab..81d361f 100644 --- a/002_source/cms/src/app/dashboard/user_metas/view/[id]/TitleCard.tsx +++ b/002_source/cms/src/app/dashboard/user_metas/view/[id]/TitleCard.tsx @@ -9,13 +9,9 @@ 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 { Teacher } from '@/components/dashboard/teacher/type.d'; -// import type { CrCategory } from '@/components/dashboard/cr/categories/type'; - -function getImageUrlFrRecord(teacher: Teacher): string { - return `http://127.0.0.1:8090/api/files/${teacher.collectionId}/${teacher.id}/${teacher.avatar}`; -} +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; +import type { Teacher } from '@/components/dashboard/teacher/type.d'; export default function SampleTitleCard({ teacherRecord }: { teacherRecord: Teacher }): React.JSX.Element { const { t } = useTranslation(); @@ -29,7 +25,7 @@ export default function SampleTitleCard({ teacherRecord }: { teacherRecord: Teac > {t('empty')} diff --git a/002_source/cms/src/app/dashboard/vocabularies/view/[cat_id]/page.tsx b/002_source/cms/src/app/dashboard/vocabularies/view/[cat_id]/page.tsx index 3b4f3d0..bddfef6 100644 --- a/002_source/cms/src/app/dashboard/vocabularies/view/[cat_id]/page.tsx +++ b/002_source/cms/src/app/dashboard/vocabularies/view/[cat_id]/page.tsx @@ -34,6 +34,7 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; import { logger } from '@/lib/default-logger'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { pb } from '@/lib/pb'; import { PropertyItem } from '@/components/core/property-item'; import { PropertyList } from '@/components/core/property-list'; @@ -128,7 +129,11 @@ export default function Page(): React.JSX.Element { sx={{ alignItems: 'center', flex: '1 1 auto' }} > diff --git a/002_source/cms/src/components/dashboard/user_meta/user-metas-table.tsx b/002_source/cms/src/components/dashboard/user_meta/user-metas-table.tsx index 2655bce..86eec3c 100644 --- a/002_source/cms/src/components/dashboard/user_meta/user-metas-table.tsx +++ b/002_source/cms/src/components/dashboard/user_meta/user-metas-table.tsx @@ -26,6 +26,7 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { DataTable } from '@/components/core/data-table'; import type { ColumnDef } from '@/components/core/data-table'; @@ -43,7 +44,7 @@ function columns(handleDeleteClick: (userMetaId: string) => void): ColumnDef
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 1506e8e..e309b4a 100644 --- a/002_source/cms/src/components/dashboard/vocabulary/type.d.ts +++ b/002_source/cms/src/components/dashboard/vocabulary/type.d.ts @@ -1,10 +1,9 @@ // RULES: // should match the collection `Vocabularies` from `schema.dbml` export interface Vocabulary { - id: string; created?: string; updated?: string; - image?: string; + image: string; sound?: string; word?: string; word_c?: string; @@ -23,6 +22,9 @@ export interface Vocabulary { // }; }; + // + id: string; + collectionId: string; } // RULES: for use with vocabulary-create-form.tsx diff --git a/002_source/cms/src/components/dashboard/vocabulary/vocabularies-table.tsx b/002_source/cms/src/components/dashboard/vocabulary/vocabularies-table.tsx index 44ac46d..5d10647 100644 --- a/002_source/cms/src/components/dashboard/vocabulary/vocabularies-table.tsx +++ b/002_source/cms/src/components/dashboard/vocabulary/vocabularies-table.tsx @@ -16,12 +16,13 @@ import { useTranslation } from 'react-i18next'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { DataTable } from '@/components/core/data-table'; import type { ColumnDef } from '@/components/core/data-table'; import ConfirmDeleteModal from './confirm-delete-modal'; -import { useVocabulariesSelection } from './vocabularies-selection-context'; import type { Vocabulary } from './type'; +import { useVocabulariesSelection } from './vocabularies-selection-context'; function columns(handleDeleteClick: (testId: string) => void): ColumnDef[] { return [ @@ -45,7 +46,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef 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 f67992b..47ef720 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 @@ -4,6 +4,7 @@ import * as React from 'react'; import RouterLink from 'next/link'; import { useParams, useRouter } from 'next/navigation'; import { COL_VOCABULARIES } from '@/constants'; +import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoadingButton } from '@mui/lab'; import { Avatar, Divider } from '@mui/material'; @@ -12,7 +13,6 @@ import Button from '@mui/material/Button'; import Card from '@mui/material/Card'; import CardActions from '@mui/material/CardActions'; import CardContent from '@mui/material/CardContent'; - import FormControl from '@mui/material/FormControl'; import FormHelperText from '@mui/material/FormHelperText'; import InputLabel from '@mui/material/InputLabel'; @@ -27,8 +27,10 @@ import { useTranslation } from 'react-i18next'; import { z as zod } from 'zod'; import { paths } from '@/paths'; +import isDevelopment from '@/lib/check-is-development'; import { logger } from '@/lib/default-logger'; import { base64ToFile, fileToBase64 } from '@/lib/file-to-base64'; +import getImageUrlFromFile from '@/lib/get-image-url-from-file.ts'; import { pb } from '@/lib/pb'; import { Option } from '@/components/core/option'; import { toast } from '@/components/core/toaster'; @@ -36,8 +38,6 @@ import FormLoading from '@/components/loading'; import ErrorDisplay from '../error'; import type { EditFormProps } from './type'; -import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories'; -import isDevelopment from '@/lib/check-is-development'; const schema = zod.object({ image: zod.union([zod.array(zod.any()), zod.string()]).optional(), @@ -144,9 +144,7 @@ export function VocabularyEditForm(): React.JSX.Element { reset({ ...defaultValues, ...result }); if (result.image !== '') { - const fetchResult = await fetch( - `http://127.0.0.1:8090/api/files/${result.collectionId}/${result.id}/${result.image}` - ); + const fetchResult = await fetch(getImageUrlFromFile(result.collectionId, result.id, result.image)); const blob = await fetchResult.blob(); const url = await fileToBase64(blob); diff --git a/002_source/cms/src/lib/get-image-url-from-file.ts.ts b/002_source/cms/src/lib/get-image-url-from-file.ts.ts index 8101ca7..5ca47a1 100644 --- a/002_source/cms/src/lib/get-image-url-from-file.ts.ts +++ b/002_source/cms/src/lib/get-image-url-from-file.ts.ts @@ -3,6 +3,8 @@ // get file url from pocketbase record // -export default function getImageUrlFromFile(collectionId: string, id: string, imgFile: string): string { - return `http://127.0.0.1:8090/api/files/${collectionId}/${id}/${imgFile}`; +import { POCKETBASE_URL } from './pb'; + +export default function getImageUrlFromFile(collectionId: string, id: string, imgFile: string | undefined): string { + return `${POCKETBASE_URL}/api/files/${collectionId}/${id}/${imgFile}`; } diff --git a/002_source/cms/src/lib/pb.ts b/002_source/cms/src/lib/pb.ts index d564382..a0646f2 100644 --- a/002_source/cms/src/lib/pb.ts +++ b/002_source/cms/src/lib/pb.ts @@ -1,3 +1,6 @@ import PocketBase from 'pocketbase'; +if (!process.env.NEXT_PUBLIC_POCKETBASE_URL) throw new Error('the pocketbase url cannot empty'); +export const POCKETBASE_URL: string = process.env.NEXT_PUBLIC_POCKETBASE_URL; + export const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL);