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/34611: Remove old merchant page #35641

Merged
merged 35 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4f0a67
remove old merchant page
DylanDylann Feb 2, 2024
731235e
remove old merchant page
DylanDylann Feb 2, 2024
4a4e854
rename function
DylanDylann Feb 2, 2024
690554b
remove redundant
DylanDylann Feb 2, 2024
eb26f8b
merge main
DylanDylann Feb 2, 2024
0e20d75
dry code
DylanDylann Feb 5, 2024
8b94671
merge main
DylanDylann Feb 5, 2024
992a3ca
fix TS
DylanDylann Feb 5, 2024
4504a50
fix types
DylanDylann Feb 5, 2024
227e0dd
merge main
DylanDylann Feb 5, 2024
12c9f48
move copy to new file
DylanDylann Feb 5, 2024
60a5de6
merge main
DylanDylann Feb 6, 2024
c496c44
merge main
DylanDylann Feb 6, 2024
6ddb061
update type
DylanDylann Feb 6, 2024
16686ca
merge main
DylanDylann Feb 6, 2024
f508fc6
migrate to ts
DylanDylann Feb 6, 2024
d8e915d
get new merchant
DylanDylann Feb 6, 2024
c2857d1
merge main
DylanDylann Feb 6, 2024
6a6bee4
merge main
DylanDylann Feb 7, 2024
f73f9f7
merge main
DylanDylann Feb 8, 2024
22f9231
lint fix
DylanDylann Feb 8, 2024
5a2e86b
lint fix
DylanDylann Feb 8, 2024
206ef8a
clean code
DylanDylann Feb 8, 2024
3172e24
merge main
DylanDylann Feb 10, 2024
f026983
fix remove empty line
DylanDylann Feb 10, 2024
403356e
fix typo
DylanDylann Feb 10, 2024
13d5d31
lint fix
DylanDylann Feb 10, 2024
1ac3823
merge main
DylanDylann Feb 13, 2024
b7e5570
merge main
DylanDylann Feb 13, 2024
ce89de5
add comment
DylanDylann Feb 13, 2024
594d1cb
add type
DylanDylann Feb 13, 2024
c19f26c
merge main
DylanDylann Feb 14, 2024
6e24b84
merge main
DylanDylann Feb 14, 2024
70fc1c8
add empty line
DylanDylann Feb 14, 2024
d55757f
fix lint
DylanDylann Feb 14, 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
6 changes: 3 additions & 3 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ const ROUTES = {
getUrlWithBackToParam(`create/${iouType}/distance/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_MERCHANT: {
route: 'create/:iouType/merchant/:transactionID/:reportID',
getRoute: (iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`create/${iouType}/merchant/${transactionID}/${reportID}`, backTo),
route: ':action/:iouType/merchant/:transactionID/:reportID',
getRoute: (action: ValueOf<typeof CONST.IOU.ACTION>, iouType: ValueOf<typeof CONST.IOU.TYPE>, transactionID: string, reportID: string, backTo = '') =>
getUrlWithBackToParam(`${action}/${iouType}/merchant/${transactionID}/${reportID}`, backTo),
},
MONEY_REQUEST_STEP_PARTICIPANTS: {
route: 'create/:iouType/participants/:transactionID/:reportID',
Expand Down
1 change: 0 additions & 1 deletion src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const SCREENS = {
CONFIRMATION: 'Money_Request_Confirmation',
CURRENCY: 'Money_Request_Currency',
CATEGORY: 'Money_Request_Category',
MERCHANT: 'Money_Request_Merchant',
WAYPOINT: 'Money_Request_Waypoint',
EDIT_WAYPOINT: 'Money_Request_Edit_Waypoint',
DISTANCE: 'Money_Request_Distance',
Expand Down
16 changes: 10 additions & 6 deletions src/components/MoneyRequestConfirmationList.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ function MoneyRequestConfirmationList(props) {
IOU.setMoneyRequestPendingFields(props.transactionID, {waypoints: isDistanceRequestWithPendingRoute ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : null});

const distanceMerchant = DistanceRequestUtils.getDistanceMerchant(hasRoute, distance, unit, rate, currency, translate, toLocaleDigit);
IOU.setMoneyRequestMerchant_temporaryForRefactor(props.transactionID, distanceMerchant);
IOU.setMoneyRequestMerchant(props.transactionID, distanceMerchant, false);
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
}, [isDistanceRequestWithPendingRoute, hasRoute, distance, unit, rate, currency, translate, toLocaleDigit, props.isDistanceRequest, props.transactionID]);

/**
Expand Down Expand Up @@ -739,11 +739,15 @@ function MoneyRequestConfirmationList(props) {
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => {
if (props.isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(props.reportID, props.reportActionID, CONST.EDIT_REQUEST_FIELD.MERCHANT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_MERCHANT.getRoute(props.iouType, props.reportID));
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(
CONST.IOU.ACTION.EDIT,
props.iouType,
transaction.transactionID,
props.reportID,
Navigation.getActiveRouteWithoutParams(),
),
);
}}
disabled={didConfirm}
interactive={!props.isReadOnly}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
IOU.setMoneyRequestPendingFields(transaction.transactionID, {waypoints: isDistanceRequestWithPendingRoute ? CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD : null});

const distanceMerchant = DistanceRequestUtils.getDistanceMerchant(hasRoute, distance, unit, rate, currency, translate, toLocaleDigit);
IOU.setMoneyRequestMerchant_temporaryForRefactor(transaction.transactionID, distanceMerchant);
IOU.setMoneyRequestMerchant(transaction.transactionID, distanceMerchant, true);
}, [isDistanceRequestWithPendingRoute, hasRoute, distance, unit, rate, currency, translate, toLocaleDigit, isDistanceRequest, transaction]);

/**
Expand Down Expand Up @@ -710,11 +710,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
style={[styles.moneyRequestMenuItem]}
titleStyle={styles.flex1}
onPress={() => {
if (isEditingSplitBill) {
Navigation.navigate(ROUTES.EDIT_SPLIT_BILL.getRoute(reportID, reportActionID, CONST.EDIT_REQUEST_FIELD.MERCHANT));
return;
}
Navigation.navigate(ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()));
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(CONST.IOU.ACTION.CREATE, iouType, transaction.transactionID, reportID, Navigation.getActiveRouteWithoutParams()),
);
}}
disabled={didConfirm}
interactive={!isReadOnly}
Expand Down
6 changes: 5 additions & 1 deletion src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ function MoneyRequestView({
interactive={canEditMerchant}
shouldShowRightIcon={canEditMerchant}
titleStyle={styles.flex1}
onPress={() => Navigation.navigate(ROUTES.EDIT_REQUEST.getRoute(report.reportID, CONST.EDIT_REQUEST_FIELD.MERCHANT))}
onPress={() =>
Navigation.navigate(
ROUTES.MONEY_REQUEST_STEP_MERCHANT.getRoute(CONST.IOU.ACTION.EDIT, CONST.IOU.TYPE.REQUEST, transaction?.transactionID ?? '', report.reportID),
)
}
brickRoadIndicator={hasViolations('merchant') || (hasErrors && isEmptyMerchant && isPolicyExpenseChat) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined}
error={hasErrors && isPolicyExpenseChat && isEmptyMerchant ? translate('common.error.enterMerchant') : ''}
/>
Expand Down
11 changes: 11 additions & 0 deletions src/components/transactionPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export default PropTypes.shape({
}),
),

/** Selected participants */
participants: PropTypes.arrayOf(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be required? And should the property isPolicyExpenseChat also be required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cead22 in the new TS type

participants?: Participant[];

isPolicyExpenseChat?: boolean;

These fields are not required. participants exists after the user selects participant so why do you think these fields should be required?

What do you think about adding a fallback value for transaction.participant here

    const isMerchantRequired = _.some(transaction.participants, (participant) => Boolean(participant.isPolicyExpenseChat));

Copy link
Contributor

Choose a reason for hiding this comment

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

why do you think these fields should be required?

What you said makes sense, I only thought maybe they could be required since we're using them.

why do you think these fields should be required?

We can, and it would make it more obvious that isPolicyExpenseChat isn't a required prop, but at the same time, the result is the same because participant.isPolicyExpenseChat will be cast to bool even without the explicit cast, so I don't feel strongly either way

PropTypes.shape({
accountID: PropTypes.number,
login: PropTypes.string,
isPolicyExpenseChat: PropTypes.bool,
isOwnPolicyExpenseChat: PropTypes.bool,
selected: PropTypes.bool,
}),
),

/** The original currency of the transaction */
currency: PropTypes.string,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const MoneyRequestModalStackNavigator = createModalStackNavigator<MoneyRequestNa
[SCREENS.MONEY_REQUEST.CONFIRMATION]: () => require('../../../pages/iou/steps/MoneyRequestConfirmPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.CURRENCY]: () => require('../../../pages/iou/IOUCurrencySelection').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.CATEGORY]: () => require('../../../pages/iou/MoneyRequestCategoryPage').default as React.ComponentType,
[SCREENS.MONEY_REQUEST.MERCHANT]: () => require('../../../pages/iou/MoneyRequestMerchantPage').default as React.ComponentType,
[SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: () => require('../../../pages/AddPersonalBankAccountPage').default as React.ComponentType,
[SCREENS.IOU_SEND.ADD_DEBIT_CARD]: () => require('../../../pages/settings/Wallet/AddDebitCardPage').default as React.ComponentType,
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: () => require('../../../pages/EnablePayments/EnablePaymentsPage').default as React.ComponentType,
Expand Down
1 change: 0 additions & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.MONEY_REQUEST.CONFIRMATION]: ROUTES.MONEY_REQUEST_CONFIRMATION.route,
[SCREENS.MONEY_REQUEST.CURRENCY]: ROUTES.MONEY_REQUEST_CURRENCY.route,
[SCREENS.MONEY_REQUEST.CATEGORY]: ROUTES.MONEY_REQUEST_CATEGORY.route,
[SCREENS.MONEY_REQUEST.MERCHANT]: ROUTES.MONEY_REQUEST_MERCHANT.route,
[SCREENS.MONEY_REQUEST.RECEIPT]: ROUTES.MONEY_REQUEST_RECEIPT.route,
[SCREENS.MONEY_REQUEST.DISTANCE]: ROUTES.MONEY_REQUEST_DISTANCE.route,
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: ROUTES.IOU_SEND_ENABLE_PAYMENTS,
Expand Down
9 changes: 5 additions & 4 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,12 @@ type MoneyRequestNavigatorParamList = {
reportID: string;
backTo: string;
};
[SCREENS.MONEY_REQUEST.MERCHANT]: {
iouType: string;
[SCREENS.MONEY_REQUEST.STEP_MERCHANT]: {
action: ValueOf<typeof CONST.IOU.ACTION>;
iouType: ValueOf<typeof CONST.IOU.TYPE>;
transactionID: string;
reportID: string;
field: string;
threadReportID: string;
backTo: string;
};
[SCREENS.IOU_SEND.ENABLE_PAYMENTS]: undefined;
[SCREENS.IOU_SEND.ADD_BANK_ACCOUNT]: undefined;
Expand Down
10 changes: 2 additions & 8 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,8 @@ function setMoneyRequestDescription(transactionID: string, comment: string, isDr
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {comment: {comment: comment.trim()}});
}

// eslint-disable-next-line @typescript-eslint/naming-convention
function setMoneyRequestMerchant_temporaryForRefactor(transactionID: string, merchant: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {merchant: merchant.trim()});
function setMoneyRequestMerchant(transactionID: string, merchant: string, isDraft: boolean) {
Onyx.merge(`${isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, {merchant});
}

function setMoneyRequestPendingFields(transactionID: string, pendingFields: PendingFields) {
Expand Down Expand Up @@ -3731,10 +3730,6 @@ function setMoneyRequestCurrency(currency: string) {
Onyx.merge(ONYXKEYS.IOU, {currency});
}

function setMoneyRequestMerchant(merchant: string) {
Onyx.merge(ONYXKEYS.IOU, {merchant: merchant.trim()});
}

function setMoneyRequestCategory(category: string) {
Onyx.merge(ONYXKEYS.IOU, {category});
}
Expand Down Expand Up @@ -3873,7 +3868,6 @@ export {
setMoneyRequestCurrency_temporaryForRefactor,
setMoneyRequestDescription,
setMoneyRequestOriginalCurrency_temporaryForRefactor,
setMoneyRequestMerchant_temporaryForRefactor,
setMoneyRequestParticipants_temporaryForRefactor,
setMoneyRequestPendingFields,
setMoneyRequestReceipt,
Expand Down
44 changes: 1 addition & 43 deletions src/pages/EditRequestPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import ROUTES from '@src/ROUTES';
import EditRequestAmountPage from './EditRequestAmountPage';
import EditRequestCategoryPage from './EditRequestCategoryPage';
import EditRequestDistancePage from './EditRequestDistancePage';
import EditRequestMerchantPage from './EditRequestMerchantPage';
import EditRequestReceiptPage from './EditRequestReceiptPage';
import EditRequestTagPage from './EditRequestTagPage';
import reportActionPropTypes from './home/report/reportActionPropTypes';
Expand Down Expand Up @@ -74,13 +73,7 @@ const defaultProps = {
function EditRequestPage({report, route, policy, policyCategories, policyTags, parentReportActions, transaction}) {
const parentReportActionID = lodashGet(report, 'parentReportActionID', '0');
const parentReportAction = lodashGet(parentReportActions, parentReportActionID, {});
const {
amount: transactionAmount,
currency: transactionCurrency,
merchant: transactionMerchant,
category: transactionCategory,
tag: transactionTag,
} = ReportUtils.getTransactionDetails(transaction);
const {amount: transactionAmount, currency: transactionCurrency, category: transactionCategory, tag: transactionTag} = ReportUtils.getTransactionDetails(transaction);

const defaultCurrency = lodashGet(route, 'params.currency', '') || transactionCurrency;
const fieldToEdit = lodashGet(route, ['params', 'field'], '');
Expand Down Expand Up @@ -128,31 +121,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
[transaction, report, policy, policyTags, policyCategories],
);

const saveMerchant = useCallback(
({merchant: newMerchant}) => {
const newTrimmedMerchant = newMerchant.trim();

// In case the merchant hasn't been changed, do not make the API request.
// In case the merchant has been set to empty string while current merchant is partial, do nothing too.
if (newTrimmedMerchant === transactionMerchant || (newTrimmedMerchant === '' && transactionMerchant === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT)) {
Navigation.dismissModal();
return;
}

// An empty newTrimmedMerchant is only possible for the P2P IOU case
IOU.updateMoneyRequestMerchant(
transaction.transactionID,
report.reportID,
newTrimmedMerchant || CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT,
policy,
policyTags,
policyCategories,
);
Navigation.dismissModal();
},
[transactionMerchant, transaction, report, policy, policyTags, policyCategories],
);

const saveTag = useCallback(
({tag: newTag}) => {
let updatedTag = newTag;
Expand Down Expand Up @@ -191,16 +159,6 @@ function EditRequestPage({report, route, policy, policyCategories, policyTags, p
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.MERCHANT) {
return (
<EditRequestMerchantPage
defaultMerchant={transactionMerchant}
isPolicyExpenseChat={isPolicyExpenseChat}
onSubmit={saveMerchant}
/>
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.CATEGORY && shouldShowCategories) {
return (
<EditRequestCategoryPage
Expand Down
13 changes: 0 additions & 13 deletions src/pages/EditSplitBillPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {Report, ReportActions, Transaction} from '@src/types/onyx';
import type {OriginalMessageIOU} from '@src/types/onyx/OriginalMessage';
import EditRequestAmountPage from './EditRequestAmountPage';
import EditRequestCategoryPage from './EditRequestCategoryPage';
import EditRequestMerchantPage from './EditRequestMerchantPage';
import EditRequestTagPage from './EditRequestTagPage';

type EditSplitBillOnyxProps = {
Expand All @@ -44,7 +43,6 @@ function EditSplitBillPage({route, transaction, draftTransaction, report}: EditS
const {
amount: transactionAmount,
currency: transactionCurrency,
merchant: transactionMerchant,
category: transactionCategory,
tag: transactionTag,
} = ReportUtils.getTransactionDetails(draftTransaction ?? transaction) ?? {};
Expand Down Expand Up @@ -82,17 +80,6 @@ function EditSplitBillPage({route, transaction, draftTransaction, report}: EditS
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.MERCHANT) {
return (
<EditRequestMerchantPage
defaultMerchant={transactionMerchant ?? ''}
onSubmit={(transactionChanges) => {
setDraftSplitTransaction({merchant: transactionChanges.merchant.trim()});
}}
/>
);
}

if (fieldToEdit === CONST.EDIT_REQUEST_FIELD.CATEGORY) {
return (
<EditRequestCategoryPage
Expand Down
Loading
Loading