From cfd513d64f2619bf8d9659c9a79751d947e1db32 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:45:32 +0530 Subject: [PATCH 01/20] feat: set address type modal UI --- public/static/locales/en/profile.json | 4 +- .../AddressManagment/AddressForm.tsx | 8 +- .../AddressManagement.module.scss | 77 +++++++++++++------ .../AddressManagment/AddressTypeChange.tsx | 57 ++++++++++++++ .../microComponents/SingleAddress.tsx | 37 ++++++--- 5 files changed, 144 insertions(+), 39 deletions(-) create mode 100644 src/features/user/Settings/EditProfile/AddressManagment/AddressTypeChange.tsx diff --git a/public/static/locales/en/profile.json b/public/static/locales/en/profile.json index fda72e7a7..0b102b933 100644 --- a/public/static/locales/en/profile.json +++ b/public/static/locales/en/profile.json @@ -150,7 +150,9 @@ "formType": { "add": "Add Address", "edit": "Edit Address" - } + }, + "addressConfirmationMessage": "Are you sure you want to set this address as your {addressType} Address? This will replace your current {addressType} Address.", + "confirm": "Confirm" } } } diff --git a/src/features/user/Settings/EditProfile/AddressManagment/AddressForm.tsx b/src/features/user/Settings/EditProfile/AddressManagment/AddressForm.tsx index 3d64b93cb..2db1753b0 100644 --- a/src/features/user/Settings/EditProfile/AddressManagment/AddressForm.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagment/AddressForm.tsx @@ -228,7 +228,9 @@ const AddressForm = ({ }; return (
+ {tProfile('addressConfirmationMessage', { + addressType: + addressAction === ADDRESS_ACTIONS.SET_BILLING + ? 'Billing' + : 'Primary', + })} +
+{formattedAddress}
+{tProfile('addressConfirmationMessage', { - addressType: - addressAction === ADDRESS_ACTIONS.SET_BILLING - ? 'Billing' - : 'Primary', + addressType: isBillingAddress ? 'Billing' : 'Primary', })}
{formattedAddress}
@@ -47,7 +49,9 @@ const AddressTypeChange = ({ text={tProfile('confirm')} elementType="button" variant="primary" - onClick={changeAddressType} + onClick={() => + editAddress(null, isBillingAddress ? 'mailing' : 'primary') + } />{tProfile('deleteAddressConfirmationMessage')}
+{tProfile('addressConfirmationMessage', { - addressType: isBillingAddress ? 'Billing' : 'Primary', + addressType: isSetBillingAction + ? ADDRESS_TYPE.MAILING + : ADDRESS_TYPE.PRIMARY, + billingAddress: + isSetBillingAction && billingAddress ? ADDRESS_TYPE.MAILING : '', + primaryAddress: + isSetPrimaryAction && primaryAddress ? ADDRESS_TYPE.PRIMARY : '', })}
-{formattedAddress}
+ {billingAddress && isSetBillingAction && ( +{billingAddress}
+ )} + {primaryAddress && isSetPrimaryAction && ( +{primaryAddress}
+ )}{billingAddress}
)} - {primaryAddress && isSetPrimaryAction && ( + {isPrimaryAddressAlreadyPresent && ({primaryAddress}
)}{tProfile('deleteAddressConfirmationMessage')}
-{tProfile('addressConfirmationMessage', { addressType: isSetBillingAction @@ -119,26 +115,33 @@ const AddressTypeChangeModal = ({ {isPrimaryAddressAlreadyPresent && (
{primaryFormattedAddress}
)} -{tProfile('addressConfirmationMessage', { - addressType: isSetBillingAction - ? ADDRESS_TYPE.MAILING - : ADDRESS_TYPE.PRIMARY, - billingAddress: isBillingAddressAlreadyPresent - ? ADDRESS_TYPE.MAILING - : '', - primaryAddress: isPrimaryAddressAlreadyPresent - ? ADDRESS_TYPE.PRIMARY - : '', + addressType: type, + isAddressSet: !!address, })}
- {isBillingAddressAlreadyPresent && ( -{billingFormattedAddress}
- )} - {isPrimaryAddressAlreadyPresent && ( -{primaryFormattedAddress}
- )} - + {formattedAddress &&{formattedAddress}
} {!isUploadingData ? ({tProfile('addressConfirmationMessage', { - addressType: type, - isAddressSet: !!address, + addressType: mode, + isAddressSet: !!userAddress, })}
- {formattedAddress &&{formattedAddress}
} + {userAddress && ( +{userAddress?.address}
+ {userAddress?.address2 &&{userAddress?.address2}
} +{formattedAddress}
+ +{userAddress?.address}
- {userAddress?.address2 &&{userAddress?.address2}
} -{formattedAddress}
- +{address}
- {address2 &&{address2}
} -{formattedAddress}
- +{address}
+ {address2 &&{address2}
} +{formattedAddress}
+ + ); +}; +export default FormattedAddressBlock; From ea0228b1017d17773d1183adeb486a927ca185ea Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:33:44 +0530 Subject: [PATCH 11/20] refactor: rename variable, and wrap the fetchUserAddresses function in useCallback --- .../AddressManagment/AddressDeleteModal.tsx | 8 ++++---- .../AddressManagment/AddressTypeConfirmationModal.tsx | 10 +++++----- .../Settings/EditProfile/AddressManagment/index.tsx | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/features/user/Settings/EditProfile/AddressManagment/AddressDeleteModal.tsx b/src/features/user/Settings/EditProfile/AddressManagment/AddressDeleteModal.tsx index 3229463b8..1443dd682 100644 --- a/src/features/user/Settings/EditProfile/AddressManagment/AddressDeleteModal.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagment/AddressDeleteModal.tsx @@ -28,12 +28,12 @@ const AddressDeleteModal = ({ const { contextLoaded, user, token, logoutUser } = useUserProps(); const { tenantConfig } = useTenant(); const { setErrors } = useContext(ErrorHandlingContext); - const [isUploadingData, setIsUploadingData] = useState(false); + const [isLoading, setIsLoading] = useState(false); const deleteAddress = async () => { if (!contextLoaded || !user) return; try { - setIsUploadingData(true); + setIsLoading(true); await deleteAuthenticatedRequest( tenantConfig.id, `/app/addresses/${addressId}`, @@ -45,14 +45,14 @@ const AddressDeleteModal = ({ setErrors(handleError(error as APIError)); } finally { setIsModalOpen(false); - setIsUploadingData(false); + setIsLoading(false); } }; return ({tProfile('deleteAddressConfirmationMessage')}
- {!isUploadingData ? ( + {!isLoading ? ({tProfile('addressConfirmationMessage', { - addressType: mode, + addressType, isAddressSet: !!userAddress, })}
@@ -83,7 +83,7 @@ const AddressTypeConfirmationModal = ({ text={tProfile('confirm')} elementType="button" variant="primary" - onClick={() => updateAddress(mode)} + onClick={() => updateAddress(addressType)} />{tProfile('deleteAddressConfirmationMessage')}
{!isLoading ? ({tProfile('addressConfirmationMessage', { addressType, diff --git a/src/features/user/Settings/EditProfile/AddressManagment/EditAddressForm.tsx b/src/features/user/Settings/EditProfile/AddressManagment/EditAddressForm.tsx index 4bf7ed9ad..7371908f3 100644 --- a/src/features/user/Settings/EditProfile/AddressManagment/EditAddressForm.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagment/EditAddressForm.tsx @@ -153,7 +153,7 @@ const EditAddressForm = ({ return (
{tProfile('deleteAddressConfirmationMessage')}
{!isLoading ? ( diff --git a/src/features/user/Settings/EditProfile/AddressManagment/UpdateAddressType.tsx b/src/features/user/Settings/EditProfile/AddressManagment/UpdateAddressType.tsx index 1d577309e..4db9f82dc 100644 --- a/src/features/user/Settings/EditProfile/AddressManagment/UpdateAddressType.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagment/UpdateAddressType.tsx @@ -66,7 +66,7 @@ const UpdateAddressType = ({ setAddressAction(null); }; return ( -{tProfile('addressConfirmationMessage', { - addressType, + addressType: tProfile(`addressType.${addressType}`), isAddressSet: !!userAddress, })}
From ef5ce97789fd951e34e7646e63a0f6de03d49866 Mon Sep 17 00:00:00 2001 From: sunilsabatp <101264823+sunilsabatp@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:38:19 +0530 Subject: [PATCH 18/20] refactor: rename tProfile to tAddressManagement --- .../EditProfile/AddressManagment/DeleteAddress.tsx | 8 ++++---- .../EditProfile/AddressManagment/UpdateAddressType.tsx | 10 +++++----- .../AddressManagment/microComponents/AddressForm.tsx | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/features/user/Settings/EditProfile/AddressManagment/DeleteAddress.tsx b/src/features/user/Settings/EditProfile/AddressManagment/DeleteAddress.tsx index 55c55861c..884daeaee 100644 --- a/src/features/user/Settings/EditProfile/AddressManagment/DeleteAddress.tsx +++ b/src/features/user/Settings/EditProfile/AddressManagment/DeleteAddress.tsx @@ -26,7 +26,7 @@ const DeleteAddress = ({ updateUserAddresses, setAddressAction, }: Props) => { - const tProfile = useTranslations('Profile.addressManagement'); + const tAddressManagement = useTranslations('Profile.addressManagement'); const tCommon = useTranslations('Common'); const { contextLoaded, user, token, logoutUser } = useUserProps(); const { tenantConfig } = useTenant(); @@ -58,8 +58,8 @@ const DeleteAddress = ({ }; return ({tProfile('deleteAddressConfirmationMessage')}
+{tAddressManagement('deleteAddressConfirmationMessage')}
{!isLoading ? (- {tProfile('addressConfirmationMessage', { - addressType: tProfile(`addressType.${addressType}`), + {tAddressManagement('addressConfirmationMessage', { + addressType: tAddressManagement(`addressType.${addressType}`), isAddressSet: !!userAddress, })}
@@ -90,7 +90,7 @@ const UpdateAddressType = ({ onClick={handleCancel} />- {tAddressManagement('addressConfirmationMessage', { + {tAddressManagement('setAddressConfirmation', { addressType: tAddressManagement(`addressType.${addressType}`), - isAddressSet: !!userAddress, })} + {userAddress && + tAddressManagement('replaceAddressWarning', { + addressType: tAddressManagement(`addressType.${addressType}`), + })}
{userAddress !== undefined && (