From df94ad095e0b3d7341c8d0f5942a4d12b67a27ca Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Sat, 11 May 2024 10:32:46 +0700 Subject: [PATCH 1/3] update the initial policy instead of creating multiple policies --- src/ONYXKEYS.ts | 4 ++++ src/libs/actions/Policy.ts | 3 ++- src/libs/actions/Welcome.ts | 6 +++++- .../BaseOnboardingPersonalDetails.tsx | 1 + src/pages/OnboardingWork/BaseOnboardingWork.tsx | 17 +++++++++++++---- src/pages/OnboardingWork/types.ts | 3 +++ 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/ONYXKEYS.ts b/src/ONYXKEYS.ts index 804c8dadd553..549a98499b23 100755 --- a/src/ONYXKEYS.ts +++ b/src/ONYXKEYS.ts @@ -282,6 +282,9 @@ const ONYXKEYS = { /** Onboarding Purpose selected by the user during Onboarding flow */ ONBOARDING_PURPOSE_SELECTED: 'onboardingPurposeSelected', + /** Onboarding policyID selected by the user during Onboarding flow */ + ONBOARDING_POLICY_ID: 'onboardingPolicyID', + /** Onboarding Purpose selected by the user during Onboarding flow */ ONBOARDING_ADMINS_CHAT_REPORT_ID: 'onboardingAdminsChatReportID', @@ -662,6 +665,7 @@ type OnyxValuesMapping = { [ONYXKEYS.MAX_CANVAS_HEIGHT]: number; [ONYXKEYS.MAX_CANVAS_WIDTH]: number; [ONYXKEYS.ONBOARDING_PURPOSE_SELECTED]: string; + [ONYXKEYS.ONBOARDING_POLICY_ID]: string; [ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID]: string; [ONYXKEYS.IS_SEARCHING_FOR_REPORTS]: boolean; [ONYXKEYS.LAST_VISITED_PATH]: string | undefined; diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index b4022b287d05..cd2930dca47c 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1620,10 +1620,11 @@ function clearAvatarErrors(policyID: string) { * Optimistically update the general settings. Set the general settings as pending until the response succeeds. * If the response fails set a general error message. Clear the error message when updating. */ -function updateGeneralSettings(policyID: string, name: string, currency: string) { +function updateGeneralSettings(policyID: string, name: string, currencyValue?: string) { const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; const distanceUnit = Object.values(policy?.customUnits ?? {}).find((unit) => unit.name === CONST.CUSTOM_UNITS.NAME_DISTANCE); const customUnitID = distanceUnit?.customUnitID; + const currency = currencyValue ?? policy?.outputCurrency ?? CONST.CURRENCY.USD; if (!policy) { return; diff --git a/src/libs/actions/Welcome.ts b/src/libs/actions/Welcome.ts index 3f4c50924e9a..119b7da42e21 100644 --- a/src/libs/actions/Welcome.ts +++ b/src/libs/actions/Welcome.ts @@ -73,6 +73,10 @@ function setOnboardingAdminsChatReportID(adminsChatReportID?: string) { Onyx.set(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, adminsChatReportID ?? null); } +function setOnboardingPolicyID(policyID?: string) { + Onyx.set(ONYXKEYS.ONBOARDING_POLICY_ID, policyID ?? null); +} + Onyx.connect({ key: ONYXKEYS.NVP_ONBOARDING, initWithStoredValues: false, @@ -134,4 +138,4 @@ function resetAllChecks() { isLoadingReportData = true; } -export {onServerDataReady, isOnboardingFlowCompleted, setOnboardingPurposeSelected, resetAllChecks, setOnboardingAdminsChatReportID}; +export {onServerDataReady, isOnboardingFlowCompleted, setOnboardingPurposeSelected, resetAllChecks, setOnboardingAdminsChatReportID, setOnboardingPolicyID}; diff --git a/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx b/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx index 7fcb5c1c5de6..3a8212cad5a5 100644 --- a/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx +++ b/src/pages/OnboardingPersonalDetails/BaseOnboardingPersonalDetails.tsx @@ -62,6 +62,7 @@ function BaseOnboardingPersonalDetails({currentUserPersonalDetails, shouldUseNat ); Welcome.setOnboardingAdminsChatReportID(); + Welcome.setOnboardingPolicyID(); Navigation.dismissModal(); diff --git a/src/pages/OnboardingWork/BaseOnboardingWork.tsx b/src/pages/OnboardingWork/BaseOnboardingWork.tsx index 8fdbed73111e..dc840dfa480f 100644 --- a/src/pages/OnboardingWork/BaseOnboardingWork.tsx +++ b/src/pages/OnboardingWork/BaseOnboardingWork.tsx @@ -27,7 +27,7 @@ import type {BaseOnboardingWorkOnyxProps, BaseOnboardingWorkProps} from './types const OPEN_WORK_PAGE_PURPOSES = [CONST.ONBOARDING_CHOICES.MANAGE_TEAM]; -function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected}: BaseOnboardingWorkProps) { +function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected, onboardingPolicyID}: BaseOnboardingWorkProps) { const styles = useThemeStyles(); const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); @@ -41,11 +41,17 @@ function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected}: return; } const work = values.work.trim(); - const {adminsChatReportID} = Policy.createWorkspace(undefined, true, work); - Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + if (!onboardingPolicyID) { + const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, work); + Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); + Welcome.setOnboardingPolicyID(policyID); + } + // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style + Policy.updateGeneralSettings(onboardingPolicyID as string, work); + Navigation.navigate(ROUTES.ONBOARDING_PERSONAL_DETAILS); }, - [onboardingPurposeSelected], + [onboardingPurposeSelected, onboardingPolicyID], ); const validate = (values: FormOnyxValues<'onboardingWorkForm'>) => { @@ -118,4 +124,7 @@ export default withOnyx({ onboardingPurposeSelected: { key: ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, }, + onboardingPolicyID: { + key: ONYXKEYS.ONBOARDING_POLICY_ID, + }, })(BaseOnboardingWork); diff --git a/src/pages/OnboardingWork/types.ts b/src/pages/OnboardingWork/types.ts index 954c8c15b31d..6c06b28259e8 100644 --- a/src/pages/OnboardingWork/types.ts +++ b/src/pages/OnboardingWork/types.ts @@ -6,6 +6,9 @@ type OnboardingWorkProps = Record; type BaseOnboardingWorkOnyxProps = { /** Saved onboarding purpose selected by the user */ onboardingPurposeSelected: OnyxEntry; + + /** Saved onboarding purpose selected by the user */ + onboardingPolicyID: OnyxEntry; }; type BaseOnboardingWorkProps = BaseOnboardingWorkOnyxProps & { From d86a8568a38088dc3e821ff5d8153c02b50feadc Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Thu, 16 May 2024 00:10:09 +0700 Subject: [PATCH 2/3] using else statement --- src/pages/OnboardingWork/BaseOnboardingWork.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/OnboardingWork/BaseOnboardingWork.tsx b/src/pages/OnboardingWork/BaseOnboardingWork.tsx index dc840dfa480f..111f960431ed 100644 --- a/src/pages/OnboardingWork/BaseOnboardingWork.tsx +++ b/src/pages/OnboardingWork/BaseOnboardingWork.tsx @@ -45,9 +45,9 @@ function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected, o const {adminsChatReportID, policyID} = Policy.createWorkspace(undefined, true, work); Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); + } else { + Policy.updateGeneralSettings(onboardingPolicyID as string, work); } - // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style - Policy.updateGeneralSettings(onboardingPolicyID as string, work); Navigation.navigate(ROUTES.ONBOARDING_PERSONAL_DETAILS); }, From 5f8e897b88ad00a2289493afff3b78d64f4145cb Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Thu, 16 May 2024 00:27:05 +0700 Subject: [PATCH 3/3] fix the lint error --- src/pages/OnboardingWork/BaseOnboardingWork.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/OnboardingWork/BaseOnboardingWork.tsx b/src/pages/OnboardingWork/BaseOnboardingWork.tsx index 111f960431ed..04f2f27d1df1 100644 --- a/src/pages/OnboardingWork/BaseOnboardingWork.tsx +++ b/src/pages/OnboardingWork/BaseOnboardingWork.tsx @@ -46,7 +46,7 @@ function BaseOnboardingWork({shouldUseNativeStyles, onboardingPurposeSelected, o Welcome.setOnboardingAdminsChatReportID(adminsChatReportID); Welcome.setOnboardingPolicyID(policyID); } else { - Policy.updateGeneralSettings(onboardingPolicyID as string, work); + Policy.updateGeneralSettings(onboardingPolicyID, work); } Navigation.navigate(ROUTES.ONBOARDING_PERSONAL_DETAILS);