diff --git a/src/app/api/customer/[id]/route.ts b/src/app/api/customer/[id]/route.ts index 21554f5..6516e7d 100644 --- a/src/app/api/customer/[id]/route.ts +++ b/src/app/api/customer/[id]/route.ts @@ -138,12 +138,12 @@ export async function PUT( parseInt(dependant.id) : getNextId(db.data!.customerDependants), custId: customerId, - firstNameEn: dependant.firstNameEn, - lastNameEn: dependant.lastNameEn, - originAdd1: dependant.originAdd1, - localAdd1: dependant.localAdd1, - email: dependant.email, - mobile: dependant.mobile, + firstNameEn: dependant.dependantInfo.firstNameEn, + lastNameEn: dependant.dependantInfo.lastNameEn, + originAdd1: dependant.dependantInfo.originAdd1, + localAdd1: dependant.dependantInfo.localAdd1, + email: dependant.dependantContact.email, + mobile: dependant.dependantContact.mobile, }; newDependants.push(newDependant); db.data!.customerDependants.push(newDependant); diff --git a/src/app/api/customer/route.ts b/src/app/api/customer/route.ts index f892c3a..28ef9d5 100644 --- a/src/app/api/customer/route.ts +++ b/src/app/api/customer/route.ts @@ -36,12 +36,12 @@ export async function POST(request: NextRequest) { const newDependant: CustomerDependant = { id: getNextId(db.data!.customerDependants), custId: newCustomer.id, - firstNameEn: dependant.firstNameEn, - lastNameEn: dependant.lastNameEn, - email: dependant.email, - mobile: dependant.mobile, - originAdd1: dependant.originAdd1, - localAdd1: dependant.localAdd1, + firstNameEn: dependant.dependantInfo.firstNameEn, + lastNameEn: dependant.dependantInfo.lastNameEn, + email: dependant.dependantContact.email, + mobile: dependant.dependantContact.mobile, + originAdd1: dependant.dependantInfo.originAdd1, + localAdd1: dependant.dependantInfo.localAdd1, }; customerDependants.push(newDependant); db.data!.customerDependants.push(newDependant); diff --git a/src/app/modules/customer/[id]/page.tsx b/src/app/modules/customer/[id]/page.tsx index cbbb8f2..cc577cb 100644 --- a/src/app/modules/customer/[id]/page.tsx +++ b/src/app/modules/customer/[id]/page.tsx @@ -18,7 +18,6 @@ import { customerDependantFormSchema, type CustomerForm, type CustomerDependantForm, - type CustomerDependant, } from "@/schemas/customer.schema"; import axios from "axios"; import { Header } from "@/components/common/header"; @@ -33,7 +32,7 @@ export default function CustomerEditPage() { const [dependantDialogTab, setDependantDialogTab] = useState("info"); const [isLoading, setIsLoading] = useState(true); const [isSaving, setIsSaving] = useState(false); - const [editingDependant, setEditingDependant] = useState(null); + const [editingDependant, setEditingDependant] = useState(null); // Main form const form = useForm({ @@ -91,7 +90,7 @@ export default function CustomerEditPage() { form.setValue("customerContact.mobile", customerData.mobile); // Convert dependants to the expected format - const dependants: CustomerDependant[] = customerData.dependants.map((dep: { + const dependants: CustomerDependantForm[] = customerData.dependants.map((dep: { id: number; firstNameEn: string; lastNameEn: string; @@ -101,12 +100,16 @@ export default function CustomerEditPage() { localAdd1: string; }) => ({ id: dep.id, - firstNameEn: dep.firstNameEn, - lastNameEn: dep.lastNameEn, - email: dep.email, - mobile: dep.mobile, - originAdd1: dep.originAdd1, - localAdd1: dep.localAdd1, + dependantInfo: { + firstNameEn: dep.firstNameEn, + lastNameEn: dep.lastNameEn, + originAdd1: dep.originAdd1, + localAdd1: dep.localAdd1, + }, + dependantContact: { + email: dep.email, + mobile: dep.mobile, + }, })); form.setValue("customerDependants", dependants); @@ -183,14 +186,18 @@ export default function CustomerEditPage() { toast.success("Dependant updated successfully!"); } else { // Add new dependant - just add to the table, don't submit parent form - const newDependant: CustomerDependant = { + const newDependant: CustomerDependantForm = { id: Date.now(), - firstNameEn: data.dependantInfo.firstNameEn, - lastNameEn: data.dependantInfo.lastNameEn, - originAdd1: data.dependantInfo.originAdd1, - localAdd1: data.dependantInfo.localAdd1, - email: data.dependantContact.email, - mobile: data.dependantContact.mobile, + dependantInfo: { + firstNameEn: data.dependantInfo.firstNameEn, + lastNameEn: data.dependantInfo.lastNameEn, + originAdd1: data.dependantInfo.originAdd1, + localAdd1: data.dependantInfo.localAdd1, + }, + dependantContact: { + email: data.dependantContact.email, + mobile: data.dependantContact.mobile, + }, }; // Add new row to dependant table without submitting parent form @@ -209,14 +216,14 @@ export default function CustomerEditPage() { } }; - const handleEditDependant = (dependant: CustomerDependant) => { + const handleEditDependant = (dependant: CustomerDependantForm) => { setEditingDependant(dependant); - dependantForm.setValue("dependantInfo.firstNameEn", dependant.firstNameEn); - dependantForm.setValue("dependantInfo.lastNameEn", dependant.lastNameEn); - dependantForm.setValue("dependantInfo.originAdd1", dependant.originAdd1); - dependantForm.setValue("dependantInfo.localAdd1", dependant.localAdd1); - dependantForm.setValue("dependantContact.email", dependant.email); - dependantForm.setValue("dependantContact.mobile", dependant.mobile); + dependantForm.setValue("dependantInfo.firstNameEn", dependant.dependantInfo.firstNameEn); + dependantForm.setValue("dependantInfo.lastNameEn", dependant.dependantInfo.lastNameEn); + dependantForm.setValue("dependantInfo.originAdd1", dependant.dependantInfo.originAdd1); + dependantForm.setValue("dependantInfo.localAdd1", dependant.dependantInfo.localAdd1); + dependantForm.setValue("dependantContact.email", dependant.dependantContact.email); + dependantForm.setValue("dependantContact.mobile", dependant.dependantContact.mobile); setDependantDialogOpen(true); setDependantDialogTab("info"); }; @@ -575,12 +582,12 @@ export default function CustomerEditPage() { {watchedDependants.map((dependant) => ( - {dependant.firstNameEn} {dependant.lastNameEn} + {dependant.dependantInfo.firstNameEn} {dependant.dependantInfo.lastNameEn} - {dependant.email} - {dependant.mobile} - {dependant.originAdd1} - {dependant.localAdd1} + {dependant.dependantContact.email} + {dependant.dependantContact.mobile} + {dependant.dependantInfo.originAdd1} + {dependant.dependantInfo.localAdd1}
- Documentation + Cosmos Plan Prototype v1.0.0
diff --git a/src/components/users/user-columns.tsx b/src/components/users/user-columns.tsx index 1f505f1..3354aef 100644 --- a/src/components/users/user-columns.tsx +++ b/src/components/users/user-columns.tsx @@ -1,5 +1,5 @@ import { Button } from "@/components/ui/button"; -import { ShieldCheck } from "lucide-react"; +import { Key } from "lucide-react"; export interface User { id: number; @@ -48,7 +48,7 @@ export function createUserColumns({ onEdit, onDelete, onPermissions }: {
{onPermissions && ( )} diff --git a/src/database/db.json b/src/database/db.json index efb59d9..4848bf9 100644 --- a/src/database/db.json +++ b/src/database/db.json @@ -1,5 +1,24 @@ { - "customers": [], + "customers": [ + { + "id": 1, + "firstNameEn": "Đỗ", + "lastNameEn": "Tùng", + "email": "dothanhtung196@gmail.com", + "mobile": "0987417491", + "originAdd1": "1231231231", + "localAdd1": "sdfgsdfg" + }, + { + "id": 2, + "firstNameEn": "Đỗ", + "lastNameEn": "Tùng", + "email": "dothanhtung196@gmail.com", + "mobile": "0987417491", + "originAdd1": "1231231231", + "localAdd1": "sdfgsdfg" + } + ], "users": [ { "id": 1, @@ -494,5 +513,36 @@ "isActive": true } ], - "customerDependants": [] + "customerDependants": [ + { + "id": 2, + "custId": 2, + "firstNameEn": "Đỗ", + "lastNameEn": "Tùng", + "email": "dothanhtung196@gmail.com", + "mobile": "0987417491", + "originAdd1": "1231231231", + "localAdd1": "sdfgsdfg" + }, + { + "id": 1, + "custId": 1, + "firstNameEn": "Đỗ", + "lastNameEn": "Tùng", + "originAdd1": "1231231231", + "localAdd1": "sdfgsdfg", + "email": "dothanhtung196@gmail.com", + "mobile": "0987417491" + }, + { + "id": 1751854039116, + "custId": 1, + "firstNameEn": "Đỗ", + "lastNameEn": "Thanh Tùng", + "originAdd1": "123", + "localAdd1": "111", + "email": "dothanhtung196@gmail.com", + "mobile": "0987417491" + } + ] } \ No newline at end of file diff --git a/src/schemas/customer.schema.ts b/src/schemas/customer.schema.ts index 1862e67..a3b6675 100644 --- a/src/schemas/customer.schema.ts +++ b/src/schemas/customer.schema.ts @@ -24,29 +24,17 @@ export const customerDependantContactSchema = z.object({ mobile: z.string().min(1, "Mobile number is required"), }); -export const customerDependantSchema = z.object({ +export const customerDependantFormSchema = z.object({ id: z.number().optional(), - firstNameEn: z.string(), - lastNameEn: z.string(), - email: z.string(), - mobile: z.string(), - originAdd1: z.string(), - localAdd1: z.string(), + dependantInfo: customerDependantInfoSchema, + dependantContact: customerDependantContactSchema, }); export const customerFormSchema = z.object({ customerInfo: customerInfoSchema, customerContact: customerContactSchema, - customerDependants: z.array(customerDependantSchema), + customerDependants: z.array(customerDependantFormSchema), }); -export const customerDependantFormSchema = z.object({ - dependantInfo: customerDependantInfoSchema, - dependantContact: customerDependantContactSchema, -}); - -export type CustomerInfo = z.infer; -export type CustomerContact = z.infer; -export type CustomerDependant = z.infer; export type CustomerForm = z.infer; export type CustomerDependantForm = z.infer;