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
16 changes: 8 additions & 8 deletions src/libs/actions/Policy/DistanceRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,12 @@ function updateDistanceTaxClaimableValue(policyID: string, customUnit: CustomUni
for (const rateID of Object.keys(customUnit.rates)) {
if (rateIDs.includes(rateID)) {
const foundRate = customUnitRates.find((rate) => rate.customUnitRateID === rateID);
optimisticRates[rateID] = {...foundRate, pendingFields: {rate: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}};
successRates[rateID] = {...foundRate, pendingFields: {rate: null}};
optimisticRates[rateID] = {...foundRate, pendingFields: {taxClaimablePercentage: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}};
successRates[rateID] = {...foundRate, pendingFields: {taxClaimablePercentage: null}};
failureRates[rateID] = {
...currentRates[rateID],
pendingFields: {rate: null},
errorFields: {rate: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
pendingFields: {taxClaimablePercentage: null},
errorFields: {taxClaimablePercentage: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
};
}
}
Expand Down Expand Up @@ -601,12 +601,12 @@ function updateDistanceTaxRate(policyID: string, customUnit: CustomUnit, customU
for (const rateID of Object.keys(customUnit.rates)) {
if (rateIDs.includes(rateID)) {
const foundRate = customUnitRates.find((rate) => rate.customUnitRateID === rateID);
optimisticRates[rateID] = {...foundRate, pendingFields: {rate: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}};
successRates[rateID] = {...foundRate, pendingFields: {rate: null}};
optimisticRates[rateID] = {...foundRate, pendingFields: {taxRateExternalID: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}};
successRates[rateID] = {...foundRate, pendingFields: {taxRateExternalID: null}};
failureRates[rateID] = {
...currentRates[rateID],
pendingFields: {rate: null},
errorFields: {rate: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
pendingFields: {taxRateExternalID: null},
errorFields: {taxRateExternalID: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type * as OnyxTypes from '@src/types/onyx';
import type {Rate} from '@src/types/onyx/Policy';
import type {Rate, TaxRateAttributes} from '@src/types/onyx/Policy';

type PolicyDistanceRateDetailsPageOnyxProps = {
/** Policy details */
Expand Down Expand Up @@ -90,7 +90,7 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
const taxClaimableValueToDisplay = taxClaimablePercentage && rate.rate ? CurrencyUtils.convertAmountToDisplayString(taxClaimablePercentage * rate.rate, currency) : '';
const unitToDisplay = translate(`common.${customUnit?.attributes?.unit ?? CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES}`);

const clearErrorFields = (fieldName: keyof Rate) => {
const clearErrorFields = (fieldName: keyof Rate | keyof TaxRateAttributes) => {
DistanceRate.clearPolicyDistanceRateErrorFields(policyID, customUnit.customUnitID, rateID, {...errorFields, [fieldName]: null});
};

Expand Down Expand Up @@ -138,10 +138,10 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
</OfflineWithFeedback>
{isDistanceTrackTaxEnabled && (
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(rate, 'attributes')}
pendingAction={rate?.pendingFields?.attributes}
errors={ErrorUtils.getLatestErrorField(rate, 'taxRateExternalID')}
pendingAction={rate?.pendingFields?.taxRateExternalID}
errorRowStyles={styles.mh5}
onClose={() => clearErrorFields('attributes')}
onClose={() => clearErrorFields('taxRateExternalID')}
>
<View style={styles.w100}>
<MenuItemWithTopDescription
Expand All @@ -155,10 +155,10 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
)}
{isDistanceTrackTaxEnabled && (
<OfflineWithFeedback
errors={ErrorUtils.getLatestErrorField(rate, 'attributes')}
pendingAction={rate?.pendingFields?.attributes}
errors={ErrorUtils.getLatestErrorField(rate, 'taxClaimablePercentage')}
pendingAction={rate?.pendingFields?.taxClaimablePercentage}
errorRowStyles={styles.mh5}
onClose={() => clearErrorFields('attributes')}
onClose={() => clearErrorFields('taxClaimablePercentage')}
>
<MenuItemWithTopDescription
shouldShowRightIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import * as DistanceRate from '@userActions/Policy/DistanceRate';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {PendingAction} from '@src/types/onyx/OnyxCommon';

type ListItemType = {
value: string;
text: string;
isSelected: boolean;
keyForList: string;
pendingAction?: PendingAction;
};

type PolicyDistanceRateTaxRateEditPageProps = WithPolicyOnyxProps & StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.WORKSPACE.DISTANCE_RATE_TAX_RATE_EDIT>;
Expand All @@ -41,6 +43,8 @@ function PolicyDistanceRateTaxRateEditPage({route, policy}: PolicyDistanceRateTa
text: `${value.name} (${value.value})`,
isSelected: taxRateExternalID === key,
keyForList: key,
pendingAction: value.pendingAction,
isDisabled: value.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
}));
return result;
}, [policy, taxRateExternalID]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: Poli
</OfflineWithFeedback>
)}
<OfflineWithFeedback errorRowStyles={styles.mh5}>
<View style={[styles.mt2, styles.mh4]}>
<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>
<Switch
Expand All @@ -135,14 +135,10 @@ function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: Poli
</View>
</View>
{!isPolicyTrackTaxEnabled && (
<View style={[styles.mh4]}>
<Text
style={styles.colorMuted}
fontSize={14}
>
<View style={[styles.mh5]}>
<Text style={styles.colorMuted}>
{translate('workspace.distanceRates.taxFeatureNotEnabledMessage')}
<TextLink
fontSize={14}
onPress={() => {
Navigation.dismissModal();
Navigation.navigate(ROUTES.WORKSPACE_MORE_FEATURES.getRoute(policyID));
Expand Down
24 changes: 14 additions & 10 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ type TaxRateAttributes = {
taxRateExternalID?: string;
};

type Rate = OnyxCommon.OnyxValueWithOfflineFeedback<{
name?: string;
rate?: number;
currency?: string;
customUnitRateID?: string;
enabled?: boolean;
errors?: OnyxCommon.Errors;
errorFields?: OnyxCommon.ErrorFields;
attributes?: TaxRateAttributes;
}>;
type Rate = OnyxCommon.OnyxValueWithOfflineFeedback<
{
name?: string;
rate?: number;
currency?: string;
customUnitRateID?: string;
enabled?: boolean;
errors?: OnyxCommon.Errors;
errorFields?: OnyxCommon.ErrorFields;
attributes?: TaxRateAttributes;
},
keyof TaxRateAttributes
>;

type Attributes = {
unit: Unit;
Expand Down Expand Up @@ -567,6 +570,7 @@ export type {
CustomUnit,
Attributes,
Rate,
TaxRateAttributes,
TaxRate,
TaxRates,
TaxRatesWithDefault,
Expand Down