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: QBO - Tag status does not change when 'Members must tag all expenses' is updated offline. #44937

Merged
merged 6 commits into from
Jul 10, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ function renamePolicyTaglist(policyID: string, policyTagListName: {oldName: stri
}

function setPolicyRequiresTag(policyID: string, requiresTag: boolean) {
const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
const isMultiLevelTags = PolicyUtils.isMultiLevelTags(policyTags);

const onyxData: OnyxData = {
optimisticData: [
{
Expand Down Expand Up @@ -653,6 +656,51 @@ function setPolicyRequiresTag(policyID: string, requiresTag: boolean) {
],
};

if (isMultiLevelTags) {
onyxData.optimisticData?.push({
Copy link
Contributor

@Ollyws Ollyws Jul 9, 2024

Choose a reason for hiding this comment

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

As the data we're pushing to the optimisticData, faliureData and successData is exactly the same couldn't we just define it once to avoid repeating ourselves?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ollyws, updated.

key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
...Object.keys(policyTags).reduce<PolicyTagList>((acc, key) => {
acc[key] = {
...acc[key],
required: requiresTag,
};

return acc;
}, {}),
},
});
onyxData.failureData?.push({
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
...Object.keys(policyTags).reduce<PolicyTagList>((acc, key) => {
acc[key] = {
...acc[key],
required: !requiresTag,
};

return acc;
}, {}),
},
});
onyxData.successData?.push({
key: `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
onyxMethod: Onyx.METHOD.MERGE,
value: {
...Object.keys(policyTags).reduce<PolicyTagList>((acc, key) => {
acc[key] = {
...acc[key],
required: !requiresTag,
};

return acc;
}, {}),
},
});
}

const parameters = {
policyID,
requiresTag,
Expand Down
Loading