Skip to content

Commit

Permalink
Merge pull request #44937 from Krishna2323/krishna2323/issue/43754
Browse files Browse the repository at this point in the history
fix: QBO - Tag status does not change when 'Members must tag all expenses' is updated offline.
  • Loading branch information
mountiny authored Jul 10, 2024
2 parents fef62aa + f89f46b commit e5edc77
Showing 1 changed file with 24 additions and 1 deletion.
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) {
],
};

if (isMultiLevelTags) {
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;
}, {}),
},
});

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

const parameters = {
policyID,
requiresTag,
Expand Down

0 comments on commit e5edc77

Please sign in to comment.