From f1c88b601776e16114a99d0b3d515340af1820b0 Mon Sep 17 00:00:00 2001 From: barsa Date: Mon, 15 Dec 2025 17:29:48 +0900 Subject: [PATCH] Refactor PersonalInfoCard and useProfileData for improved user profile management - Updated type definitions in PersonalInfoCard to use UserProfile instead of ProfileDisplayData, enhancing clarity. - Simplified onChange function to restrict fields to "email" and "phonenumber". - Modified UI to indicate that first and last names cannot be changed from the portal. - Adjusted useProfileData hook to focus on email management, removing firstname and lastname from state and update logic, streamlining profile updates. --- .../account/components/PersonalInfoCard.tsx | 65 +++++++------------ .../features/account/hooks/useProfileData.ts | 9 +-- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/apps/portal/src/features/account/components/PersonalInfoCard.tsx b/apps/portal/src/features/account/components/PersonalInfoCard.tsx index 0e9135f1..24ffb446 100644 --- a/apps/portal/src/features/account/components/PersonalInfoCard.tsx +++ b/apps/portal/src/features/account/components/PersonalInfoCard.tsx @@ -2,15 +2,15 @@ import { SubCard } from "@/components/molecules/SubCard/SubCard"; import { UserIcon, PencilIcon, CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; -import type { ProfileDisplayData } from "@customer-portal/domain/customer"; +import type { UserProfile } from "@customer-portal/domain/customer"; interface PersonalInfoCardProps { - data: ProfileDisplayData; + data: UserProfile; isEditing: boolean; isSaving: boolean; onEdit: () => void; onCancel: () => void; - onChange: (field: keyof ProfileDisplayData, value: string) => void; + onChange: (field: "email" | "phonenumber", value: string) => void; onSave: () => void; } @@ -47,56 +47,41 @@ export function PersonalInfoCard({
- {isEditing ? ( - onChange("firstname", e.target.value)} - className="block w-full px-4 py-3 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors" - /> - ) : ( -

+

+

{data.firstname || Not provided}

- )} +

Name cannot be changed from the portal.

+
- {isEditing ? ( - onChange("lastname", e.target.value)} - className="block w-full px-4 py-3 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors" - /> - ) : ( -

+

+

{data.lastname || Not provided}

- )} +

Name cannot be changed from the portal.

+
-
-
-

{data.email}

- - - - - Verified - + {isEditing ? ( + onChange("email", e.target.value)} + className="block w-full px-4 py-3 border border-gray-300 rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 transition-colors" + /> + ) : ( +
+
+

{data.email}

+
+

Email can be updated from the portal.

-

- Email cannot be changed. Contact support to update your email. -

-
+ )}
diff --git a/apps/portal/src/features/account/hooks/useProfileData.ts b/apps/portal/src/features/account/hooks/useProfileData.ts index 735c7778..86572e47 100644 --- a/apps/portal/src/features/account/hooks/useProfileData.ts +++ b/apps/portal/src/features/account/hooks/useProfileData.ts @@ -20,8 +20,7 @@ export function useProfileData() { const [billingInfo, setBillingInfo] = useState<{ address: Address } | null>(null); const [formData, setFormData] = useState({ - firstname: user?.firstname || "", - lastname: user?.lastname || "", + email: user?.email || "", phonenumber: user?.phonenumber || "", }); @@ -70,8 +69,7 @@ export function useProfileData() { useEffect(() => { if (user) { setFormData({ - firstname: user.firstname || "", - lastname: user.lastname || "", + email: user.email || "", phonenumber: user.phonenumber || "", }); } @@ -81,8 +79,7 @@ export function useProfileData() { setIsSavingProfile(true); try { const updatedUser = await accountService.updateProfile({ - firstname: next.firstname, - lastname: next.lastname, + email: next.email, phonenumber: next.phonenumber, }); useAuthStore.setState(state => ({