Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address actions #2308

Merged
merged 27 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cfd513d
feat: set address type modal UI
sunilsabatp Nov 13, 2024
26c7cd3
feat: modify the edit address api to handle change address type
sunilsabatp Nov 14, 2024
7a29a2b
feat: component rename for better clarity
sunilsabatp Nov 14, 2024
dbdc164
feat: implement delete action & lift state management
sunilsabatp Nov 14, 2024
3dfea1f
refactor: refactor translations, optimize address selection, and defi…
sunilsabatp Nov 16, 2024
7ea7126
refactor singleAddress component: simplify address formatting, optimi…
sunilsabatp Nov 17, 2024
4be3b81
merge: merge base branch, shift setAddressType(primary,billing) moda…
sunilsabatp Nov 22, 2024
13311ac
refactor: shift address delete modal to the root component
sunilsabatp Nov 22, 2024
b16d705
refactor: simplify AddressTypeConfirmationModal component
sunilsabatp Nov 22, 2024
4a5f0e4
Merge branch 'address-mgmt/edit-address-form' into address-mgmt/addre…
sunilsabatp Nov 25, 2024
aaa5848
refactor: simplify address formatting logic,
sunilsabatp Nov 25, 2024
df3db69
feat: add FormattedAddressBlock component to display user address
sunilsabatp Nov 25, 2024
ea0228b
refactor: rename variable, and wrap the fetchUserAddresses function i…
sunilsabatp Nov 25, 2024
ccc8ce4
refactor: merge base branch, resolve conflicts
sunilsabatp Nov 25, 2024
eb6896e
Merge branch 'address-mgmt/edit-address-form' into address-mgmt/addre…
sunilsabatp Nov 26, 2024
64f7351
refactor: minor ui fixes
sunilsabatp Nov 26, 2024
6df7098
Merge branch 'address-mgmt/edit-address-form' into address-mgmt/addre…
sunilsabatp Nov 29, 2024
f69fd7b
Merge branch 'address-mgmt/edit-address-form' into address-mgmt/addre…
sunilsabatp Dec 2, 2024
9ff8673
refactor: remove unneeded files
sunilsabatp Dec 2, 2024
6523041
Merge branch 'feature/address-mgmt' into address-mgmt/address-actions
sunilsabatp Dec 2, 2024
3837dc7
refactor: rename component/function/props.
sunilsabatp Dec 4, 2024
6783400
"refactor: reset addressAction state when the modal is opened or closed
sunilsabatp Dec 4, 2024
075a427
refactor: minor code clean up
sunilsabatp Dec 4, 2024
9e154b6
refactor: simplify translation interpolation
sunilsabatp Dec 4, 2024
ef5ce97
refactor: rename tProfile to tAddressManagement
sunilsabatp Dec 4, 2024
035c34e
refactor: update address confirmation messages for clarity and structure
mohitb35 Dec 4, 2024
b64c57f
fix: corrects import path for ADDRESS_ACTIONS while creating AddressA…
mohitb35 Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion public/static/locales/en/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
},
"addressManagement": {
"addressManagementTitle": "Address",
"addressTags": {
"addressType": {
"primary": "Primary Address",
"mailing": "Billing Address"
},
Expand All @@ -147,6 +147,12 @@
"setAsPrimaryAddress": "Set as Primary Address",
"setAsBillingAddress": "Set as Billing Address"
},
"deleteAddress": "Delete Address",
"delete": "Delete",
"setAddressConfirmation": "Are you sure you want to set this address as your {addressType}?",
"replaceAddressWarning": " This will replace your current {addressType}.",
"deleteAddressConfirmationMessage": "Are you sure you want to delete this address? If you want to use it again, please add it as a new address.",
"confirm": "Confirm",
"addAddress": "Add New Address",
"addressForm": {
"addAddress": "Add Address",
Expand Down
2 changes: 1 addition & 1 deletion src/features/common/types/profile.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { User, UserPublicProfile } from '@planet-sdk/common';
import type { SetState } from './common';
import type { PublicUser } from './user';
import type { ADDRESS_ACTIONS } from '../../user/Settings/EditProfile/AddressManagment/microComponents/AddressActionMenu';
import type { ADDRESS_ACTIONS } from '../../../utils/addressManagement';

export interface UserFeaturesProps {
handleShare: () => void;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ExtendedCountryCode } from '../../../../common/types/country';
import type { SetState } from '../../../../common/types/common';
import type { Address, APIError } from '@planet-sdk/common';
import type { AddressAction } from '../../../../common/types/profile';

import { useState, useContext, useCallback } from 'react';
import { useTranslations } from 'next-intl';
Expand All @@ -25,6 +26,7 @@ export type FormData = {
interface Props {
setIsModalOpen: SetState<boolean>;
setUserAddresses: SetState<Address[]>;
setAddressAction: SetState<AddressAction | null>;
}

const defaultAddressDetail = {
Expand All @@ -35,7 +37,11 @@ const defaultAddressDetail = {
state: '',
};

const AddAddress = ({ setIsModalOpen, setUserAddresses }: Props) => {
const AddAddress = ({
setIsModalOpen,
setUserAddresses,
setAddressAction,
}: Props) => {
const tAddressManagement = useTranslations('Profile.addressManagement');
const { contextLoaded, user, token, logoutUser } = useUserProps();
const configCountry = getStoredConfig('country');
Expand Down Expand Up @@ -72,6 +78,7 @@ const AddAddress = ({ setIsModalOpen, setUserAddresses }: Props) => {
} finally {
setIsLoading(false);
setIsModalOpen(false);
setAddressAction(null);
}
},
[
Expand All @@ -98,6 +105,7 @@ const AddAddress = ({ setIsModalOpen, setUserAddresses }: Props) => {
label={tAddressManagement('addressForm.addAddress')}
defaultAddressDetail={defaultAddressDetail}
processFormData={addAddress}
setAddressAction={setAddressAction}
/>
</AddressFormLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,58 +94,87 @@
border-bottom: 1px solid rgba(189, 189, 189, 1);
}
// address action form

.header {
font-weight: 700;
font-size: $fontSixteen;
}
.addressFormLayout {
min-width: 565px;
display: flex;
flex-direction: column;
gap: 40px;
min-width: 565px;
background: rgba(255, 255, 255, 1);
border-radius: 16px;
padding: 20px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
h2 {
font-weight: 700;
font-size: $fontSixteen;
.addressForm {
display: flex;
flex-direction: column;
gap: 23px;
}
.buttonContainer {
display: flex;
justify-content: space-between;
gap: 8px;
margin-top: 25px;
button {
flex: 1 1;
}
}
}

.addressForm {
.addressActionContainer {
width: 468px;
display: flex;
gap: 10px;
flex-direction: column;
gap: 23px;
}

.formButtonContainer {
display: flex;
justify-content: space-between;
align-items: flex-end;
margin-top: 25px;
.addAddressButton,
.cancelButton {
min-width: 252px;
background: rgba(255, 255, 255, 1);
border-radius: 16px;
padding: 20px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
.address {
width: 100%;
background: rgba(242, 242, 242, 0.5);
border-radius: 8px;
font-size: $fontSmall;
font-weight: 400;
padding: 24px;
}
.buttonContainer {
display: flex;
gap: 20px;
margin-top: 34px;
button {
flex: 1 1;
}
}
}

@include xsPhoneView {
.addressFormLayout {
min-width: fit-content;
width: 95%;
.buttonContainer {
display: flex;
flex-direction: column;
button {
width: 100%;
}
}
}
.formButtonContainer {
display: flex;
flex-direction: column;
gap: 8px;
.addAddressButton,
.cancelButton {
width: 100%;
.addressActionContainer {
width: 95%;
.buttonContainer {
flex-direction: column;
gap: 8px;
}
}
}

// Form spinner

.addressMgmtSpinner {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { SetState } from '../../../../common/types/common';
import type { APIError } from '@planet-sdk/common';
import type { AddressAction } from '../../../../common/types/profile';

import { useContext, useState } from 'react';
import { useTranslations } from 'next-intl';
import { handleError } from '@planet-sdk/common';
import { CircularProgress } from '@mui/material';
import { ErrorHandlingContext } from '../../../../common/Layout/ErrorHandlingContext';
import { useTenant } from '../../../../common/Layout/TenantContext';
import { useUserProps } from '../../../../common/Layout/UserPropsContext';
import WebappButton from '../../../../common/WebappButton';
import styles from './AddressManagement.module.scss';
import { deleteAuthenticatedRequest } from '../../../../../utils/apiRequests/api';

interface Props {
setIsModalOpen: SetState<boolean>;
addressId: string | undefined;
updateUserAddresses: () => Promise<void>;
setAddressAction: SetState<AddressAction | null>;
}

const DeleteAddress = ({
setIsModalOpen,
addressId,
updateUserAddresses,
setAddressAction,
}: Props) => {
const tAddressManagement = useTranslations('Profile.addressManagement');
const tCommon = useTranslations('Common');
const { contextLoaded, user, token, logoutUser } = useUserProps();
const { tenantConfig } = useTenant();
const { setErrors } = useContext(ErrorHandlingContext);
const [isLoading, setIsLoading] = useState(false);

const deleteAddress = async () => {
if (!contextLoaded || !user || !token) return;
try {
setIsLoading(true);
await deleteAuthenticatedRequest(
tenantConfig.id,
`/app/addresses/${addressId}`,
token,
logoutUser
);
updateUserAddresses();
} catch (error) {
setErrors(handleError(error as APIError));
} finally {
setIsModalOpen(false);
setIsLoading(false);
setAddressAction(null);
}
};
const handleCancel = () => {
setIsModalOpen(false);
setAddressAction(null);
};
return (
<div className={styles.addressActionContainer}>
<h2 className={styles.header}>{tAddressManagement('deleteAddress')}</h2>
<p>{tAddressManagement('deleteAddressConfirmationMessage')}</p>
{!isLoading ? (
<div className={styles.buttonContainer}>
<WebappButton
text={tCommon('cancel')}
elementType="button"
variant="secondary"
onClick={handleCancel}
/>
<WebappButton
text={tAddressManagement('delete')}
elementType="button"
variant="primary"
onClick={deleteAddress}
/>
</div>
) : (
<div className={styles.addressMgmtSpinner}>
<CircularProgress color="success" />
</div>
)}
</div>
);
};
export default DeleteAddress;
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { ExtendedCountryCode } from '../../../../common/types/country';
import type { SetState } from '../../../../common/types/common';
import type { Address, APIError } from '@planet-sdk/common';
import type { FormData } from './AddAddress';
import type { AddressAction } from '../../../../common/types/profile';

import { useState, useContext, useCallback } from 'react';
import { useTranslations } from 'next-intl';
Expand All @@ -12,24 +14,18 @@ import { ErrorHandlingContext } from '../../../../common/Layout/ErrorHandlingCon
import AddressForm from './microComponents/AddressForm';
import AddressFormLayout from './microComponents/AddressFormLayout';

export type FormData = {
address: string | undefined;
address2: string | null;
city: string | undefined;
zipCode: string | undefined;
state: string | null;
};

interface Props {
setIsModalOpen: SetState<boolean>;
selectedAddressForAction: Address | null;
fetchUserAddresses?: () => Promise<void>;
updateUserAddresses?: () => Promise<void>;
setAddressAction: SetState<AddressAction | null>;
}

const EditAddress = ({
setIsModalOpen,
selectedAddressForAction,
fetchUserAddresses,
updateUserAddresses,
setAddressAction,
}: Props) => {
const defaultAddressDetail = {
address: selectedAddressForAction?.address,
Expand Down Expand Up @@ -65,14 +61,15 @@ const EditAddress = ({
token,
logoutUser
);
if (res && fetchUserAddresses) {
fetchUserAddresses();
if (res && updateUserAddresses) {
updateUserAddresses();
}
} catch (error) {
setErrors(handleError(error as APIError));
} finally {
setIsLoading(false);
setIsModalOpen(false);
setAddressAction(null);
}
},
[
Expand All @@ -84,7 +81,7 @@ const EditAddress = ({
selectedAddressForAction?.id,
tenantConfig.id,
logoutUser,
fetchUserAddresses,
updateUserAddresses,
handleError,
putAuthenticatedRequest,
]
Expand All @@ -100,6 +97,7 @@ const EditAddress = ({
label={tAddressManagement('addressForm.saveChanges')}
defaultAddressDetail={defaultAddressDetail}
processFormData={updateAddress}
setAddressAction={setAddressAction}
/>
</AddressFormLayout>
);
Expand Down
Loading