Skip to content

Commit

Permalink
Merge pull request #43849 from cretadn22/should-grey-out-default-valu…
Browse files Browse the repository at this point in the history
…e-when-creating-offline

Should grey out default value when creating policy offline
  • Loading branch information
iwiznia authored Jun 18, 2024
2 parents b278b8f + e74a697 commit 8dea185
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
38 changes: 36 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1466,6 +1466,11 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
harvesting: {
enabled: true,
},
pendingFields: {
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
];
Expand Down Expand Up @@ -1538,6 +1543,11 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
},
},
chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
pendingFields: {
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
{
Expand Down Expand Up @@ -1606,7 +1616,14 @@ function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {pendingAction: null},
value: {
pendingAction: null,
pendingFields: {
autoReporting: null,
approvalMode: null,
reimbursementChoice: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -1802,6 +1819,11 @@ function createDraftWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policy
},
},
chatReportIDAdmins: makeMeAdmin ? Number(adminsChatReportID) : undefined,
pendingFields: {
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
{
Expand Down Expand Up @@ -2078,6 +2100,11 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string
errors: {},
},
},
pendingFields: {
autoReporting: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
approvalMode: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
};

const optimisticData: OnyxUpdate[] = [
Expand Down Expand Up @@ -2148,7 +2175,14 @@ function createWorkspaceFromIOUPayment(iouReport: Report | EmptyObject): string
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {pendingAction: null},
value: {
pendingAction: null,
pendingFields: {
autoReporting: null,
approvalMode: null,
reimbursementChoice: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down
9 changes: 7 additions & 2 deletions src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
keyForList: value.customUnitRateID ?? '',
isSelected: selectedDistanceRates.find((rate) => rate.customUnitRateID === value.customUnitRateID) !== undefined,
isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
pendingAction: value.pendingAction ?? value.pendingFields?.rate ?? value.pendingFields?.enabled ?? value.pendingFields?.currency,
pendingAction:
value.pendingAction ??
value.pendingFields?.rate ??
value.pendingFields?.enabled ??
value.pendingFields?.currency ??
(policy?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD ? policy?.pendingAction : undefined),
errors: value.errors ?? undefined,
rightElement: <ListItemRightCaretWithLabel labelText={value.enabled ? translate('workspace.common.enabled') : translate('workspace.common.disabled')} />,
})),
[customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate],
[customUnit?.attributes?.unit, customUnitRates, selectedDistanceRates, translate, policy?.pendingAction],
);

const addRate = () => {
Expand Down

0 comments on commit 8dea185

Please sign in to comment.