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

[TS migration] Migrate WorkspaceReimburse Page #35399

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4feb092
[TS Migration] Migrate WorkspaceCard to Typescript
ruben-rebelo Jan 23, 2024
b974629
[TS migration] Migrate WorkspaceReimburse page
ruben-rebelo Feb 1, 2024
f51dfad
Revert "[TS Migration] Migrate WorkspaceCard to Typescript"
ruben-rebelo Feb 1, 2024
3a7ad1e
[TS migration][WorkspaceReimburse] Missing imports
ruben-rebelo Feb 1, 2024
d11c98a
[TS migration][WorkspaceReimburse] Code improvements
ruben-rebelo Feb 2, 2024
794d552
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Feb 2, 2024
e66017b
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Feb 8, 2024
34135a2
[TS migration][WorkspaceReimburse] Code improvements
ruben-rebelo Feb 8, 2024
7cd655d
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Feb 22, 2024
458be5e
[TS migration][WorkspaceReimburse] Ts issues fix
ruben-rebelo Feb 27, 2024
aafd0e5
[TS migration][WorkspaceReimburse] Lint
ruben-rebelo Feb 27, 2024
a04d571
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Feb 28, 2024
c403cfa
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Mar 12, 2024
9cda701
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Mar 18, 2024
026d8e7
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Mar 21, 2024
64cfc7e
[TS migration][WorkspaceReimburse] TS issue fix
ruben-rebelo Mar 21, 2024
1f240fd
Merge branch 'main' into ts-migration/workspacereimburse-page
ruben-rebelo Mar 22, 2024
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
4 changes: 2 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ type OnyxValues = {
[ONYXKEYS.FORMS.ADD_DEBIT_CARD_FORM_DRAFT]: OnyxTypes.AddDebitCardForm;
[ONYXKEYS.FORMS.WORKSPACE_SETTINGS_FORM]: OnyxTypes.WorkspaceSettingsForm;
[ONYXKEYS.FORMS.WORKSPACE_SETTINGS_FORM_DRAFT]: OnyxTypes.WorkspaceSettingsForm;
[ONYXKEYS.FORMS.WORKSPACE_RATE_AND_UNIT_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.WORKSPACE_RATE_AND_UNIT_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.WORKSPACE_RATE_AND_UNIT_FORM]: OnyxTypes.RateUnitForm;
[ONYXKEYS.FORMS.WORKSPACE_RATE_AND_UNIT_FORM_DRAFT]: OnyxTypes.RateUnitForm;
[ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM]: OnyxTypes.CloseAccountForm;
[ONYXKEYS.FORMS.CLOSE_ACCOUNT_FORM_DRAFT]: OnyxTypes.CloseAccountForm;
[ONYXKEYS.FORMS.PROFILE_SETTINGS_FORM]: OnyxTypes.Form;
Expand Down
4 changes: 2 additions & 2 deletions src/components/Picker/BasePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ function BasePicker<TPickerValue>(
*/
const onValueChange = (inputValue: TPickerValue, index: number) => {
if (inputID) {
onInputChange(inputValue);
onInputChange?.(inputValue);
return;
}

onInputChange(inputValue, index);
onInputChange?.(inputValue, index);
};

const enableHighlight = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type BasePickerProps<TPickerValue> = {
shouldSaveDraft?: boolean;

/** A callback method that is called when the value changes and it receives the selected value as an argument */
onInputChange: (value: TPickerValue, index?: number) => void;
onInputChange?: (value: TPickerValue, index?: number) => void;

/** Size of a picker component */
size?: PickerSize;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type UpdateWorkspaceCustomUnitAndRateParams = {
policyID: string;
lastModified: number;
lastModified?: number | string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lastModified?: number | string;
lastModified?: string;

customUnit: string;
customUnitRate: string;
};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/DistanceRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function getDistanceMerchant(
const distanceUnit = unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.miles') : translate('common.kilometers');
const singularDistanceUnit = unit === CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES ? translate('common.mile') : translate('common.kilometer');
const unitString = distanceInUnits === '1' ? singularDistanceUnit : distanceUnit;
const ratePerUnit = PolicyUtils.getUnitRateValue({rate}, toLocaleDigit);
const ratePerUnit = rate ? PolicyUtils.getUnitRateValue(toLocaleDigit, {rate}) : translate('common.tbd');
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const currencySymbol = CurrencyUtils.getCurrencySymbol(currency) || `${currency} `;

Expand Down
6 changes: 3 additions & 3 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type {ValueOf} from 'type-fest';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, PolicyMembers, PolicyTag, PolicyTags} from '@src/types/onyx';
import type {Rate} from '@src/types/onyx/Policy';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type MemberEmailsToAccountIDs = Record<string, number>;
type UnitRate = {rate: number};

/**
* Filter out the active policies, which will exclude policies with pending deletion
Expand Down Expand Up @@ -47,7 +47,7 @@ function hasCustomUnitsError(policy: OnyxEntry<Policy>): boolean {
return Object.keys(policy?.customUnits?.errors ?? {}).length > 0;
}

function getNumericValue(value: number, toLocaleDigit: (arg: string) => string): number | string {
function getNumericValue(value: number | string, toLocaleDigit: (arg: string) => string): number | string {
const numValue = parseFloat(value.toString().replace(toLocaleDigit('.'), '.'));
if (Number.isNaN(numValue)) {
return NaN;
Expand All @@ -63,7 +63,7 @@ function getRateDisplayValue(value: number, toLocaleDigit: (arg: string) => stri
return numValue.toString().replace('.', toLocaleDigit('.')).substring(0, value.toString().length);
}

function getUnitRateValue(customUnitRate: UnitRate, toLocaleDigit: (arg: string) => string) {
function getUnitRateValue(toLocaleDigit: (arg: string) => string, customUnitRate?: Rate) {
return getRateDisplayValue((customUnitRate?.rate ?? 0) / CONST.POLICY.CUSTOM_UNIT_RATE_BASE_OFFSET, toLocaleDigit);
}

Expand Down
19 changes: 14 additions & 5 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, PolicyMember, PolicyTags, RecentlyUsedCategories, RecentlyUsedTags, ReimbursementAccount, Report, ReportAction, Transaction} from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {CustomUnit} from '@src/types/onyx/Policy';
import type {Attributes, CustomUnit, Rate} from '@src/types/onyx/Policy';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Expand Down Expand Up @@ -68,6 +68,13 @@ type OptimisticCustomUnits = {
outputCurrency: string;
};

type NewCustomUnit = {
customUnitID: string;
name: string;
attributes: Attributes;
rates: Rate;
};

type PoliciesRecord = Record<string, OnyxEntry<Policy>>;

const allPolicies: OnyxCollection<Policy> = {};
Expand Down Expand Up @@ -933,7 +940,7 @@ function hideWorkspaceAlertMessage(policyID: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {alertMessage: ''});
}

function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: CustomUnit, newCustomUnit: CustomUnit, lastModified: number) {
function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: CustomUnit, newCustomUnit: NewCustomUnit, lastModified?: string) {
if (!currentCustomUnit.customUnitID || !newCustomUnit?.customUnitID || !newCustomUnit.rates?.customUnitRateID) {
return;
}
Expand All @@ -947,7 +954,7 @@ function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: C
[newCustomUnit.customUnitID]: {
...newCustomUnit,
rates: {
[newCustomUnit.rates.customUnitRateID as string]: {
[newCustomUnit.rates.customUnitRateID]: {
...newCustomUnit.rates,
errors: null,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
Expand All @@ -970,7 +977,7 @@ function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: C
pendingAction: null,
errors: null,
rates: {
[newCustomUnit.rates.customUnitRateID as string]: {
[newCustomUnit.rates.customUnitRateID]: {
pendingAction: null,
},
},
Expand All @@ -989,7 +996,7 @@ function updateWorkspaceCustomUnitAndRate(policyID: string, currentCustomUnit: C
[currentCustomUnit.customUnitID]: {
customUnitID: currentCustomUnit.customUnitID,
rates: {
[newCustomUnit.rates.customUnitRateID as string]: {
[newCustomUnit.rates.customUnitRateID]: {
...currentCustomUnit.rates,
errors: ErrorUtils.getMicroSecondOnyxError('workspace.reimburse.updateCustomUnitError'),
},
Expand Down Expand Up @@ -2019,3 +2026,5 @@ export {
createDraftInitialWorkspace,
setWorkspaceInviteMessageDraft,
};

export type {NewCustomUnit};
172 changes: 0 additions & 172 deletions src/pages/workspace/reimburse/WorkspaceRateAndUnitPage.js

This file was deleted.

Loading
Loading