From 683ce43e06ca2b4bb77182c2acdb2b69b9b3b973 Mon Sep 17 00:00:00 2001 From: yashmantri Date: Tue, 17 Oct 2023 17:03:39 +0530 Subject: [PATCH] TP-43439 | UAT Fixes --- .../addressGeolocation/AddressItem.tsx | 51 +++++++++---------- .../addressGeolocation/SimilarAddressItem.tsx | 7 ++- .../utils/relativeDistanceFormatter.ts | 4 +- src/screens/allCases/ListItem.tsx | 3 +- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/screens/addressGeolocation/AddressItem.tsx b/src/screens/addressGeolocation/AddressItem.tsx index cba805e8..a6c8da79 100644 --- a/src/screens/addressGeolocation/AddressItem.tsx +++ b/src/screens/addressGeolocation/AddressItem.tsx @@ -73,16 +73,15 @@ function AddressItem({ let relativeDistanceBwLatLong = 0; - if (isGroupedAddress) { - const addressGeolocationCoordinated: IGeolocationCoordinate = { - latitude: addressItem.latitude, - longitude: addressItem.longitude, - }; - relativeDistanceBwLatLong = getDistanceFromLatLonInKm( - currentGeolocationCoordinates, - addressGeolocationCoordinated - ); - } + const addressGeolocationCoordinated: IGeolocationCoordinate = { + latitude: addressItem.latitude, + longitude: addressItem.longitude, + }; + relativeDistanceBwLatLong = getDistanceFromLatLonInKm( + currentGeolocationCoordinates, + addressGeolocationCoordinated + ); + const handleAddFeedback = () => { if (prefilledAddressScreenTemplate != null) { const addressKey = '{{addressReferenceId}}'; @@ -138,22 +137,22 @@ function AddressItem({ - - - {sanitizeString([addressItem?.pinCode, addressItem?.city].filter(Boolean).join(', '))} - - - {showRelativeDistance && relativeDistanceBwLatLong ? ( - <>({relativeDistanceFormatter(relativeDistanceBwLatLong)} km away) - ) : ( - '--' - )} - - + {addressItem?.pinCode || addressItem?.city || relativeDistanceBwLatLong ? ( + + + {sanitizeString([addressItem?.pinCode, addressItem?.city].filter(Boolean).join(', '))} + + + {showRelativeDistance && relativeDistanceBwLatLong ? ( + <>({relativeDistanceFormatter(relativeDistanceBwLatLong)} km away) + ) : null} + + + ) : null} {lastFeedbackForAddress?.feedbackPresent ? ( diff --git a/src/screens/addressGeolocation/SimilarAddressItem.tsx b/src/screens/addressGeolocation/SimilarAddressItem.tsx index 9e15de40..73a10c8e 100644 --- a/src/screens/addressGeolocation/SimilarAddressItem.tsx +++ b/src/screens/addressGeolocation/SimilarAddressItem.tsx @@ -29,6 +29,7 @@ import { type GenericFunctionArgs } from '../../common/GenericTypes'; import { toast } from '../../../RN-UI-LIB/src/components/toast'; import { ToastMessages } from '../allCases/constants'; import AddressSource from './AddressSource'; +import relativeDistanceFormatter from './utils/relativeDistanceFormatter'; interface IAddressItem { addressItem: IAddress; @@ -167,8 +168,10 @@ function SimilarAddressItem({ {showRelativeDistance && relativeDistanceBwLatLong ? ( <>   ●   - {!isNaN(relativeDistanceBwLatLong) ? relativeDistanceBwLatLong.toFixed(2) : '--'} km - away + {!isNaN(relativeDistanceBwLatLong) + ? relativeDistanceFormatter(relativeDistanceBwLatLong) + : '--'}{' '} + km away ) : null} {showSource ? : null} diff --git a/src/screens/addressGeolocation/utils/relativeDistanceFormatter.ts b/src/screens/addressGeolocation/utils/relativeDistanceFormatter.ts index 34805f5a..80a89aed 100644 --- a/src/screens/addressGeolocation/utils/relativeDistanceFormatter.ts +++ b/src/screens/addressGeolocation/utils/relativeDistanceFormatter.ts @@ -4,10 +4,10 @@ const relativeDistanceFormatter = (relativeDistance: number) => { return '--'; } if (relativeDistance >= MAXIMUM_DISTANCE_WITH_DECIMAL) { - return Math.round(relativeDistance, 0); + return Math.round(relativeDistance); } - return relativeDistance.toFixed(2); + return relativeDistance.toFixed(1); }; export default relativeDistanceFormatter; diff --git a/src/screens/allCases/ListItem.tsx b/src/screens/allCases/ListItem.tsx index 9588bb37..2ae1b246 100644 --- a/src/screens/allCases/ListItem.tsx +++ b/src/screens/allCases/ListItem.tsx @@ -33,6 +33,7 @@ import { toast } from '../../../RN-UI-LIB/src/components/toast'; import { COMPLETED_STATUSES, ToastMessages } from './constants'; import { VisitPlanStatus } from '../../reducer/userSlice'; import { PaymentStatus } from '../caseDetails/interface'; +import relativeDistanceFormatter from '@screens/addressGeolocation/utils/relativeDistanceFormatter'; interface IListItem { caseListItemDetailObj: ICaseItemCaseDetailObj; @@ -225,7 +226,7 @@ const ListItem: React.FC = (props) => { {nearbyCaseView && distanceInKm && ( - {distanceInKm?.toFixed(2)} km away + {relativeDistanceFormatter(distanceInKm)} km away )}