Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: separate pending fields in workspace general settings #47312

Merged
merged 9 commits into from
Aug 22, 2024
21 changes: 21 additions & 0 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,9 @@ 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
dominictb marked this conversation as resolved.
Show resolved Hide resolved
const currencyPendingAction = currency !== policy?.outputCurrency ? CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE : null;

const currentRates = distanceUnit?.rates ?? {};
const optimisticRates: Record<string, Rate> = {};
const finallyRates: Record<string, Rate> = {};
Expand Down Expand Up @@ -1074,6 +1077,7 @@ function updateGeneralSettings(policyID: string, name: string, currencyValue?: s
pendingFields: {
...policy.pendingFields,
generalSettings: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update generalSettings to workspaceName or policyName

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also update generalSettings in other places. Let's create a new workspace offline, you will see that currency and address aren't greyed out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann I think we also need to update the errorFields. And maybe a BE change is needed to return the correct errorFields if it's returning generalSettings error field when we update the WS name failure

And maybe a BE change is needed to return the correct errorFields if it's returning generalSettings error field when we update the WS name failure

cc @aldo-expensify Can you please let me know my concern above? Everything works well if BE returns nothing when we update the WS name failure because we also generate the error in FE. If not, we need a BE change to return the correct errorFields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see generalSettings in the backend, so I think the backend is not creating this error ever. Did you see it happening?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dominictb Is this ready for review? I still see this bug

Screenshot 2024-08-19 at 16 52 20

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann couldn't reproduce your issue. Can you try to fetch the latest commit?

outputCurrency: currencyPendingAction,
},

// Clear errorFields in case the user didn't dismiss the general settings error
Expand Down Expand Up @@ -1280,12 +1284,29 @@ function updateAddress(policyID: string, newAddress: CompanyAddress) {
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
address: newAddress,
pendingFields: {
address: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
];

const finallyData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
address: newAddress,
pendingFields: {
address: null,
},
},
},
];

API.write(WRITE_COMMANDS.UPDATE_POLICY_ADDRESS, parameters, {
optimisticData,
finallyData,
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/workspace/WorkspaceProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import withPolicy from './withPolicy';
import type {WithPolicyProps} from './withPolicy';
import withPolicy from './withPolicy';
import WorkspacePageWithSections from './WorkspacePageWithSections';

type WorkspaceProfilePageOnyxProps = {
Expand Down Expand Up @@ -229,7 +229,7 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
</OfflineWithFeedback>
)}
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.generalSettings}
pendingAction={policy?.pendingFields?.outputCurrency}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.GENERAL_SETTINGS)}
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '-1', CONST.POLICY.COLLECTION_KEYS.GENERAL_SETTINGS)}
errorRowStyles={[styles.mt2]}
Expand All @@ -249,7 +249,7 @@ function WorkspaceProfilePage({policyDraft, policy: policyProp, currencyList = {
</View>
</OfflineWithFeedback>
{canUseSpotnanaTravel && shouldShowAddress && (
<OfflineWithFeedback pendingAction={policy?.pendingFields?.generalSettings}>
<OfflineWithFeedback pendingAction={policy?.pendingFields?.address}>
<View>
<MenuItemWithTopDescription
title={formattedAddress}
Expand Down
Loading