update,
This commit is contained in:
@@ -26,19 +26,26 @@ import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr
|
|||||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||||
import { ShieldWarning as ShieldWarningIcon } from '@phosphor-icons/react/dist/ssr/ShieldWarning';
|
import { ShieldWarning as ShieldWarningIcon } from '@phosphor-icons/react/dist/ssr/ShieldWarning';
|
||||||
import { User as UserIcon } from '@phosphor-icons/react/dist/ssr/User';
|
import { User as UserIcon } from '@phosphor-icons/react/dist/ssr/User';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
import PocketBase from 'pocketbase';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { paths } from '@/paths';
|
import { paths } from '@/paths';
|
||||||
import { dayjs } from '@/lib/dayjs';
|
import { dayjs } from '@/lib/dayjs';
|
||||||
|
import { logger } from '@/lib/default-logger';
|
||||||
import { PropertyItem } from '@/components/core/property-item';
|
import { PropertyItem } from '@/components/core/property-item';
|
||||||
import { PropertyList } from '@/components/core/property-list';
|
import { PropertyList } from '@/components/core/property-list';
|
||||||
|
import { toast } from '@/components/core/toaster';
|
||||||
// import { getLessonTypeById } from '@/components/dashboard/lesson_type/http-actions';
|
// import { getLessonTypeById } from '@/components/dashboard/lesson_type/http-actions';
|
||||||
import { LessonTypeDefaultValue, type LessonType } from '@/components/dashboard/lesson_type/ILessonType';
|
import { LessonTypeDefaultValue, type LessonType } from '@/components/dashboard/lesson_type/ILessonType';
|
||||||
|
import { defaultLessonType } from '@/components/dashboard/lesson_type/interfaces';
|
||||||
import { Notifications } from '@/components/dashboard/lesson_type/notifications';
|
import { Notifications } from '@/components/dashboard/lesson_type/notifications';
|
||||||
import { Payments } from '@/components/dashboard/lesson_type/payments';
|
import { Payments } from '@/components/dashboard/lesson_type/payments';
|
||||||
import type { Address } from '@/components/dashboard/lesson_type/shipping-address';
|
import type { Address } from '@/components/dashboard/lesson_type/shipping-address';
|
||||||
import { ShippingAddress } from '@/components/dashboard/lesson_type/shipping-address';
|
import { ShippingAddress } from '@/components/dashboard/lesson_type/shipping-address';
|
||||||
|
|
||||||
|
const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL);
|
||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { typeId } = useParams<{ typeId: string }>();
|
const { typeId } = useParams<{ typeId: string }>();
|
||||||
@@ -51,17 +58,20 @@ export default function Page(): React.JSX.Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// getLessonTypeById(typeId)
|
if (typeId) {
|
||||||
// .then((lessonType: LessonType) => {
|
pb.collection('LessonsTypes')
|
||||||
// setIsLoading(false);
|
.getOne(typeId)
|
||||||
// setShowLessonType(lessonType);
|
.then((lessonType: RecordModel) => {
|
||||||
// })
|
setShowLessonType({ ...defaultLessonType, ...lessonType });
|
||||||
// .catch((err) => {
|
setIsLoading(false);
|
||||||
// // console.error(err);
|
})
|
||||||
// console.error(t('lessonType.load_error'));
|
.catch((err) => {
|
||||||
// });
|
logger.error(err);
|
||||||
// console.log('hello');
|
toast(t('dashboard.lessonTypes.list.error'));
|
||||||
}, []);
|
});
|
||||||
|
}
|
||||||
|
}, [typeId]);
|
||||||
|
|
||||||
if (isLoading) return <div>{t('common.loading')}</div>;
|
if (isLoading) return <div>{t('common.loading')}</div>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@@ -14,6 +14,11 @@ import { LessonTypeEditForm } from '@/components/dashboard/lesson_type/lesson-ty
|
|||||||
|
|
||||||
export default function Page(): React.JSX.Element {
|
export default function Page(): React.JSX.Element {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
console.log('helloworld');
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
14
002_source/cms/src/app/helloworld/page.tsx
Normal file
14
002_source/cms/src/app/helloworld/page.tsx
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
||||||
|
|
||||||
|
function Page(): React.JSX.Element {
|
||||||
|
React.useLayoutEffect(() => {
|
||||||
|
console.log('helloworld');
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return <>helloworld</>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Page;
|
@@ -16,7 +16,6 @@ export function I18nProvider({ children, language = 'en' }: I18nProviderProps):
|
|||||||
const { i18n } = useTranslation();
|
const { i18n } = useTranslation();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
console.log(`find me ? I18nProvider ${language}`);
|
|
||||||
// i18n
|
// i18n
|
||||||
// .changeLanguage(language)
|
// .changeLanguage(language)
|
||||||
// .then(() => {
|
// .then(() => {
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import RouterLink from 'next/link';
|
import RouterLink from 'next/link';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { COL_LESSON_TYPES } from '@/constants';
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
import { MenuItem } from '@mui/material';
|
import { MenuItem } from '@mui/material';
|
||||||
@@ -23,6 +24,8 @@ import Select from '@mui/material/Select';
|
|||||||
import Stack from '@mui/material/Stack';
|
import Stack from '@mui/material/Stack';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
import Grid from '@mui/material/Unstable_Grid2';
|
import Grid from '@mui/material/Unstable_Grid2';
|
||||||
|
import type { RecordModel } from 'pocketbase';
|
||||||
|
import PocketBase from 'pocketbase';
|
||||||
// import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
// import { Camera as CameraIcon } from '@phosphor-icons/react/dist/ssr/Camera';
|
||||||
// import axios from 'axios';
|
// import axios from 'axios';
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
@@ -37,7 +40,9 @@ import { toast } from '@/components/core/toaster';
|
|||||||
// import { getLessonTypeById, updateLessonType } from './http-actions';
|
// import { getLessonTypeById, updateLessonType } from './http-actions';
|
||||||
// TODO: this may be wrong
|
// TODO: this may be wrong
|
||||||
import type { LessonType } from './ILessonType';
|
import type { LessonType } from './ILessonType';
|
||||||
import type { LessonTypeEditFormProps } from './interfaces';
|
import { defaultLessonType, type LessonTypeEditFormProps } from './interfaces';
|
||||||
|
|
||||||
|
const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL);
|
||||||
|
|
||||||
// function fileToBase64(file: Blob): Promise<string> {
|
// function fileToBase64(file: Blob): Promise<string> {
|
||||||
// return new Promise((resolve, reject) => {
|
// return new Promise((resolve, reject) => {
|
||||||
@@ -73,6 +78,7 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { typeId } = useParams<{ typeId: string }>();
|
const { typeId } = useParams<{ typeId: string }>();
|
||||||
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
const [isUpdating, setIsUpdating] = React.useState<boolean>(false);
|
||||||
|
const [isLoading, setIsLoading] = React.useState<boolean>(false);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
@@ -83,8 +89,7 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
// watch,
|
// watch,
|
||||||
} = useForm<Values>({ defaultValues, resolver: zodResolver(schema) });
|
} = useForm<Values>({ defaultValues, resolver: zodResolver(schema) });
|
||||||
|
|
||||||
const onSubmit = React.useCallback(
|
const onSubmit = React.useCallback(async (values: Values): Promise<void> => {
|
||||||
async (values: Values): Promise<void> => {
|
|
||||||
setIsUpdating(true);
|
setIsUpdating(true);
|
||||||
const tempUpdate: LessonTypeEditFormProps = {
|
const tempUpdate: LessonTypeEditFormProps = {
|
||||||
name: values.name,
|
name: values.name,
|
||||||
@@ -93,21 +98,20 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
visible: values.visible_to_user ? 'visible' : 'hidden',
|
visible: values.visible_to_user ? 'visible' : 'hidden',
|
||||||
};
|
};
|
||||||
|
|
||||||
// updateLessonType(tempUpdate, typeId)
|
pb.collection(COL_LESSON_TYPES)
|
||||||
// .then((res) => {
|
.update(typeId, tempUpdate)
|
||||||
// logger.debug(res);
|
.then((res) => {
|
||||||
// toast.success(t('dashboard.lessonTypes.update.success'));
|
logger.debug(res);
|
||||||
// setIsUpdating(false);
|
toast.success(t('dashboard.lessonTypes.update.success'));
|
||||||
// router.push(paths.dashboard.lesson_types.list);
|
setIsUpdating(false);
|
||||||
// })
|
router.push(paths.dashboard.lesson_types.list);
|
||||||
// .catch((err) => {
|
})
|
||||||
// logger.error(err);
|
.catch((err) => {
|
||||||
// toast.error('Something went wrong!');
|
logger.error(err);
|
||||||
// setIsUpdating(false);
|
toast.error('Something went wrong!');
|
||||||
// });
|
setIsUpdating(false);
|
||||||
},
|
});
|
||||||
[router]
|
}, []);
|
||||||
);
|
|
||||||
|
|
||||||
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
const avatarInputRef = React.useRef<HTMLInputElement>(null);
|
||||||
// const avatar = watch('avatar');
|
// const avatar = watch('avatar');
|
||||||
@@ -124,20 +128,30 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
[setValue]
|
[setValue]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleLoad = React.useCallback(
|
||||||
|
(id: string) => {
|
||||||
|
pb.collection(COL_LESSON_TYPES)
|
||||||
|
.getOne(id)
|
||||||
|
.then((lessonType: RecordModel) => {
|
||||||
|
reset({ ...defaultLessonType, ...lessonType });
|
||||||
|
|
||||||
|
setIsLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
logger.error(err);
|
||||||
|
toast(t('dashboard.lessonTypes.list.error'));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[typeId]
|
||||||
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
// getLessonTypeById(typeId)
|
handleLoad(typeId);
|
||||||
// .then((lessonType: LessonType) => {
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
// reset({
|
}, [typeId]);
|
||||||
// name: lessonType.name,
|
|
||||||
// type: lessonType.type,
|
if (isLoading) return <>loading</>;
|
||||||
// pos: lessonType.pos,
|
|
||||||
// visible_to_user: lessonType.visible,
|
|
||||||
// });
|
|
||||||
// })
|
|
||||||
// .catch((err) => {
|
|
||||||
// // console.error(err);
|
|
||||||
// });
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
@@ -223,7 +237,14 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormControl error={Boolean(errors.pos)} fullWidth>
|
<FormControl error={Boolean(errors.pos)} fullWidth>
|
||||||
<InputLabel required>{t('dashboard.lessonTypes.edit.position')}</InputLabel>
|
<InputLabel required>{t('dashboard.lessonTypes.edit.position')}</InputLabel>
|
||||||
<OutlinedInput {...field} />
|
<OutlinedInput
|
||||||
|
{...field}
|
||||||
|
onChange={(e) => {
|
||||||
|
field.onChange(parseInt(e.target.value));
|
||||||
|
}}
|
||||||
|
type="number"
|
||||||
|
/>
|
||||||
|
|
||||||
{errors.pos ? <FormHelperText>{errors.pos.message}</FormHelperText> : null}
|
{errors.pos ? <FormHelperText>{errors.pos.message}</FormHelperText> : null}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
@@ -237,8 +258,8 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
<FormControl error={Boolean(errors.visible_to_user)} fullWidth>
|
<FormControl error={Boolean(errors.visible_to_user)} fullWidth>
|
||||||
<InputLabel>{t('dashboard.lessonTypes.edit.visibleToUser')}</InputLabel>
|
<InputLabel>{t('dashboard.lessonTypes.edit.visibleToUser')}</InputLabel>
|
||||||
<Select {...field}>
|
<Select {...field}>
|
||||||
<MenuItem value={'visible'}>{t('dashboard.lessonTypes.edit.visible')}</MenuItem>
|
<MenuItem value="visible">{t('dashboard.lessonTypes.edit.visible')}</MenuItem>
|
||||||
<MenuItem value={'hidden'}>{t('dashboard.lessonTypes.edit.hidden')}</MenuItem>
|
<MenuItem value="hidden">{t('dashboard.lessonTypes.edit.hidden')}</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
{errors.visible_to_user ? (
|
{errors.visible_to_user ? (
|
||||||
@@ -256,7 +277,7 @@ export function LessonTypeEditForm(): React.JSX.Element {
|
|||||||
<Button color="secondary" component={RouterLink} href={paths.dashboard.lesson_types.list}>
|
<Button color="secondary" component={RouterLink} href={paths.dashboard.lesson_types.list}>
|
||||||
{t('dashboard.lessonTypes.edit.cancelButton')}
|
{t('dashboard.lessonTypes.edit.cancelButton')}
|
||||||
</Button>
|
</Button>
|
||||||
<LoadingButton disabled={isUpdating} type="submit" variant="contained" loading={isUpdating}>
|
<LoadingButton disabled={isUpdating} loading={isUpdating} type="submit" variant="contained">
|
||||||
{t('dashboard.lessonTypes.edit.updateButton')}
|
{t('dashboard.lessonTypes.edit.updateButton')}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</CardActions>
|
</CardActions>
|
||||||
|
@@ -36,7 +36,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LessonT
|
|||||||
<Link
|
<Link
|
||||||
color="inherit"
|
color="inherit"
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
href={paths.dashboard.lesson_types.details('1')}
|
href={paths.dashboard.lesson_types.details(row.id)}
|
||||||
sx={{ whiteSpace: 'nowrap' }}
|
sx={{ whiteSpace: 'nowrap' }}
|
||||||
variant="subtitle2"
|
variant="subtitle2"
|
||||||
>
|
>
|
||||||
|
3
002_source/cms/src/constants.ts
Normal file
3
002_source/cms/src/constants.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
const COL_LESSON_TYPES = 'LessonsTypes';
|
||||||
|
|
||||||
|
export { COL_LESSON_TYPES };
|
Reference in New Issue
Block a user