From 06904f13aff53c4b3680a7af65274611bce340e9 Mon Sep 17 00:00:00 2001 From: smelaa Date: Tue, 7 May 2024 14:46:19 +0200 Subject: [PATCH 1/2] Fix country selection bug --- src/libs/Navigation/types.ts | 5 ++++- .../workspace/WorkspaceProfileAddressPage.tsx | 14 +++++++++++++- src/pages/workspace/withPolicy.tsx | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 380ede9dfec5..4e8a7dde6c27 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -163,7 +163,10 @@ type SettingsNavigatorParamList = { [SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_DATE]: undefined; [SCREENS.SETTINGS.PROFILE.STATUS_CLEAR_AFTER_TIME]: undefined; [SCREENS.WORKSPACE.CURRENCY]: undefined; - [SCREENS.WORKSPACE.ADDRESS]: undefined; + [SCREENS.WORKSPACE.ADDRESS]: { + policyID: string; + country?: Country | ''; + }; [SCREENS.WORKSPACE.NAME]: undefined; [SCREENS.WORKSPACE.DESCRIPTION]: undefined; [SCREENS.WORKSPACE.SHARE]: undefined; diff --git a/src/pages/workspace/WorkspaceProfileAddressPage.tsx b/src/pages/workspace/WorkspaceProfileAddressPage.tsx index 175a3611ef57..35c0428a3d2d 100644 --- a/src/pages/workspace/WorkspaceProfileAddressPage.tsx +++ b/src/pages/workspace/WorkspaceProfileAddressPage.tsx @@ -4,11 +4,13 @@ import AddressForm from '@components/AddressForm'; import type {FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; +import useGeographicalStateFromRoute from '@hooks/useGeographicalStateFromRoute'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; import {updateAddress} from '@userActions/Policy'; import type {Country} from '@src/CONST'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type SCREENS from '@src/SCREENS'; import type {CompanyAddress} from '@src/types/onyx/Policy'; @@ -19,7 +21,7 @@ type WorkspaceProfileAddressPagePolicyProps = WithPolicyProps; type WorkspaceProfileAddressPageProps = StackScreenProps & WorkspaceProfileAddressPagePolicyProps; -function WorkspaceProfileAddressPage({policy}: WorkspaceProfileAddressPageProps) { +function WorkspaceProfileAddressPage({policy, route}: WorkspaceProfileAddressPageProps) { const {translate} = useLocalize(); const address = useMemo(() => policy?.address, [policy]); const [currentCountry, setCurrentCountry] = useState(address?.country); @@ -28,6 +30,9 @@ function WorkspaceProfileAddressPage({policy}: WorkspaceProfileAddressPageProps) const [city, setCity] = useState(address?.city); const [zipcode, setZipcode] = useState(address?.zipCode); + const countryFromUrlTemp = route?.params?.country; + const countryFromUrl = CONST.ALL_COUNTRIES[countryFromUrlTemp as keyof typeof CONST.ALL_COUNTRIES] ? countryFromUrlTemp : ''; + const updatePolicyAddress = (values: FormOnyxValues) => { if (!policy) { return; @@ -81,6 +86,13 @@ function WorkspaceProfileAddressPage({policy}: WorkspaceProfileAddressPageProps) setZipcode(address.zipCode); }, [address]); + useEffect(() => { + if (!countryFromUrl) { + return; + } + handleAddressChange(countryFromUrl, 'country'); + }, [countryFromUrl, handleAddressChange]); + return ( ; function getPolicyIDFromRoute(route: PolicyRoute): string { From fe19eed611c766cf90c8b0baff433c80fcc2330d Mon Sep 17 00:00:00 2001 From: smelaa Date: Tue, 7 May 2024 16:08:32 +0200 Subject: [PATCH 2/2] eslint --- src/pages/workspace/WorkspaceProfileAddressPage.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceProfileAddressPage.tsx b/src/pages/workspace/WorkspaceProfileAddressPage.tsx index 35c0428a3d2d..b73a57c30223 100644 --- a/src/pages/workspace/WorkspaceProfileAddressPage.tsx +++ b/src/pages/workspace/WorkspaceProfileAddressPage.tsx @@ -4,7 +4,6 @@ import AddressForm from '@components/AddressForm'; import type {FormOnyxValues} from '@components/Form/types'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import ScreenWrapper from '@components/ScreenWrapper'; -import useGeographicalStateFromRoute from '@hooks/useGeographicalStateFromRoute'; import useLocalize from '@hooks/useLocalize'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types';