Skip to content

Commit

Permalink
review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
war-in committed Mar 28, 2024
1 parent fffd56b commit bbce2e0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
7 changes: 2 additions & 5 deletions src/pages/iou/request/step/IOURequestStepDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {withOnyx} from 'react-native-onyx';
import DatePicker from '@components/DatePicker';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import type {FormOnyxValues} from '@components/Form/types';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as IOUUtils from '@libs/IOUUtils';
Expand All @@ -21,10 +22,6 @@ import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

type MoneyRequestCreated = {
moneyRequestCreated: string;
};

type IOURequestStepDateOnyxProps = {
/** The draft transaction that holds data to be persisted on the current transaction */
splitDraftTransaction: OnyxEntry<OnyxTypes.Transaction>;
Expand Down Expand Up @@ -66,7 +63,7 @@ function IOURequestStepDate({
Navigation.goBack(backTo);
};

const updateDate = (value: MoneyRequestCreated) => {
const updateDate = (value: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_DATE_FORM>) => {
const newCreated = value.moneyRequestCreated;

// Only update created if it has changed
Expand Down
16 changes: 6 additions & 10 deletions src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import FormProvider from '@components/Form/FormProvider';
import InputWrapperWithRef from '@components/Form/InputWrapper';
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
import type {AnimatedTextInputRef} from '@components/RNTextInput';
import TextInput from '@components/TextInput';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -21,16 +22,11 @@ import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import INPUT_IDS from '@src/types/form/MoneyRequestDescriptionForm';
import type * as OnyxTypes from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import StepScreenWrapper from './StepScreenWrapper';
import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
import withWritableReportOrNotFound from './withWritableReportOrNotFound';

type MoneyRequestComment = {
moneyRequestComment: string;
};

type IOURequestStepDescriptionOnyxProps = {
/** The draft transaction that holds data to be persisted on the current transaction */
splitDraftTransaction: OnyxEntry<OnyxTypes.Transaction>;
Expand Down Expand Up @@ -73,7 +69,7 @@ function IOURequestStepDescription({
const styles = useThemeStyles();
const {translate} = useLocalize();
const inputRef = useRef<AnimatedTextInputRef | null>(null);
const focusTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const focusTimeoutRef = useRef<NodeJS.Timeout | null>(null);
// In the split flow, when editing we use SPLIT_TRANSACTION_DRAFT to save draft value
const isEditingSplitBill = iouType === CONST.IOU.TYPE.SPLIT && action === CONST.IOU.ACTION.EDIT;
const currentDescription = isEditingSplitBill && !lodashIsEmpty(splitDraftTransaction) ? splitDraftTransaction?.comment.comment ?? '' : transaction?.comment.comment ?? '';
Expand All @@ -96,13 +92,13 @@ function IOURequestStepDescription({
/**
* @returns - An object containing the errors for each inputID
*/
const validate = useCallback((value: MoneyRequestComment): Errors => {
const validate = useCallback((values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_DESCRIPTION_FORM>): FormInputErrors<typeof ONYXKEYS.FORMS.MONEY_REQUEST_DESCRIPTION_FORM> => {
const errors = {};

if (value.moneyRequestComment.length > CONST.DESCRIPTION_LIMIT) {
if (values.moneyRequestComment.length > CONST.DESCRIPTION_LIMIT) {
ErrorUtils.addErrorMessage(errors, 'moneyRequestComment', [
'common.error.characterLimitExceedCounter',
{length: value.moneyRequestComment.length, limit: CONST.DESCRIPTION_LIMIT},
{length: values.moneyRequestComment.length, limit: CONST.DESCRIPTION_LIMIT},
]);
}

Expand All @@ -113,7 +109,7 @@ function IOURequestStepDescription({
Navigation.goBack(backTo);
};

const updateComment = (value: {moneyRequestComment: string}) => {
const updateComment = (value: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_DESCRIPTION_FORM>) => {
const newComment = value.moneyRequestComment.trim();

// Only update comment if it has changed
Expand Down
8 changes: 4 additions & 4 deletions src/pages/iou/request/step/withWritableReportOrNotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type WithWritableReportOrNotFoundOnyxProps = {
report: OnyxEntry<Report>;
};

type MoneyRequestStepType = typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT | typeof SCREENS.MONEY_REQUEST.STEP_DESCRIPTION;
type MoneyRequestRouteName = typeof SCREENS.MONEY_REQUEST.STEP_WAYPOINT | typeof SCREENS.MONEY_REQUEST.STEP_DESCRIPTION;

type Route<T extends MoneyRequestStepType> = RouteProp<MoneyRequestNavigatorParamList, T>;
type Route<T extends MoneyRequestRouteName> = RouteProp<MoneyRequestNavigatorParamList, T>;

type WithWritableReportOrNotFoundProps<T extends MoneyRequestStepType> = WithWritableReportOrNotFoundOnyxProps & {route: Route<T>};
type WithWritableReportOrNotFoundProps<T extends MoneyRequestRouteName> = WithWritableReportOrNotFoundOnyxProps & {route: Route<T>};

export default function <TProps extends WithWritableReportOrNotFoundProps<MoneyRequestStepType>, TRef>(
export default function <TProps extends WithWritableReportOrNotFoundProps<MoneyRequestRouteName>, TRef>(
WrappedComponent: ComponentType<TProps & RefAttributes<TRef>>,
): React.ComponentType<Omit<TProps & RefAttributes<TRef>, keyof WithWritableReportOrNotFoundOnyxProps>> {
// eslint-disable-next-line rulesdir/no-negated-variables
Expand Down

0 comments on commit bbce2e0

Please sign in to comment.