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

Refactor iou page by separating each step as individual screen #17964

Merged
merged 70 commits into from
Jun 21, 2023

Conversation

bernhardoj
Copy link
Contributor

@bernhardoj bernhardoj commented Apr 25, 2023

Details

Participants selection is lost when the component unmount. This PR refactor money request page to have their own screen for each step and save the currency, amount, description, and participants in a context provider.

Fixed Issues

$ #17662
PROPOSAL: #17662 (comment)

Tests

Same as QA Steps

  • Verify that no errors appear in the JS console

Offline tests

Same as QA Steps

QA Steps

  1. Open a group chat (chat with >=3 members)
  2. Press the "+" button in composer
  3. Press Split Bill
  4. Enter any amount and press Next
  5. Unselect any amount of participants
  6. Press Amount to edit the amount
  7. Go back
  8. Verify the unselected participants stay unselected
  9. Go back again
  10. Press Next
  11. Verify the same thing on step 8
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Screen.Recording.2023-05-19.at.19.27.50.mov
Mobile Web - Chrome
WhatsApp.Video.2023-05-19.at.20.22.35.mp4
Mobile Web - Safari
Screen.Recording.2023-05-19.at.19.52.03.mov
Desktop
Screen.Recording.2023-05-19.at.19.36.20.mov
iOS
Screen.Recording.2023-05-19.at.19.50.47.mov
Android
WhatsApp.Video.2023-05-19.at.20.22.34.mov

@bernhardoj bernhardoj requested a review from a team as a code owner April 25, 2023 12:22
@melvin-bot melvin-bot bot requested review from PauloGasparSv and thesahindia and removed request for a team April 25, 2023 12:22
@MelvinBot
Copy link

@PauloGasparSv @thesahindia One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@bernhardoj
Copy link
Contributor Author

bernhardoj commented Apr 25, 2023

Additional video to make sure iou request is not broken:

  • Send money
Screen.Recording.2023-05-19.at.18.20.13.mov
  • Send money (from FAB)
Screen.Recording.2023-05-19.at.18.32.03.mov
  • Request money
Screen.Recording.2023-05-19.at.18.23.45.mov
  • Request money (from FAB)
Screen.Recording.2023-05-19.at.18.32.38.mov
  • Split money (from FAB)
Screen.Recording.2023-05-19.at.20.38.09.mov
  • Split money
Screen.Recording.2023-05-19.at.20.37.35.mov
  • Request Money in Policy Expense Chat
Screen.Recording.2023-06-02.at.22.26.13.mov
  • Request Money in Policy Expense Chat (FAB)
Screen.Recording.2023-06-02.at.22.36.11.mov

@bernhardoj
Copy link
Contributor Author

bernhardoj commented Apr 25, 2023

Details of the refactor:

  1. MoneyRequestModal removed
  2. Each step (amount, participants, and confirmation) now has their own screen wrapped with ScreenWrapper
  3. Amount, currency, participants, and description is stored in Onyx.
  4. Logic from MoneyRequestModal moved to the appropriate step page, for example createTransaction moved to MoneyRequestConfirmPage
  5. Because the IOU type is now taken from the route params, it's possible for user to include invalid IOU type, thus I added a FullPageNotFoundView to show not found interface when the IOU type is not one of send, request, or split.

Screenshot 2023-04-25 at 13 13 52

@bernhardoj

This comment was marked as outdated.

};

