Skip to content

Commit

Permalink
Merge pull request Expensify#31170 from dukenv0307/fix/30801
Browse files Browse the repository at this point in the history
Build optimistic custom unit when creating workspace
  • Loading branch information
robertjchen authored Dec 3, 2023
2 parents 1682be4 + 34ecf98 commit cc4add5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libs/actions/Policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,10 @@ function generateCustomUnitID() {
* @returns {Object}
*/
function buildOptimisticCustomUnits() {
const currency = lodashGet(allPersonalDetails, [sessionAccountID, 'localCurrencyCode'], CONST.CURRENCY.USD);
const customUnitID = generateCustomUnitID();
const customUnitRateID = generateCustomUnitID();

const customUnits = {
[customUnitID]: {
customUnitID,
Expand All @@ -1088,6 +1090,7 @@ function buildOptimisticCustomUnits() {
customUnitRateID,
name: CONST.CUSTOM_UNITS.DEFAULT_RATE,
rate: CONST.CUSTOM_UNITS.MILEAGE_IRS_RATE * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET,
currency,
},
},
},
Expand All @@ -1097,6 +1100,7 @@ function buildOptimisticCustomUnits() {
customUnits,
customUnitID,
customUnitRateID,
outputCurrency: currency,
};
}

Expand All @@ -1110,7 +1114,7 @@ function buildOptimisticCustomUnits() {
*/
function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', policyID = generatePolicyID(), makeMeAdmin = false) {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);
const {customUnits} = buildOptimisticCustomUnits();
const {customUnits, outputCurrency} = buildOptimisticCustomUnits();

const optimisticData = [
{
Expand All @@ -1123,7 +1127,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
role: CONST.POLICY.ROLE.ADMIN,
owner: sessionEmail,
isPolicyExpenseChatEnabled: true,
outputCurrency: lodashGet(allPersonalDetails, [sessionAccountID, 'localCurrencyCode'], CONST.CURRENCY.USD),
outputCurrency,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
customUnits,
makeMeAdmin,
Expand Down Expand Up @@ -1156,7 +1160,7 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', policyID = generatePolicyID()) {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);

const {customUnits, customUnitID, customUnitRateID} = buildOptimisticCustomUnits();
const {customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticCustomUnits();

const {
announceChatReportID,
Expand Down Expand Up @@ -1202,7 +1206,7 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName
role: CONST.POLICY.ROLE.ADMIN,
owner: sessionEmail,
isPolicyExpenseChatEnabled: true,
outputCurrency: lodashGet(allPersonalDetails, [sessionAccountID, 'localCurrencyCode'], CONST.CURRENCY.USD),
outputCurrency,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
customUnits,
},
Expand Down

0 comments on commit cc4add5

Please sign in to comment.