From 58e694b972b168c80f3068d2e66032d2f32a0153 Mon Sep 17 00:00:00 2001 From: Jefferson Date: Fri, 22 Dec 2023 07:04:24 -0300 Subject: [PATCH 1/4] Prevent multiple pickup point selected for items from white label sellers --- react/fetchers/index.js | 68 +++++++++++++++++++++------- react/utils/DeliveryChannelsUtils.js | 4 ++ 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/react/fetchers/index.js b/react/fetchers/index.js index 8c7e22a..836787e 100644 --- a/react/fetchers/index.js +++ b/react/fetchers/index.js @@ -2,8 +2,11 @@ import axios from 'axios' import axiosRetry from 'axios-retry' import { newAddress } from '../utils/newAddress' -import { PICKUP_IN_STORE, SEARCH } from '../constants' -import { isDelivery } from '../utils/DeliveryChannelsUtils' +import { DELIVERY, PICKUP_IN_STORE, SEARCH } from '../constants' +import { + getFirstItemWithSelectedDelivery, + isPickup, +} from '../utils/DeliveryChannelsUtils' axiosRetry(axios, { retries: 2 }) @@ -84,27 +87,58 @@ export function updateShippingData( addressType: SEARCH, }) + const logisticsInfoWithPickupSelected = logisticsInfo.map((li) => { + const hasPickupSla = li.slas.some((sla) => sla.id === pickupPoint.id) + const shouldKeepSelectedSla = !isPickup(li) + + return { + itemIndex: li.itemIndex, + slas: li.slas, + addressId: hasPickupSla + ? pickupAddressWithAddressId.addressId + : li.addressId, + selectedSla: hasPickupSla + ? pickupPoint.id + : shouldKeepSelectedSla + ? li.selectedSla + : null, + selectedDeliveryChannel: hasPickupSla + ? PICKUP_IN_STORE + : shouldKeepSelectedSla + ? li.selectedDeliveryChannel + : null, + } + }) + + const firstItemWithSelectedDelivery = getFirstItemWithSelectedDelivery( + logisticsInfoWithPickupSelected + ) + + const defaultDeliverySla = firstItemWithSelectedDelivery.selectedSla + + const newLogisticsInfo = logisticsInfoWithPickupSelected.map((li) => { + const hasDefaultDeliverySla = li.slas.find( + (sla) => sla.id === defaultDeliverySla + ) + + if (!li.selectedDeliveryChannel && hasDefaultDeliverySla) { + return { + ...li, + selectedSla: defaultDeliverySla, + selectedDeliveryChannel: DELIVERY, + } + } + + return li + }) + const shippingData = { ...(hasGeocoordinates ? { clearAddressIfPostalCodeNotFound: false } : {}), selectedAddresses: [ ...(residentialAddress ? [residentialAddress] : []), pickupAddressWithAddressId, ], - logisticsInfo: logisticsInfo.map((li) => { - const hasSla = li.slas.some((sla) => sla.id === pickupPoint.id) - const hasDeliverySla = li.slas.some((sla) => isDelivery(sla)) - - return { - itemIndex: li.itemIndex, - addressId: hasSla ? pickupAddressWithAddressId.addressId : li.addressId, - selectedSla: hasSla ? pickupPoint.id : li.selectedSla, - selectedDeliveryChannel: hasSla - ? PICKUP_IN_STORE - : hasDeliverySla - ? li.selectedDeliveryChannel - : null, - } - }), + logisticsInfo: newLogisticsInfo, } return ( diff --git a/react/utils/DeliveryChannelsUtils.js b/react/utils/DeliveryChannelsUtils.js index a86ab1c..b70fd61 100644 --- a/react/utils/DeliveryChannelsUtils.js +++ b/react/utils/DeliveryChannelsUtils.js @@ -32,3 +32,7 @@ export function isDelivery(deliveryChannelSource) { return deliveryChannel === DELIVERY } + +export function getFirstItemWithSelectedDelivery(logisticsInfo) { + return logisticsInfo.find((li) => isDelivery(li)) +} From 4d329d36f72a6c56988e6190bc0bdab53e07be38 Mon Sep 17 00:00:00 2001 From: Jefferson Date: Fri, 22 Dec 2023 07:31:31 -0300 Subject: [PATCH 2/4] Nitpick variable name --- react/fetchers/index.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/react/fetchers/index.js b/react/fetchers/index.js index 836787e..f47ca94 100644 --- a/react/fetchers/index.js +++ b/react/fetchers/index.js @@ -116,21 +116,22 @@ export function updateShippingData( const defaultDeliverySla = firstItemWithSelectedDelivery.selectedSla - const newLogisticsInfo = logisticsInfoWithPickupSelected.map((li) => { - const hasDefaultDeliverySla = li.slas.find( - (sla) => sla.id === defaultDeliverySla - ) - - if (!li.selectedDeliveryChannel && hasDefaultDeliverySla) { - return { - ...li, - selectedSla: defaultDeliverySla, - selectedDeliveryChannel: DELIVERY, + const logisticsInfoWithDefaultDeliverySla = + logisticsInfoWithPickupSelected.map((li) => { + const hasDefaultDeliverySla = li.slas.find( + (sla) => sla.id === defaultDeliverySla + ) + + if (!li.selectedDeliveryChannel && hasDefaultDeliverySla) { + return { + ...li, + selectedSla: defaultDeliverySla, + selectedDeliveryChannel: DELIVERY, + } } - } - return li - }) + return li + }) const shippingData = { ...(hasGeocoordinates ? { clearAddressIfPostalCodeNotFound: false } : {}), @@ -138,7 +139,7 @@ export function updateShippingData( ...(residentialAddress ? [residentialAddress] : []), pickupAddressWithAddressId, ], - logisticsInfo: newLogisticsInfo, + logisticsInfo: logisticsInfoWithDefaultDeliverySla, } return ( From 3a42f94006ad5e632a26f8c1ad1f3995ecdd749f Mon Sep 17 00:00:00 2001 From: Jefferson Date: Fri, 22 Dec 2023 07:55:45 -0300 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c37adfa..078220a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] + ### Fixed - Add rootPath to API requests. +- Prevent multiple pickup point selection for items from white label sellers. ## [3.8.1] - 2023-09-11 From 89a322aa388b93ac6e65aa5dde3267b0898e6210 Mon Sep 17 00:00:00 2001 From: Jefferson Date: Fri, 22 Dec 2023 08:04:31 -0300 Subject: [PATCH 4/4] Fix when there's no item with selected delivery sla --- react/fetchers/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/react/fetchers/index.js b/react/fetchers/index.js index f47ca94..42a93bb 100644 --- a/react/fetchers/index.js +++ b/react/fetchers/index.js @@ -114,7 +114,8 @@ export function updateShippingData( logisticsInfoWithPickupSelected ) - const defaultDeliverySla = firstItemWithSelectedDelivery.selectedSla + const defaultDeliverySla = + firstItemWithSelectedDelivery && firstItemWithSelectedDelivery.selectedSla const logisticsInfoWithDefaultDeliverySla = logisticsInfoWithPickupSelected.map((li) => {