const MoneyRequestParticipantsPage = (props) => {
if (props.iou.loading) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed because there will be never a loading happen when we load the participants.

if (this.isEditing) {
this.props.redirectIfEmpty([this.props.participants, this.props.amount], this.iouType, this.reportID);
} else {
// Set the money request participants based on the report participants
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taken from here

const [selectedOptions, setSelectedOptions] = useState(
ReportUtils.isPolicyExpenseChat(props.report)
? OptionsListUtils.getPolicyExpenseReportOptions(props.report)
: OptionsListUtils.getParticipantsOptions(props.report, props.personalDetails),
);

*
* @returns {String}
*/
getTitleForStep() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taken from here

const titleForStep = useMemo(() => {
if (currentStepIndex === 0) {
const confirmIndex = _.indexOf(steps, Steps.MoneyRequestConfirm);
if (previousStepIndex === confirmIndex) {
return props.translate('iou.amount');
}
if (props.iouType === CONST.IOU.MONEY_REQUEST_TYPE.SEND) {
return props.translate('iou.sendMoney');
}
return props.translate(props.hasMultipleParticipants ? 'iou.splitBill' : 'iou.requestMoney');
}
return props.translate('iou.cash');
// eslint-disable-next-line react-hooks/exhaustive-deps -- props does not need to be a dependency as it will always exist
}, [currentStepIndex, props.translate, steps]);

prevCreatingIOUTransactionStatusRef.current = lodashGet(props.iou, 'creatingIOUTransaction');
});

const createTransaction = useCallback((selectedParticipants) => {
Copy link
Contributor Author

@bernhardoj bernhardoj Apr 25, 2023

Choose a reason for hiding this comment

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

Taken from here

const createTransaction = useCallback((selectedParticipants) => {
const reportID = lodashGet(props.route, 'params.reportID', '');
const trimmedComment = props.iou.comment.trim();
// IOUs created from a group report will have a reportID param in the route.
// Since the user is already viewing the report, we don't need to navigate them to the report
if (props.hasMultipleParticipants && CONST.REGEX.NUMBER.test(reportID)) {
IOU.splitBill(
selectedParticipants,
props.currentUserPersonalDetails.login,
amount,
trimmedComment,
props.iou.selectedCurrencyCode,
props.preferredLocale,
reportID,
);
return;
}
// If the request is created from the global create menu, we also navigate the user to the group report
if (props.hasMultipleParticipants) {
IOU.splitBillAndOpenReport(
selectedParticipants,
props.currentUserPersonalDetails.login,
amount,
trimmedComment,
props.iou.selectedCurrencyCode,
props.preferredLocale,
);
return;
}
if (!selectedParticipants[0].login) {
// TODO - request to the policy expense chat. Not implemented yet!
// Will be implemented here: https://github.com/Expensify/Expensify/issues/270581
return;
}
IOU.requestMoney(
props.report,
Math.round(amount * 100),
props.iou.selectedCurrencyCode,
props.currentUserPersonalDetails.login,
selectedParticipants[0],
trimmedComment,
);
}, [amount, props.iou.comment, props.currentUserPersonalDetails.login, props.hasMultipleParticipants, props.iou.selectedCurrencyCode, props.preferredLocale, props.report, props.route]);

*
* @param {String} paymentMethodType
*/
const sendMoney = useCallback((paymentMethodType) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Taken from here

const sendMoney = useCallback((paymentMethodType) => {
const amountInDollars = Math.round(amount * 100);
const currency = props.iou.selectedCurrencyCode;
const trimmedComment = props.iou.comment.trim();
const participant = selectedOptions[0];
if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
IOU.sendMoneyElsewhere(
props.report,
amountInDollars,
currency,
trimmedComment,
props.currentUserPersonalDetails.login,
participant,
);
return;
}
if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.PAYPAL_ME) {
IOU.sendMoneyViaPaypal(
props.report,
amountInDollars,
currency,
trimmedComment,
props.currentUserPersonalDetails.login,
participant,
);
return;
}
if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
IOU.sendMoneyWithWallet(
props.report,
amountInDollars,
currency,
trimmedComment,
props.currentUserPersonalDetails.login,
participant,
);
}
}, [amount, props.iou.comment, selectedOptions, props.currentUserPersonalDetails.login, props.iou.selectedCurrencyCode, props.report]);

@cead22 cead22 changed the title refactor iou page by separating each step as individual screen Refactor iou page by separating each step as individual screen Apr 26, 2023
@bernhardoj
Copy link
Contributor Author

@PauloGasparSv @s77rt Ready for review!

@mountiny
Copy link
Contributor

More merge conflicts

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

Lots of changes! Just a few comments but it's looking good

