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 5 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
25 changes: 24 additions & 1 deletion src/libs/actions/Policy/Tag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {NullishDeep, OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {NullishDeep, OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import type {EnablePolicyTagsParams, OpenPolicyTagsPageParams, RenamePolicyTaglistParams, RenamePolicyTagsParams, SetPolicyTagsEnabled, SetPolicyTagsRequired} from '@libs/API/parameters';
Expand Down Expand Up @@ -624,6 +624,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 @@ -667,6 +670,26 @@ function setPolicyRequiresTag(policyID: string, requiresTag: boolean) {
],
};

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

if (isMultiLevelTags) {
onyxData.optimisticData?.push(getUpdatedTagsData(requiresTag));
onyxData.failureData?.push(getUpdatedTagsData(!requiresTag));
onyxData.successData?.push(getUpdatedTagsData(requiresTag));
}

const parameters = {
policyID,
requiresTag,
Expand Down
Loading