diff --git a/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx b/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx index 6885456..9bee1da 100644 --- a/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx +++ b/002_source/cms/src/components/dashboard/teacher/teacher-edit-form.tsx @@ -1,10 +1,12 @@ 'use client'; +// src/components/dashboard/teacher/teacher-edit-form.tsx +// import * as React from 'react'; import RouterLink from 'next/link'; import { useParams, useRouter } from 'next/navigation'; // -import { COL_TEACHERS, COL_USER_METAS } from '@/constants'; +import { COL_USER_METAS } from '@/constants'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoadingButton } from '@mui/lab'; // @@ -32,6 +34,7 @@ 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 { pb } from '@/lib/pb'; @@ -40,7 +43,6 @@ import FormLoading from '@/components/loading'; // import ErrorDisplay from '../../error'; import ErrorDisplay from '../error'; -import isDevelopment from '@/lib/check-is-development'; // TODO: review this const schema = zod.object({ diff --git a/002_source/cms/src/components/dashboard/user.de/user-edit-form.tsx b/002_source/cms/src/components/dashboard/user.de/user-edit-form.tsx index bc08af1..a4fb402 100644 --- a/002_source/cms/src/components/dashboard/user.de/user-edit-form.tsx +++ b/002_source/cms/src/components/dashboard/user.de/user-edit-form.tsx @@ -32,6 +32,7 @@ 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 { pb } from '@/lib/pb'; @@ -40,7 +41,6 @@ import FormLoading from '@/components/loading'; // import ErrorDisplay from '../../error'; import ErrorDisplay from '../error'; -import isDevelopment from '@/lib/check-is-development'; // TODO: review this const schema = zod.object({ diff --git a/002_source/cms/src/components/dashboard/user_meta/type.d.tsx b/002_source/cms/src/components/dashboard/user_meta/type.d.tsx index 6f61ac5..231568a 100644 --- a/002_source/cms/src/components/dashboard/user_meta/type.d.tsx +++ b/002_source/cms/src/components/dashboard/user_meta/type.d.tsx @@ -1,8 +1,55 @@ 'use client'; +import type { BillingAddress } from '@/db/billingAddress/type'; + // RULES: sorting direction for teacher lists export type SortDir = 'asc' | 'desc'; +// obsoleted +// export interface BillingAddress { +// city: string; +// country: string; +// line1: string; +// line2: string; +// state: string; +// zipCode: string; +// // +// id: string; +// collectionId: string; +// collectionName: string; +// updated: string; +// created: string; +// } + +export interface DBUserMeta { + name: string; + // + // NOTE: obslete "avatar" and use "avatar_file" + avatar?: string; + avatar_file?: string; + // + email: string; + phone: string; + quota: number; + company: string; + // + // billingAddress: BillingAddress[] | []; + expand: { billingAddress?: BillingAddress[] }; + + // status is obsoleted, replace by state + status: 'pending' | 'active' | 'blocked'; + state: 'pending' | 'active' | 'blocked'; + // + timezone: string; + language: string; + currency: string; + // + id: string; + created: string; + updated?: string; + collectionId: string; +} + // RULES: core teacher data structure export interface UserMeta { name: string; @@ -14,10 +61,18 @@ export interface UserMeta { email: string; phone?: string; quota: number; + company?: string; + // + billingAddress: BillingAddress | Record; // status is obsoleted, replace by state status: 'pending' | 'active' | 'blocked'; state: 'pending' | 'active' | 'blocked'; + // + timezone: string; + language: string; + currency: string; + // id: string; createdAt: Date; diff --git a/002_source/cms/src/components/dashboard/user_meta/user-meta-edit-form.tsx b/002_source/cms/src/components/dashboard/user_meta/user-meta-edit-form.tsx index daba2ce..aee8a3a 100644 --- a/002_source/cms/src/components/dashboard/user_meta/user-meta-edit-form.tsx +++ b/002_source/cms/src/components/dashboard/user_meta/user-meta-edit-form.tsx @@ -1,10 +1,15 @@ 'use client'; +// src/components/dashboard/user_meta/user-meta-edit-form.tsx +// import * as React from 'react'; import RouterLink from 'next/link'; import { useParams, useRouter } from 'next/navigation'; // -import { COL_TEACHERS, COL_USER_METAS } from '@/constants'; +import { COL_CUSTOMERS, COL_USER_METAS } from '@/constants'; +import { UpdateBillingAddressById } from '@/db/billingAddress/UpdateById'; +import { getUserMetaById } from '@/db/UserMetas/GetById'; +import { UpdateUserMetaById } from '@/db/UserMetas/UpdateById'; import { zodResolver } from '@hookform/resolvers/zod'; import { LoadingButton } from '@mui/lab'; // @@ -32,6 +37,7 @@ 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 { pb } from '@/lib/pb'; @@ -40,7 +46,6 @@ import FormLoading from '@/components/loading'; // import ErrorDisplay from '../../error'; import ErrorDisplay from '../error'; -import isDevelopment from '@/lib/check-is-development'; // TODO: review this const schema = zod.object({ @@ -89,7 +94,7 @@ export function UserMetaEditForm(): React.JSX.Element { const router = useRouter(); const { t } = useTranslation(['lp_categories']); - const { id: teacherId } = useParams<{ id: string }>(); + const { id: userMetaId } = useParams<{ id: string }>(); // const [isUpdating, setIsUpdating] = React.useState(false); const [showLoading, setShowLoading] = React.useState(false); @@ -123,7 +128,7 @@ export function UserMetaEditForm(): React.JSX.Element { }; try { - await pb.collection(COL_USER_METAS).update(teacherId, updateData); + await pb.collection(COL_USER_METAS).update(userMetaId, updateData); toast.success('Teacher updated successfully'); router.push(paths.dashboard.teachers.list); } catch (error) { @@ -133,7 +138,7 @@ export function UserMetaEditForm(): React.JSX.Element { setIsUpdating(false); } }, - [teacherId, router] + [userMetaId, router] ); const avatarInputRef = React.useRef(null); @@ -186,9 +191,9 @@ export function UserMetaEditForm(): React.JSX.Element { ); React.useEffect(() => { - void loadExistingData(teacherId); + void loadExistingData(userMetaId); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [teacherId]); + }, [userMetaId]); if (showLoading) return ; if (showError.show)