From 785894f62b61669f3c20e37801f91745aca5855e Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Thu, 17 Apr 2025 18:59:23 +0800 Subject: [PATCH] update to remove temporary files, --- 002_source/cms/.gitignore | 2 + .../lesson-category-edit-form copy 2.tsx | 334 ------------------ 2 files changed, 2 insertions(+), 334 deletions(-) delete mode 100644 002_source/cms/src/components/dashboard/lesson_category/lesson-category-edit-form copy 2.tsx diff --git a/002_source/cms/.gitignore b/002_source/cms/.gitignore index 48b2552..4829ca2 100644 --- a/002_source/cms/.gitignore +++ b/002_source/cms/.gitignore @@ -1,3 +1,5 @@ +**/~* +**/*copy*.tsx **/*copy.tsx # **/repomix-output.xml diff --git a/002_source/cms/src/components/dashboard/lesson_category/lesson-category-edit-form copy 2.tsx b/002_source/cms/src/components/dashboard/lesson_category/lesson-category-edit-form copy 2.tsx deleted file mode 100644 index e4aa1d5..0000000 --- a/002_source/cms/src/components/dashboard/lesson_category/lesson-category-edit-form copy 2.tsx +++ /dev/null @@ -1,334 +0,0 @@ -'use client'; - -import * as React from 'react'; -import RouterLink from 'next/link'; -import { useParams, useRouter } from 'next/navigation'; -import { COL_LESSON_CATEGORIES, NS_LESSON_CATEGORY } from '@/constants'; -import { zodResolver } from '@hookform/resolvers/zod'; -import { LoadingButton } from '@mui/lab'; -import { Avatar, Divider, MenuItem } from '@mui/material'; -// import Avatar from '@mui/material/Avatar'; -import Box from '@mui/material/Box'; -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 Checkbox from '@mui/material/Checkbox'; - -import FormControl from '@mui/material/FormControl'; -// import FormControlLabel from '@mui/material/FormControlLabel'; -import FormHelperText from '@mui/material/FormHelperText'; -import InputLabel from '@mui/material/InputLabel'; -import OutlinedInput from '@mui/material/OutlinedInput'; -import Select from '@mui/material/Select'; -import Stack from '@mui/material/Stack'; -import Typography from '@mui/material/Typography'; -import Grid from '@mui/material/Unstable_Grid2'; -import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera'; -import type { RecordModel } from 'pocketbase'; -import { Controller, useForm } from 'react-hook-form'; -import { useTranslation } from 'react-i18next'; -import { z as zod } from 'zod'; - -import { paths } from '@/paths'; -import { logger } from '@/lib/default-logger'; -import { pb } from '@/lib/pb'; -import { Option } from '@/components/core/option'; -import { TextEditor } from '@/components/core/text-editor/text-editor'; -import { toast } from '@/components/core/toaster'; -import FormLoading from '@/components/loading'; - -import ErrorDisplay from '../error'; -import { defaultLessonCategory } from './_constants'; -import { fileToBase64 } from './file-to-base64'; -import { LessonCategory, EditFormProps } from './types'; - -const schema = zod.object({ - cat_name: zod.string().min(1, 'Name is required').max(255), - type: zod.string().min(1, 'Name is required').max(255), - pos: zod.number().min(1, 'Phone is required').max(15), - visible: zod.string().max(255), - description: zod.string().optional(), - remarks: zod.string().optional(), -}); - -type Values = zod.infer; - -const defaultValues = { - cat_name: '', - type: '', - pos: 1, - visible: 'visible', -} satisfies Values; - -export function LessonCategoryEditForm(): React.JSX.Element { - const router = useRouter(); - const { t } = useTranslation(['common', 'lesson_category']); - - const NS_DEFAULT = { ns: 'lesson_category' }; - const { cat_id: catId } = useParams<{ cat_id: string }>(); - // - const [isUpdating, setIsUpdating] = React.useState(false); - const [showLoading, setShowLoading] = React.useState(false); - const [showError, setShowError] = React.useState(false); - - const { - control, - handleSubmit, - formState: { errors }, - setValue, - reset, - watch, - } = useForm({ defaultValues, resolver: zodResolver(schema) }); - - const onSubmit = React.useCallback(async (values: Values): Promise => { - // setIsUpdating(true); - // const tempUpdate: LessonCategoryEditFormProps = { - // name: values.cat_name, - // type: values.type, - // pos: values.pos, - // visible: values.visible ? 'visible' : 'hidden', - // }; - - - // pb.collection(COL_LESSON_CATEGORIES) - // .update(catId, tempUpdate) - // .then((res) => { - // logger.debug(res); - // toast.success(t('update.success', NS_DEFAULT)); - // setIsUpdating(false); - // router.push(paths.dashboard.lesson_categories.list); - // }) - // .catch((err) => { - // logger.error(err); - // toast.error('Something went wrong!'); - // }) - // .finally(() => { - // // - // setIsUpdating(false); - // }); - }, []); - - const avatarInputRef = React.useRef(null); - // const avatar = watch('avatar'); - - const handleAvatarChange = React.useCallback( - async (event: React.ChangeEvent) => { - const file = event.target.files?.[0]; - - if (file) { - const url = await fileToBase64(file); - // setValue('avatar', url); - } - }, - [setValue] - ); - - const [textDescription, setTextDescription] = React.useState('loading'); - const handleLoad = React.useCallback( - (id: string) => { - setShowLoading(true); - pb.collection(COL_LESSON_CATEGORIES) - .getOne(id) - .then((model: RecordModel) => { - const temp: LessonCategory = { ...defaultLessonCategory, ...model }; - reset(temp); - setTextDescription(temp.description); - }) - .catch((err) => { - logger.error(err); - toast(t('list.error', NS_DEFAULT)); - }) - .finally(() => { - setShowLoading(false); - }); - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [catId] - ); - - React.useEffect(() => { - handleLoad(catId); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [catId]); - - if (showLoading) return ; - if (showError) - return ( - - ); - - return ( -
- - - } spacing={4}> - - {t('edit.basic-info', NS_DEFAULT)} - - - - - {/* - - // TODO: resume me - - - */} - - - {t('edit.avatar', NS_DEFAULT)} - {t('edit.avatarRequirements', NS_DEFAULT)} - - - - - - - ( - - {t('edit.name', NS_DEFAULT)} - - {errors.cat_name ? {errors.cat_name.message} : null} - - )} - /> - - - - ( - - {t('edit.position', NS_DEFAULT)} - { - field.onChange(parseInt(e.target.value)); - }} - type="number" - /> - - {errors.pos ? {errors.pos.message} : null} - - )} - /> - - - ( - - {t('edit.visible', NS_DEFAULT)} - - - {errors.visible ? {errors.visible.message} : null} - - )} - /> - - - - - - {t('create.detail-information', NS_DEFAULT)} - - - { - console.log({ field }); - return ( - - - {t('create.description', NS_DEFAULT)} - - - {JSON.stringify({ field })} - { - console.log(editor.getHTML()); - field.onChange({ target: { value: editor.getHTML() } }); - }} - placeholder={t('edit.write-something', NS_DEFAULT)} - /> - - - ); - }} - /> - - - ( - - - {t('create.remarks', NS_DEFAULT)} - - - - - - )} - /> - - - - - - - - - - {t('edit.updateButton', NS_DEFAULT)} - - - -
- ); -}