Skip to content

Commit

Permalink
fix: remove generalSettings field in policy onyx
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Aug 16, 2024
1 parent 18f1683 commit 1eecd00
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,8 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s
const customUnitID = distanceUnit?.customUnitID;
const currency = currencyValue ?? policy?.outputCurrency ?? CONST.CURRENCY.USD;

// only add pending action for currency if it's different from the current currency
const currencyPendingAction = currency !== policy?.outputCurrency ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : null;
const namePendingAction = name !== policy?.name ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : null;

const currentRates = distanceUnit?.rates ?? {};
const optimisticRates: Record<string, Rate> = {};
Expand Down Expand Up @@ -1076,13 +1076,14 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s

pendingFields: {
...policy.pendingFields,
generalSettings: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
name: namePendingAction,
outputCurrency: currencyPendingAction,
},

// Clear errorFields in case the user didn't dismiss the general settings error
errorFields: {
generalSettings: null,
name: null,
outputCurrency: null,
},
name,
outputCurrency: currency,
Expand All @@ -1103,7 +1104,8 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
generalSettings: null,
name: null,
outputCurrency: null,
},
...(customUnitID && {
customUnits: {
Expand All @@ -1123,7 +1125,8 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errorFields: {
generalSettings: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.editor.genericFailureMessage'),
name: namePendingAction && ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.editor.genericFailureMessage'),
outputCurrency: currencyPendingAction && ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('workspace.editor.genericFailureMessage'),
},
...(customUnitID && {
customUnits: {
Expand Down Expand Up @@ -1618,7 +1621,9 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
generalSettings: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
name: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
outputCurrency: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
address: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
description: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
Expand Down
3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, reimbursementAcc

const hasMembersError = PolicyUtils.hasEmployeeListError(policy);
const hasPolicyCategoryError = PolicyUtils.hasPolicyCategoriesError(policyCategories);
const hasGeneralSettingsError = !isEmptyObject(policy?.errorFields?.generalSettings ?? {}) || !isEmptyObject(policy?.errorFields?.avatarURL ?? {});
const hasGeneralSettingsError =
!isEmptyObject(policy?.errorFields?.name ?? {}) || !isEmptyObject(policy?.errorFields?.avatarURL ?? {}) || !isEmptyObject(policy?.errorFields?.ouputCurrency ?? {});
const {login} = useCurrentUserPersonalDetails();
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policy, login);
const isPaidGroupPolicy = PolicyUtils.isPaidGroupPolicy(policy);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
disabledStyle={styles.cursorDefault}
errorRowStyles={styles.mt3}
/>
<OfflineWithFeedback pendingAction={policy?.pendingFields?.generalSettings}>
<OfflineWithFeedback pendingAction={policy?.pendingFields?.name}>
<MenuItemWithTopDescription
title={policyName}
titleStyle={styles.workspaceTitleStyle}
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Workspace account ID configured for Expensify Card */
workspaceAccountID?: number;
} & Partial<PendingJoinRequestPolicy>,
'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount
'addWorkspaceRoom' | keyof ACHAccount
>;

/** Stages of policy connection sync */
Expand Down

0 comments on commit 1eecd00

Please sign in to comment.