diff --git a/src/app/api/customer-dependant/[id]/route.ts b/src/app/api/customer-dependant/[id]/route.ts index ae76621..4028154 100644 --- a/src/app/api/customer-dependant/[id]/route.ts +++ b/src/app/api/customer-dependant/[id]/route.ts @@ -104,8 +104,8 @@ export async function PUT( ...db.data!.customerDependants[dependantIndex], firstNameEn: body.dependantInfo.firstNameEn, lastNameEn: body.dependantInfo.lastNameEn, - originAdd1: body.dependantInfo.originAdd1, - localAdd1: body.dependantInfo.localAdd1, + originAdd1: body.dependantContact.originAdd1, + localAdd1: body.dependantContact.localAdd1, email: body.dependantContact.email, mobile: body.dependantContact.mobile, }; diff --git a/src/app/api/customer/[id]/route.ts b/src/app/api/customer/[id]/route.ts index 6516e7d..b88f7ca 100644 --- a/src/app/api/customer/[id]/route.ts +++ b/src/app/api/customer/[id]/route.ts @@ -116,10 +116,14 @@ export async function PUT( ...db.data!.customers[customerIndex], firstNameEn: body.customerInfo.firstNameEn, lastNameEn: body.customerInfo.lastNameEn, - originAdd1: body.customerInfo.originAdd1, - localAdd1: body.customerInfo.localAdd1, + firstNameJp: body.customerInfo.firstNameJp, + lastNameJp: body.customerInfo.lastNameJp, + firstNameJpKana: body.customerInfo.firstNameJpKana, + lastNameJpKana: body.customerInfo.lastNameJpKana, email: body.customerContact.email, mobile: body.customerContact.mobile, + originAdd1: body.customerContact.originAdd1, + localAdd1: body.customerContact.localAdd1, }; db.data!.customers[customerIndex] = updatedCustomer; @@ -140,10 +144,14 @@ export async function PUT( custId: customerId, firstNameEn: dependant.dependantInfo.firstNameEn, lastNameEn: dependant.dependantInfo.lastNameEn, - originAdd1: dependant.dependantInfo.originAdd1, - localAdd1: dependant.dependantInfo.localAdd1, + firstNameJp: dependant.dependantInfo.firstNameJp, + lastNameJp: dependant.dependantInfo.lastNameJp, + firstNameJpKana: dependant.dependantInfo.firstNameJpKana, + lastNameJpKana: dependant.dependantInfo.lastNameJpKana, email: dependant.dependantContact.email, mobile: dependant.dependantContact.mobile, + originAdd1: dependant.dependantContact.originAdd1, + localAdd1: dependant.dependantContact.localAdd1, }; 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 28ef9d5..b93da9f 100644 --- a/src/app/api/customer/route.ts +++ b/src/app/api/customer/route.ts @@ -19,10 +19,14 @@ export async function POST(request: NextRequest) { id: getNextId(db.data!.customers), firstNameEn: validatedData.customerInfo.firstNameEn, lastNameEn: validatedData.customerInfo.lastNameEn, + firstNameJp: validatedData.customerInfo.firstNameJp, + lastNameJp: validatedData.customerInfo.lastNameJp, + firstNameJpKana: validatedData.customerInfo.firstNameJpKana, + lastNameJpKana: validatedData.customerInfo.lastNameJpKana, email: validatedData.customerContact.email, mobile: validatedData.customerContact.mobile, - originAdd1: validatedData.customerInfo.originAdd1, - localAdd1: validatedData.customerInfo.localAdd1, + originAdd1: validatedData.customerContact.originAdd1, + localAdd1: validatedData.customerContact.localAdd1, }; // Add customer to database @@ -38,10 +42,14 @@ export async function POST(request: NextRequest) { custId: newCustomer.id, firstNameEn: dependant.dependantInfo.firstNameEn, lastNameEn: dependant.dependantInfo.lastNameEn, + firstNameJp: dependant.dependantInfo.firstNameJp, + lastNameJp: dependant.dependantInfo.lastNameJp, + firstNameJpKana: dependant.dependantInfo.firstNameJpKana, + lastNameJpKana: dependant.dependantInfo.lastNameJpKana, email: dependant.dependantContact.email, mobile: dependant.dependantContact.mobile, - originAdd1: dependant.dependantInfo.originAdd1, - localAdd1: dependant.dependantInfo.localAdd1, + originAdd1: dependant.dependantContact.originAdd1, + localAdd1: dependant.dependantContact.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 b2d9814..e7712f9 100644 --- a/src/app/modules/customer/[id]/page.tsx +++ b/src/app/modules/customer/[id]/page.tsx @@ -41,12 +41,16 @@ export default function CustomerEditPage() { customerInfo: { firstNameEn: "", lastNameEn: "", - originAdd1: "", - localAdd1: "", + firstNameJp: "", + lastNameJp: "", + firstNameJpKana: "", + lastNameJpKana: "", }, customerContact: { email: "", mobile: "", + originAdd1: "", + localAdd1: "", }, customerDependants: [], }, @@ -59,12 +63,16 @@ export default function CustomerEditPage() { dependantInfo: { firstNameEn: "", lastNameEn: "", - originAdd1: "", - localAdd1: "", + firstNameJp: "", + lastNameJp: "", + firstNameJpKana: "", + lastNameJpKana: "", }, dependantContact: { email: "", mobile: "", + originAdd1: "", + localAdd1: "", }, }, }); @@ -84,16 +92,28 @@ export default function CustomerEditPage() { // Populate form with customer data form.setValue("customerInfo.firstNameEn", customerData.firstNameEn); form.setValue("customerInfo.lastNameEn", customerData.lastNameEn); - form.setValue("customerInfo.originAdd1", customerData.originAdd1); - form.setValue("customerInfo.localAdd1", customerData.localAdd1); + form.setValue("customerInfo.firstNameJp", customerData.firstNameJp); + form.setValue("customerInfo.lastNameJp", customerData.lastNameJp); + form.setValue("customerInfo.firstNameJpKana", customerData.firstNameJpKana); + form.setValue("customerInfo.lastNameJpKana", customerData.lastNameJpKana); + form.setValue("customerInfo.firstNameJp", customerData.firstNameJp); + form.setValue("customerInfo.lastNameJp", customerData.lastNameJp); + form.setValue("customerInfo.firstNameJpKana", customerData.firstNameJpKana); + form.setValue("customerInfo.lastNameJpKana", customerData.lastNameJpKana); form.setValue("customerContact.email", customerData.email); form.setValue("customerContact.mobile", customerData.mobile); + form.setValue("customerContact.originAdd1", customerData.originAdd1); + form.setValue("customerContact.localAdd1", customerData.localAdd1); // Convert dependants to the expected format const dependants: CustomerDependantForm[] = customerData.dependants.map((dep: { id: number; firstNameEn: string; lastNameEn: string; + firstNameJp: string; + lastNameJp: string; + firstNameJpKana: string; + lastNameJpKana: string; email: string; mobile: string; originAdd1: string; @@ -103,12 +123,16 @@ export default function CustomerEditPage() { dependantInfo: { firstNameEn: dep.firstNameEn, lastNameEn: dep.lastNameEn, - originAdd1: dep.originAdd1, - localAdd1: dep.localAdd1, + firstNameJp: dep.firstNameJp, + lastNameJp: dep.lastNameJp, + firstNameJpKana: dep.firstNameJpKana, + lastNameJpKana: dep.lastNameJpKana, }, dependantContact: { email: dep.email, mobile: dep.mobile, + originAdd1: dep.originAdd1, + localAdd1: dep.localAdd1, }, })); @@ -173,12 +197,20 @@ export default function CustomerEditPage() { dep.id === editingDependant.id ? { ...dep, - 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, + firstNameJp: data.dependantInfo.firstNameJp, + lastNameJp: data.dependantInfo.lastNameJp, + firstNameJpKana: data.dependantInfo.firstNameJpKana, + lastNameJpKana: data.dependantInfo.lastNameJpKana, + }, + dependantContact: { + email: data.dependantContact.email, + mobile: data.dependantContact.mobile, + originAdd1: data.dependantContact.originAdd1, + localAdd1: data.dependantContact.localAdd1, + }, } : dep ); @@ -191,12 +223,16 @@ export default function CustomerEditPage() { dependantInfo: { firstNameEn: data.dependantInfo.firstNameEn, lastNameEn: data.dependantInfo.lastNameEn, - originAdd1: data.dependantInfo.originAdd1, - localAdd1: data.dependantInfo.localAdd1, + firstNameJp: data.dependantInfo.firstNameJp, + lastNameJp: data.dependantInfo.lastNameJp, + firstNameJpKana: data.dependantInfo.firstNameJpKana, + lastNameJpKana: data.dependantInfo.lastNameJpKana, }, dependantContact: { email: data.dependantContact.email, mobile: data.dependantContact.mobile, + originAdd1: data.dependantContact.originAdd1, + localAdd1: data.dependantContact.localAdd1, }, }; @@ -220,10 +256,14 @@ export default function CustomerEditPage() { setEditingDependant(dependant); 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("dependantInfo.firstNameJp", dependant.dependantInfo.firstNameJp); + dependantForm.setValue("dependantInfo.lastNameJp", dependant.dependantInfo.lastNameJp); + dependantForm.setValue("dependantInfo.firstNameJpKana", dependant.dependantInfo.firstNameJpKana); + dependantForm.setValue("dependantInfo.lastNameJpKana", dependant.dependantInfo.lastNameJpKana); dependantForm.setValue("dependantContact.email", dependant.dependantContact.email); dependantForm.setValue("dependantContact.mobile", dependant.dependantContact.mobile); + dependantForm.setValue("dependantContact.originAdd1", dependant.dependantContact.originAdd1); + dependantForm.setValue("dependantContact.localAdd1", dependant.dependantContact.localAdd1); setDependantDialogOpen(true); setDependantDialogTab("info"); }; @@ -252,8 +292,6 @@ export default function CustomerEditPage() { const isValid = await form.trigger([ "customerInfo.firstNameEn", "customerInfo.lastNameEn", - "customerInfo.originAdd1", - "customerInfo.localAdd1", ]); if (isValid) { setActiveTab("contact"); @@ -262,7 +300,12 @@ export default function CustomerEditPage() { } } else if (activeTab === "contact") { // Validate customer contact fields before proceeding - const isValid = await form.trigger(["customerContact.email", "customerContact.mobile"]); + const isValid = await form.trigger([ + "customerContact.email", + "customerContact.mobile", + "customerContact.originAdd1", + "customerContact.localAdd1" + ]); if (isValid) { setActiveTab("dependants"); } else { @@ -287,19 +330,19 @@ export default function CustomerEditPage() { return ( values.customerInfo?.firstNameEn?.trim() !== "" && values.customerInfo?.lastNameEn?.trim() !== "" && - values.customerInfo?.originAdd1?.trim() !== "" && - values.customerInfo?.localAdd1?.trim() !== "" && !errors.customerInfo?.firstNameEn && - !errors.customerInfo?.lastNameEn && - !errors.customerInfo?.originAdd1 && - !errors.customerInfo?.localAdd1 + !errors.customerInfo?.lastNameEn ); } else if (tabName === "contact") { return ( values.customerContact?.email?.trim() !== "" && values.customerContact?.mobile?.trim() !== "" && + values.customerContact?.originAdd1?.trim() !== "" && + values.customerContact?.localAdd1?.trim() !== "" && !errors.customerContact?.email && - !errors.customerContact?.mobile + !errors.customerContact?.mobile && + !errors.customerContact?.originAdd1 && + !errors.customerContact?.localAdd1 ); } return true; @@ -395,16 +438,14 @@ export default function CustomerEditPage() { )} /> - -
( - Origin Address + First Name (Japanese) - + @@ -412,12 +453,38 @@ export default function CustomerEditPage() { /> ( - Local Address + Last Name (Japanese) - + + + + + )} + /> + ( + + First Name (Japanese Kana) + + + + + + )} + /> + ( + + Last Name (Japanese Kana) + + @@ -458,6 +525,34 @@ export default function CustomerEditPage() { )} />
+
+ ( + + Origin Address + + + + + + )} + /> + ( + + Local Address + + + + + + )} + /> +
- + {editingDependant ? "Edit Dependant" : "Add New Dependant"}
- + Dependant Info @@ -518,16 +613,14 @@ export default function CustomerEditPage() { )} /> -
-
( - Origin Address + First Name (Japanese) - + @@ -535,12 +628,38 @@ export default function CustomerEditPage() { /> ( - Local Address + Last Name (Japanese) - + + + + + )} + /> + ( + + First Name (Japanese Kana) + + + + + + )} + /> + ( + + Last Name (Japanese Kana) + + @@ -554,8 +673,10 @@ export default function CustomerEditPage() { const isValid = await dependantForm.trigger([ "dependantInfo.firstNameEn", "dependantInfo.lastNameEn", - "dependantInfo.originAdd1", - "dependantInfo.localAdd1" + "dependantInfo.firstNameJp", + "dependantInfo.lastNameJp", + "dependantInfo.firstNameJpKana", + "dependantInfo.lastNameJpKana" ]); if (isValid) { setDependantDialogTab("contact"); @@ -598,6 +719,34 @@ export default function CustomerEditPage() { )} />
+
+ ( + + Origin Address + + + + + + )} + /> + ( + + Local Address + + + + + + )} + /> +
-
( - Origin Address + First Name (Japanese) - + @@ -293,12 +310,38 @@ export default function CustomerAddPage() { /> ( - Local Address + Last Name (Japanese) - + + + + + )} + /> + ( + + First Name (Japanese Kana) + + + + + + )} + /> + ( + + Last Name (Japanese Kana) + + @@ -342,6 +385,34 @@ export default function CustomerAddPage() { )} />
+
+ ( + + Origin Address + + + + + + )} + /> + ( + + Local Address + + + + + + )} + /> +
-
( - Origin Address + First Name (Japanese) - + @@ -420,12 +489,38 @@ export default function CustomerAddPage() { /> ( - Local Address + Last Name (Japanese) - + + + + + )} + /> + ( + + First Name (Japanese Kana) + + + + + + )} + /> + ( + + Last Name (Japanese Kana) + + @@ -439,8 +534,10 @@ export default function CustomerAddPage() { const isValid = await dependantForm.trigger([ "dependantInfo.firstNameEn", "dependantInfo.lastNameEn", - "dependantInfo.originAdd1", - "dependantInfo.localAdd1" + "dependantInfo.firstNameJp", + "dependantInfo.lastNameJp", + "dependantInfo.firstNameJpKana", + "dependantInfo.lastNameJpKana" ]); if (isValid) { setDependantDialogTab("contact"); @@ -483,6 +580,34 @@ export default function CustomerAddPage() { )} />
+
+ ( + + Origin Address + + + + + + )} + /> + ( + + Local Address + + + + + + )} + /> +