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: Track tax switch does not appear grayed out when enabled/disabled offline #43347

Merged
merged 20 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
17 changes: 12 additions & 5 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2725,11 +2725,11 @@
customUnits: {
[customUnitID]: {
attributes,
pendingFields: {
taxEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
pendingFields: {
customUnits: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
},
},
],
Expand All @@ -2738,8 +2738,12 @@
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
customUnits: null,
customUnits: {
[customUnitID]: {
pendingFields: {
taxEnabled: null,
},
},
},
},
},
Expand All @@ -2752,6 +2756,9 @@
customUnits: {
[customUnitID]: {
attributes: policy.customUnits ? policy.customUnits[customUnitID].attributes : null,
errorFields: {
taxEnabled: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage'),

Check failure on line 2760 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'getMicroSecondOnyxError' does not exist on type 'typeof import("/home/runner/work/App/App/src/libs/ErrorUtils")'. Did you mean 'getMicroSecondOnyxErrorObject'?

Check failure on line 2760 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Unsafe call of an `any` typed value
},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: Poli
/>
</OfflineWithFeedback>
)}
<OfflineWithFeedback errorRowStyles={styles.mh5}>
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(customUnits[customUnitID] ?? {}, 'taxEnabled')}
errorRowStyles={styles.mh5}
pendingAction={customUnits[customUnitID]?.pendingFields?.taxEnabled}
>
<View style={[styles.mt2, styles.mh5]}>
<View style={[styles.flexRow, styles.mb2, styles.mr2, styles.alignItemsCenter, styles.justifyContentBetween]}>
<Text style={[styles.textNormal, styles.colorMuted]}>{translate('workspace.distanceRates.trackTax')}</Text>
Expand Down
41 changes: 22 additions & 19 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,31 +57,34 @@ type Attributes = {
};

/** Policy custom unit */
type CustomUnit = OnyxCommon.OnyxValueWithOfflineFeedback<{
/** Custom unit name */
name: string;
type CustomUnit = OnyxCommon.OnyxValueWithOfflineFeedback<
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
{
/** Custom unit name */
name: string;

/** ID that identifies this custom unit */
customUnitID: string;
/** ID that identifies this custom unit */
customUnitID: string;

/** Contains custom attributes like unit, for this custom unit */
attributes: Attributes;
/** Contains custom attributes like unit, for this custom unit */
attributes: Attributes;

/** Distance rates using this custom unit */
rates: Record<string, Rate>;
/** Distance rates using this custom unit */
rates: Record<string, Rate>;

/** The default category in which this custom unit is used */
defaultCategory?: string;
/** The default category in which this custom unit is used */
defaultCategory?: string;

/** Whether this custom unit is enabled */
enabled?: boolean;
/** Whether this custom unit is enabled */
enabled?: boolean;

/** Error messages to show in UI */
errors?: OnyxCommon.Errors;
/** Error messages to show in UI */
errors?: OnyxCommon.Errors;

/** Form fields that triggered errors */
errorFields?: OnyxCommon.ErrorFields;
}>;
/** Form fields that triggered errors */
errorFields?: OnyxCommon.ErrorFields;
},
keyof Attributes
>;

/** Policy company address data */
type CompanyAddress = {
Expand Down Expand Up @@ -1265,7 +1268,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Object containing all policy information necessary to connect with Spontana */
travelSettings?: WorkspaceTravelSettings;
} & Partial<PendingJoinRequestPolicy>,
'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount
'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount | keyof Attributes
>;

/** Stages of policy connection sync */
Expand Down
Loading