Skip to content

Commit

Permalink
#260 when there is only one address exists in the cart for use, then …
Browse files Browse the repository at this point in the history
…do not show other-addresses section
  • Loading branch information
rajeev-k-tomy committed Jan 21, 2022
1 parent 267ef82 commit a4f889d
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function useAddressOtherOptions({
}) {
const { customerAddressList } = useAppContext();
const { mostRecentAddressOptions } = useAddressWrapper();
const mostRecentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();

let addressOptions = prepareCustomerAddressOptions({
cartAddress,
Expand Down
2 changes: 1 addition & 1 deletion src/reactapp/src/components/address/utility/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function prepareMostRecentAddressOptions(
stateList,
selectedAddress = ''
) {
const mostRecentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();

if (_isObjEmpty(mostRecentAddressList)) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function BillingAddressForm() {
}

if (isNewAddress) {
const recentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const recentAddressList = LocalStorage.getMostRecentlyUsedAddressList();
const newAddressId = `new_address_${_keys(recentAddressList).length + 1}`;
LocalStorage.addAddressToMostRecentlyUsedList(billingValues);
setIsNewAddress(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ function BillingAddressFormikProvider({ children, formikData }) {
);

useEffect(() => {
if (forceFilledAddress === selectedAddress || !cartHasBillingAddress) {
if (
!isNewAddress &&
(forceFilledAddress === selectedAddress || !cartHasBillingAddress)
) {
if (customerHasAddress(customerAddressList)) {
setFormToViewMode();
}
Expand All @@ -115,6 +118,7 @@ function BillingAddressFormikProvider({ children, formikData }) {
}
}, [
isSame,
isNewAddress,
selectedAddress,
setFormToViewMode,
forceFilledAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function BillingAddressOthers({ forceHide }) {
const { cartBillingAddress } = useBillingAddressCartContext();
const { isLoggedIn, customerAddressList } = useBillingAddressAppContext();
const isCartBillingAddressValid = isCartAddressValid(cartBillingAddress);
const mostRecentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();

const addressOptions = useAddressOtherOptions({
selectedAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React from 'react';
import { CreateNewAddressLink } from '../../address';
import BillingAddressOthers from './BillingAddressOthers';
import BillingAddressSelected from './BillingAddressSelected';
import { _isObjEmpty } from '../../../utils';
import { _keys } from '../../../utils';
import { CART_BILLING_ADDRESS } from '../utility';
import LocalStorage from '../../../utils/localStorage';
import { isCartAddressValid } from '../../../utils/address';
import useBillingAddressAppContext from '../hooks/useBillingAddressAppContext';
import useBillingAddressCartContext from '../hooks/useBillingAddressCartContext';
Expand All @@ -24,8 +25,13 @@ function BillingAddressView() {
} = useBillingAddressFormikContext();
const { cartBillingAddress } = useBillingAddressCartContext();
const { isLoggedIn, customerAddressList } = useBillingAddressAppContext();
const hideOtherAddrSection = isLoggedIn && _isObjEmpty(customerAddressList);
const isCartShippingAddressValid = isCartAddressValid(cartBillingAddress);
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();
// hide other section if there exists only one address for use.
const hideOtherAddrSection =
isLoggedIn &&
_keys(customerAddressList).length <= 1 &&
!_keys(mostRecentAddressList).length;

const newAddressClickHandler = () => {
setIsNewAddress(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function useSaveAddressAction(billingFormikContext) {

const addressIdContext = addressId || selectedAddress;
const isCustomerAddress = isValidCustomerAddressId(addressId);
const mostRecentAddresses = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddresses = LocalStorage.getMostRecentlyUsedAddressList();
const recentAddressInUse = mostRecentAddresses[addressId];
const billingToSave = recentAddressInUse || billingValues;
let updateCustomerAddrPromise = _emptyFunc();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function ShippingAddressForm() {
}

if (isNewAddress) {
const recentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const recentAddressList = LocalStorage.getMostRecentlyUsedAddressList();
const newAddressId = `new_address_${_keys(recentAddressList).length + 1}`;
LocalStorage.addAddressToMostRecentlyUsedList(shippingValues);
setIsNewAddress(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function ShippingAddressOthers({ forceHide }) {
const { isLoggedIn, customerAddressList } = useShippingAddressAppContext();
const { cartShippingAddress } = useShippingAddressCartContext();
const isCartShippingAddressValid = isCartAddressValid(cartShippingAddress);
const mostRecentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();
const addressOptions = useAddressOtherOptions({
selectedAddress,
cartAddress: cartShippingAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import React from 'react';
import { CreateNewAddressLink } from '../../address';
import ShippingAddressOthers from './ShippingAddressOthers';
import ShippingAddressSelected from './ShippingAddressSelected';
import { _isObjEmpty } from '../../../utils';
import { _keys } from '../../../utils';
import { CART_SHIPPING_ADDRESS } from '../utility';
import LocalStorage from '../../../utils/localStorage';
import { isCartAddressValid } from '../../../utils/address';
import useShippingAddressAppContext from '../hooks/useShippingAddressAppContext';
import useShippingAddressCartContext from '../hooks/useShippingAddressCartContext';
Expand All @@ -24,8 +25,13 @@ function ShippingAddressView() {
} = useShippingAddressFormikContext();
const { cartShippingAddress } = useShippingAddressCartContext();
const { isLoggedIn, customerAddressList } = useShippingAddressAppContext();
const hideOtherAddrSection = isLoggedIn && _isObjEmpty(customerAddressList);
const isCartShippingAddressValid = isCartAddressValid(cartShippingAddress);
const mostRecentAddressList = LocalStorage.getMostRecentlyUsedAddressList();
// hide other section if there exists only one address for use.
const hideOtherAddrSection =
isLoggedIn &&
_keys(customerAddressList).length <= 1 &&
!_keys(mostRecentAddressList).length;

const newAddressClickHandler = () => {
setIsNewAddress(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default function useSaveAddressAction(shippingAddressFormContext) {
useAddressWrapper();

const submitHandler = async (customerAddressId) => {
const mostRecentAddresses = LocalStorage.getMostlyRecentlyUsedAddressList();
const mostRecentAddresses = LocalStorage.getMostRecentlyUsedAddressList();
const recentAddressInUse = mostRecentAddresses[customerAddressId];
const addressToSave = recentAddressInUse || shippingAddressToSave;
const useCustomerAddressInSave = customerAddressId && !recentAddressInUse;
Expand Down
2 changes: 1 addition & 1 deletion src/reactapp/src/utils/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function prepareFormAddressFromCartAddress(address, selectedAddressId) {
}

export function isMostRecentAddress(addressId) {
const recentAddressList = LocalStorage.getMostlyRecentlyUsedAddressList();
const recentAddressList = LocalStorage.getMostRecentlyUsedAddressList();

return !!recentAddressList[addressId];
}
8 changes: 4 additions & 4 deletions src/reactapp/src/utils/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const LocalStorage = {
return _get(LocalStorage.getHyvaCheckoutStorage(), source.value, true);
},

getMostlyRecentlyUsedAddressList() {
getMostRecentlyUsedAddressList() {
return (
_get(
LocalStorage.getHyvaCheckoutStorage(),
Expand Down Expand Up @@ -200,7 +200,7 @@ const LocalStorage = {
},

addAddressToMostRecentlyUsedList(newAddress) {
const existingAddrList = LocalStorage.getMostlyRecentlyUsedAddressList();
const existingAddrList = LocalStorage.getMostRecentlyUsedAddressList();
const newAddressId = `new_address_${_keys(existingAddrList).length + 1}`;

_set(newAddress, 'id', newAddressId);
Expand All @@ -217,7 +217,7 @@ const LocalStorage = {
},

updateMostRecentlyAddedAddress(addressId, addressToUpdate) {
const existingAddrList = LocalStorage.getMostlyRecentlyUsedAddressList();
const existingAddrList = LocalStorage.getMostRecentlyUsedAddressList();

_set(existingAddrList, addressId, addressToUpdate);

Expand All @@ -231,7 +231,7 @@ const LocalStorage = {
},

removeMostRecentlyUsedAddress(addressId) {
const existingAddrList = LocalStorage.getMostlyRecentlyUsedAddressList();
const existingAddrList = LocalStorage.getMostRecentlyUsedAddressList();

const storageData = _set(
LocalStorage.getHyvaCheckoutStorage(),
Expand Down

0 comments on commit a4f889d

Please sign in to comment.