Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 9 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
parts: Record<string, boolean>;
file?: File | CustomRNImageManipulatorResult;
policyCategories?: PolicyCategories;
localCurrency: string;
};

type SetWorkspaceReimbursementActionParams = {
Expand All @@ -209,7 +210,7 @@
};

const deprecatedAllPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 213 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand All @@ -225,7 +226,7 @@
});

let deprecatedAllReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 229 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -235,7 +236,7 @@

let deprecatedSessionEmail = '';
let deprecatedSessionAccountID = 0;
Onyx.connect({

Check warning on line 239 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
deprecatedSessionEmail = val?.email ?? '';
Expand All @@ -244,25 +245,25 @@
});

let deprecatedAllPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 248 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (deprecatedAllPersonalDetails = val),
});

let deprecatedAllRecentlyUsedCurrencies: string[];
Onyx.connect({

Check warning on line 254 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.RECENTLY_USED_CURRENCIES,
callback: (val) => (deprecatedAllRecentlyUsedCurrencies = val ?? []),
});

let deprecatedActivePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 260 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (deprecatedActivePolicyID = value),
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected>;
Onyx.connect({

Check warning on line 266 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => (deprecatedIntroSelected = value),
});
Expand Down Expand Up @@ -2698,7 +2699,7 @@
}

function buildDuplicatePolicyData(policy: Policy, options: DuplicatePolicyDataOptions) {
const {policyName = '', policyID = generatePolicyID(), file, welcomeNote, parts, targetPolicyID = generatePolicyID(), policyCategories} = options;
const {policyName = '', policyID = generatePolicyID(), file, welcomeNote, parts, targetPolicyID = generatePolicyID(), policyCategories, localCurrency} = options;

const {
adminsChatReportID,
Expand All @@ -2722,8 +2723,12 @@
const isRulesOptionSelected = parts?.expenses;
const isWorkflowsOptionSelected = parts?.exportLayouts;
const isPerDiemOptionSelected = parts?.perDiem;
const isOverviewOptionSelected = parts?.overview;

const outputCurrency = isOverviewOptionSelected ? policy?.outputCurrency : localCurrency;

const policyMemberAccountIDs = isMemberOptionSelected ? Object.values(getMemberAccountIDsForWorkspace(policy?.employeeList, false, false)) : [];
const {customUnitID, customUnitRateID} = buildOptimisticDistanceRateCustomUnits(policy?.outputCurrency);
const {customUnitID, customUnitRateID} = buildOptimisticDistanceRateCustomUnits(outputCurrency);

const optimisticAnnounceChat = ReportUtils.buildOptimisticAnnounceChat(targetPolicyID, [...policyMemberAccountIDs]);
const announceRoomChat = optimisticAnnounceChat.announceChatData;
Expand Down Expand Up @@ -2774,6 +2779,8 @@
},
avatarURL: file?.uri,
originalFileName: file?.name,
outputCurrency,
address: isOverviewOptionSelected ? policy?.address : undefined,
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import SelectionList from '@components/SelectionList';
import MultiSelectListItem from '@components/SelectionList/ListItem/MultiSelectListItem';
import type {ConfirmButtonOptions, ListItem} from '@components/SelectionList/types';
import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import usePolicy from '@hooks/usePolicy';
Expand Down Expand Up @@ -48,6 +49,7 @@ function WorkspaceDuplicateSelectFeaturesForm({policyID}: WorkspaceDuplicateForm
const customUnitRates: Record<string, Rate> = customUnits?.rates ?? {};
const allRates = Object.values(customUnitRates)?.length;
const [bankAccountList] = useOnyx(ONYXKEYS.BANK_ACCOUNT_LIST, {canBeMissing: true});
const currentUserPersonalDetails = useCurrentUserPersonalDetails();

const accountingIntegrations = Object.values(CONST.POLICY.CONNECTIONS.NAME);
const connectedIntegration = getAllValidConnectedIntegration(policy, accountingIntegrations);
Expand Down Expand Up @@ -225,11 +227,22 @@ function WorkspaceDuplicateSelectFeaturesForm({policyID}: WorkspaceDuplicateForm
distance: selectedItems.includes('distanceRates'),
invoices: selectedItems.includes('invoices'),
exportLayouts: selectedItems.includes('workflows'),
overview: selectedItems.includes('overview'),
},
file: duplicatedWorkspaceAvatar,
localCurrency: currentUserPersonalDetails?.localCurrencyCode ?? '',
});
Navigation.closeRHPFlow();
}, [duplicateWorkspace?.name, duplicateWorkspace?.policyID, policy, policyCategories, selectedItems, translate, duplicatedWorkspaceAvatar]);
}, [
duplicateWorkspace?.name,
duplicateWorkspace?.policyID,
policy,
policyCategories,
selectedItems,
translate,
duplicatedWorkspaceAvatar,
currentUserPersonalDetails?.localCurrencyCode,
]);

const confirmDuplicateAndHideModal = useCallback(() => {
setIsDuplicateModalOpen(false);
Expand Down
1 change: 1 addition & 0 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ describe('actions/Policy', () => {
invoices: true,
exportLayouts: true,
},
localCurrency: 'USD',
};

Policy.duplicateWorkspace(fakePolicy, options);
Expand Down
Loading