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

Create DistanceRates.ts Utils file #42786

Merged
merged 9 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
537 changes: 537 additions & 0 deletions src/libs/actions/Policy/DistanceRate.ts

Large diffs are not rendered by default.

478 changes: 1 addition & 477 deletions src/libs/actions/Policy/Policy.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useWindowDimensions from '@hooks/useWindowDimensions';
import * as ErrorUtils from '@libs/ErrorUtils';
import type {FullScreenNavigatorParamList} from '@libs/Navigation/types';
import * as Category from '@userActions/Policy/Category';
import * as DistanceRate from '@userActions/Policy/DistanceRate';
import * as Policy from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
Expand Down Expand Up @@ -63,7 +64,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive: policy?.areDistanceRatesEnabled ?? false,
pendingAction: policy?.pendingFields?.areDistanceRatesEnabled,
action: (isEnabled: boolean) => {
Policy.enablePolicyDistanceRates(policy?.id ?? '', isEnabled);
DistanceRate.enablePolicyDistanceRates(policy?.id ?? '', isEnabled);
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {getOptimisticRateName, validateRateValue} from '@libs/PolicyDistanceRate
import Navigation from '@navigation/Navigation';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import {createPolicyDistanceRate, generateCustomUnitID} from '@userActions/Policy/Policy';
import {createPolicyDistanceRate} from '@userActions/Policy/DistanceRate';
import {generateCustomUnitID} from '@userActions/Policy/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@navigation/types';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as Policy from '@userActions/Policy/Policy';
import * as DistanceRate from '@userActions/Policy/DistanceRate';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -65,15 +65,15 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail

const toggleRate = () => {
if (!rate?.enabled || canDisableOrDeleteRate) {
Policy.setPolicyDistanceRatesEnabled(policyID, customUnit, [{...rate, enabled: !rate?.enabled}]);
DistanceRate.setPolicyDistanceRatesEnabled(policyID, customUnit, [{...rate, enabled: !rate?.enabled}]);
} else {
setIsWarningModalVisible(true);
}
};

const deleteRate = () => {
Navigation.goBack();
Policy.deletePolicyDistanceRates(policyID, customUnit, [rateID]);
DistanceRate.deletePolicyDistanceRates(policyID, customUnit, [rateID]);
setIsDeleteModalVisible(false);
};

Expand All @@ -95,7 +95,7 @@ function PolicyDistanceRateDetailsPage({policy, route}: PolicyDistanceRateDetail
];

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

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {validateRateValue} from '@libs/PolicyDistanceRatesUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import NotFoundPage from '@pages/ErrorPage/NotFoundPage';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as Policy from '@userActions/Policy/Policy';
import * as DistanceRate from '@userActions/Policy/DistanceRate';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
Expand Down Expand Up @@ -45,7 +45,7 @@ function PolicyDistanceRateEditPage({policy, route}: PolicyDistanceRateEditPageP
const currentRateValue = (rate?.rate ?? 0).toString();

const submitRate = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.POLICY_DISTANCE_RATE_EDIT_FORM>) => {
Policy.updatePolicyDistanceRateValue(policyID, customUnit, [{...rate, rate: Number(values.rate) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET}]);
DistanceRate.updatePolicyDistanceRateValue(policyID, customUnit, [{...rate, rate: Number(values.rate) * CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET}]);
Keyboard.dismiss();
Navigation.goBack();
};
Expand Down
14 changes: 7 additions & 7 deletions src/pages/workspace/distanceRates/PolicyDistanceRatesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Navigation from '@libs/Navigation/Navigation';
import type {FullScreenNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as Policy from '@userActions/Policy/Policy';
import * as DistanceRate from '@userActions/Policy/DistanceRate';
import ButtonWithDropdownMenu from '@src/components/ButtonWithDropdownMenu';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -68,17 +68,17 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
);

const fetchDistanceRates = useCallback(() => {
Policy.openPolicyDistanceRatesPage(policyID);
DistanceRate.openPolicyDistanceRatesPage(policyID);
}, [policyID]);

const dismissError = useCallback(
(item: RateForList) => {
if (customUnitRates[item.value].errors) {
Policy.clearDeleteDistanceRateError(policyID, customUnit?.customUnitID ?? '', item.value);
DistanceRate.clearDeleteDistanceRateError(policyID, customUnit?.customUnitID ?? '', item.value);
return;
}

Policy.clearCreateDistanceRateItemAndError(policyID, customUnit?.customUnitID ?? '', item.value);
DistanceRate.clearCreateDistanceRateItemAndError(policyID, customUnit?.customUnitID ?? '', item.value);
},
[customUnit?.customUnitID, customUnitRates, policyID],
);
Expand Down Expand Up @@ -132,7 +132,7 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
return;
}

Policy.setPolicyDistanceRatesEnabled(
DistanceRate.setPolicyDistanceRatesEnabled(
policyID,
customUnit,
selectedDistanceRates.filter((rate) => rate.enabled).map((rate) => ({...rate, enabled: false})),
Expand All @@ -145,7 +145,7 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
return;
}

Policy.setPolicyDistanceRatesEnabled(
DistanceRate.setPolicyDistanceRatesEnabled(
policyID,
customUnit,
selectedDistanceRates.filter((rate) => !rate.enabled).map((rate) => ({...rate, enabled: true})),
Expand All @@ -158,7 +158,7 @@ function PolicyDistanceRatesPage({policy, route}: PolicyDistanceRatesPageProps)
return;
}

Policy.deletePolicyDistanceRates(
DistanceRate.deletePolicyDistanceRates(
policyID,
customUnit,
selectedDistanceRates.map((rate) => rate.customUnitRateID ?? ''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as OptionsListUtils from '@libs/OptionsListUtils';
import type {SettingsNavigatorParamList} from '@navigation/types';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
import * as Category from '@userActions/Policy/Category';
import * as Policy from '@userActions/Policy/Policy';
import * as DistanceRate from '@userActions/Policy/DistanceRate';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
Expand Down Expand Up @@ -48,7 +48,7 @@ function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: Poli
const errorFields = customUnits[customUnitID]?.errorFields;

const setNewUnit = (unit: UnitItemType) => {
Policy.setPolicyDistanceRatesUnit(policyID, customUnit, {...customUnit, attributes: {unit: unit.value}});
DistanceRate.setPolicyDistanceRatesUnit(policyID, customUnit, {...customUnit, attributes: {unit: unit.value}});
};

const setNewCategory = (category: ListItem) => {
Expand All @@ -63,7 +63,7 @@ function PolicyDistanceRatesSettingsPage({policy, policyCategories, route}: Poli
};

const clearErrorFields = (fieldName: keyof CustomUnit) => {
Policy.clearPolicyDistanceRatesErrorFields(policyID, customUnitID, {...errorFields, [fieldName]: null});
DistanceRate.clearPolicyDistanceRatesErrorFields(policyID, customUnitID, {...errorFields, [fieldName]: null});
};

return (
Expand Down
Loading