* @param {String} reportID
*/
function startMoneyRequest(iouType, reportID = '') {
resetMoneyRequestInfo(`${iouType}${reportID}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to call this when we start a money request? It looks like we always call resetMoneyRequestInfo whenever we complete a command so is this redundant?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we still need this if you abandon the money request (close money request modal without completing the process)

Copy link
Contributor

Choose a reason for hiding this comment

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

But then at that point don't you want to continue the money request? I guess this is a NAB though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we always want to clear it when we open it from FAB or Composer. We're following the same pattern with Assign Task.

@@ -74,24 +106,63 @@ class MoneyRequestAmountPage extends React.Component {
}

componentDidMount() {
this.focusTextInput();
if (this.isEditing) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I wonder if we should handle these shouldReset / isEditing in a different way that is more DRY

Are these to handle new money request drafts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking to create a custom hook as the reset logic is being used in the amount, participant, confirmation, and description page, but both the amount and description page is still class component.

Are these to handle new money request drafts?

The reset logic is to prevent the user from doing a money request of type A with money request data of type B. For example, doing a send request with saved split request data. This is possible by directly accessing the URL (change from /send/new/confirmation to /split/new/confirmation). More context here #17964 (comment)

const selectedAmountAsString = this.props.iou.amount ? CurrencyUtils.convertToWholeUnit(this.props.iou.currency, this.props.iou.amount).toString() : '';
this.setState({
amount: selectedAmountAsString,
selection: {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this for?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, can you specify what you are referring to?

Copy link
Contributor

Choose a reason for hiding this comment

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

Selection

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To put the cursor at the end of the number. We're following the same logic from constructor

this.state = {
amount: selectedAmountAsString,
selectedCurrencyCode: props.iou.currency,
shouldUpdateSelection: true,
selection: {
start: selectedAmountAsString.length,
end: selectedAmountAsString.length,
},
};
}

@bernhardoj
Copy link
Contributor Author

bernhardoj commented Jun 21, 2023

Conflicts solved! Both issues here #17964 (comment) are solved too.

Added some default values in getParticipantsOptions in case the user does not exist in personal details. Previously, login and displayName is always returned from getPersonalDetailsByLogins.
bernhardoj@ef3d955#diff-733528d957ae6a80eb863637fa5d54278c89c6121998f3574fa8c0aba935daebL181-L187

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Great work on this one. @s77rt I hope this was tested thorough as this is a big refactoring :D

One change requested

},
{
getComponent: () => {
const MoneyRequestParticipantsPage = require('../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default;
Copy link
Contributor

Choose a reason for hiding this comment

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

That is a mistake no?

Suggested change
const MoneyRequestParticipantsPage = require('../../../pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage').default;
const MoneyRequestParticipantsPage = require('../../../pages/iou/steps/MoneyRequstParticipantsPage').default;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope. That is how it's structured
image

But I realized the folder name has a typo Requst 🤣. Should we fix it now? I'm afraid changing it will make the review hard.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that is confusing.

Lets fix it in a follow up

Comment on lines +212 to +214
function getParticipantsOptions(participants, personalDetails) {
const details = getPersonalDetailsForAccountIDs(_.pluck(participants, 'accountID'), personalDetails);
return _.map(participants, (participant) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we have to change how this loop works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because participants is now an array of objects, it looks like this: [{accountID: 1, selected: true, ...}]. Previously, it was a report object and we take the participantAccountIDs which is just an array.
image

Also, we need selected attribute from each participant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks

src/libs/actions/IOU.js Outdated Show resolved Hide resolved
@@ -213,20 +213,22 @@ function getParticipantsOptions(participants, personalDetails) {
const details = getPersonalDetailsForAccountIDs(_.pluck(participants, 'accountID'), personalDetails);
return _.map(participants, (participant) => {
const detail = details[participant.accountID];
const login = detail.login || participant.login;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we are falling back to participant.login? i.e. if login is undefined, what would be wrong with that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The login is needed for displayName, alternateText, and icons.name

@@ -213,20 +213,22 @@ function getParticipantsOptions(participants, personalDetails) {
const details = getPersonalDetailsForAccountIDs(_.pluck(participants, 'accountID'), personalDetails);
return _.map(participants, (participant) => {
const detail = details[participant.accountID];
const login = detail.login || participant.login;
const displayName = detail.displayName || LocalePhoneNumber.formatPhoneNumber(login);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need a fallback here either. getPersonalDetailsForAccountIDs will return the data from onyx and displayName seems always set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The fallback is for a case where the user doesn't exist, for example when you search a random email. More explanation in my previous comment here #17964 (comment)

Comment on lines 223 to 225
alternateText: Str.isSMSLogin(detail.login || '') ? LocalePhoneNumber.formatPhoneNumber(detail.login) : detail.login || detail.displayName,
alternateText: LocalePhoneNumber.formatPhoneNumber(login) || displayName,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this change for? login is not guaranteed to be a phone number

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just simplifying it actually 😅. LocalePhoneNumber.formatPhoneNumber(login) will return it untouched if it's not a phone number.

function formatPhoneNumber(number) {
if (!number) {
return '';
}
const numberWithoutSMSDomain = Str.removeSMSDomain(number);
const parsedPhoneNumber = parsePhoneNumber(numberWithoutSMSDomain);
// return the string untouched if it's not a phone number
if (!parsedPhoneNumber.valid) {
if (parsedPhoneNumber.number && parsedPhoneNumber.number.international) {
return parsedPhoneNumber.number.international;
}
return numberWithoutSMSDomain;
}

We also did (use LocalePhoneNumber.formatPhoneNumber(login) without extra checking) that previously here
bernhardoj@ef3d955#diff-733528d957ae6a80eb863637fa5d54278c89c6121998f3574fa8c0aba935daebL181-L187

@@ -140,7 +140,7 @@ class MoneyRequestParticipantsSelector extends Component {
* @param {Object} option
*/
addSingleParticipant(option) {
this.props.onAddParticipants([{accountID: option.accountID, isPolicyExpenseChat: option.isPolicyExpenseChat, reportID: option.reportID, selected: true}]);
this.props.onAddParticipants([{accountID: option.accountID, login: option.login, isPolicyExpenseChat: option.isPolicyExpenseChat, reportID: option.reportID, selected: true}]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need the login here? Can't we drop login now and just relay on accountID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed for all things above.

Copy link
Contributor

@thienlnam thienlnam left a comment

Choose a reason for hiding this comment

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

Alright, going to send it since Vit's comments were addressed and so we can get this tested heavily through QA

Nice work on this!

@thienlnam thienlnam merged commit 7c04c2f into Expensify:main Jun 21, 2023
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

Navigation.goBack(ROUTES.getMoneyRequestRoute(this.iouType, this.reportID), true);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This code need to be documented better. It is not obvious at all what is happening here. Please explain in the code what "reset" means in this context and what an iou.id even is? When did we start adding "id" to the IOU and why...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We start to add an ID to avoid a problem explained here #17964 (comment). The ID is iouType + reportID

const moneyRequestId = `${this.iouType}${this.reportID}`;
const shouldReset = this.props.iou.id !== moneyRequestId;

Every time we start a money request, it will set an ID to it

App/src/libs/actions/IOU.js

Lines 1298 to 1301 in e6c4b4e

function startMoneyRequest(iouType, reportID = '') {
resetMoneyRequestInfo(`${iouType}${reportID}`);
Navigation.navigate(ROUTES.getMoneyRequestRoute(iouType, reportID));
}

what "reset" means

I think this can be found in the function itself.

/**
* Reset money request info from the store with its initial value
* @param {String} id
*/
function resetMoneyRequestInfo(id = '') {

Inspired from

/**
* Clears out the task info from the store
*/
function clearOutTaskInfo() {
Onyx.set(ONYXKEYS.TASK, null);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I would appreciate it if the code could be annotated more thoroughly. Enhancing code documentation is essential for our team's effectiveness. Can we kindly address this?

Regarding the current solution, I remain uncertain about its efficiency. It appears more like a workaround to me, rather than a refined resolution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can create a follow-up PR to add the comment and fix this typo #17964 (comment)

But, should we wait until the regression period ends before opening the PR?

Regarding the current solution, I remain uncertain about its efficiency. It appears more like a workaround to me, rather than a refined resolution.

I can't say for sure whether it's a workaround or not, but at least that's what we can come up with considering so many cases using Onyx.

Copy link
Member

Choose a reason for hiding this comment

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

@bernhardoj It might be good to document the code now if not done already. I am also wondering about the logic done here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but to do that, I'm thinking of a plan.

Currently, this reset logic exists on the Money request amount, participant, description, and confirm page, all basically have the same logic. I don't want to repeatedly write the comment on each page, so what about we create a custom hook called useMoneyRequestEffect that handles this logic? If you agree,

  1. We need to migrate MoneyRequestDescriptionPage to a functional component, it's a fairly simple page, I can handle that.
  2. Currently, MoneyRequestAmountPage is being used for the amount and edit amount page.
    getComponent: () => {
    const MoneyRequestAmountPage = require('../../../pages/iou/steps/MoneyRequestAmountPage').default;
    return MoneyRequestAmountPage;
    },
    name: 'Money_Request',
    },
    {
    getComponent: () => {
    const MoneyRequestEditAmountPage = require('../../../pages/iou/steps/MoneyRequestAmountPage').default;
    return MoneyRequestEditAmountPage;
    },
    name: 'Money_Request_Amount',

    We actually want this logic for the edit amount page only and I don't think conditionally using hook is correct.
if (isEditing.current) useMoneyRequestEffect();

I see we have an issue #23149 to make MoneyRequestAmountPage more reusable, we can wait for this to complete and then separate the page for the edit amount page.

OR

Replace the Onyx with Context approach 😄. This will completely remove this reset logic thing.

@parasharrajat @marcaaron

Copy link
Member

Choose a reason for hiding this comment

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

I agree with that issue. IMO, the logic is fairly complex and confusing. Refactor is a good thing to do. We can wait on that refactor or you can help write proper comments during the refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So, migrating description page to functional and create useMoneyRequestEffect after MoneyRequestAmountPage refactor is done. Is that correct?

Copy link
Member

Choose a reason for hiding this comment

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

Kind of. let's wait and see the end result of refactoring and then we can re-evaluate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@parasharrajat the refactor is done. What is the process here to do the follow-up? Should I just open the PR?

As a reminder, here is the plan I have:

  1. Separate edit amount from NewRequestAmountPage to its own page
  2. Create a new hook called useMoneyRequestEffect that will contain this logic
    useEffect(() => {
    const moneyRequestId = `${iouType}${reportID}`;
    const shouldReset = iou.id !== moneyRequestId;
    if (shouldReset) {
    IOU.resetMoneyRequestInfo(moneyRequestId);
    }
    if (_.isEmpty(iou.participants) || (iou.amount === 0 && !iou.receiptPath) || shouldReset) {
    Navigation.goBack(ROUTES.getMoneyRequestRoute(iouType, reportID), true);
    }
    }, [iou.id, iou.participants, iou.amount, iou.receiptPath, iouType, reportID]);
  3. Replace the above logic (and on other pages) with the new hook.
  4. Update the comment in the new hook

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/thienlnam in version: 1.3.31-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.31-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 cancelled 🔪
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.3.31-3 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

}

this.setState({selectedCurrencyCode: this.props.iou.selectedCurrencyCode});
if (prevProps.iou.amount !== this.props.iou.amount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This has caused a small regression in #22361
The dot wasn't removed from the end of amount when navigating back to the screen (in an edge case where amount is the same, more details here)
We resolved this by moving CurrencyUtils.convertToWholeUnit logic into a separate method and calling it in useFocusEffect (when page is focused)

amount: PropTypes.number,
participants: PropTypes.arrayOf(
PropTypes.shape({
accountID: PropTypes.number,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please come back and update this code to include comments on all these properties?

Add descriptions to all propTypes using a single line comment above the definition. No need to document the types, but add some context for each property so that other developers understand the intended use.

https://github.com/Expensify/Style-Guides/blob/main/react.md#things-to-do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, here is the PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.