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 MoneyTemporaryForRefactorRequestConfirmationList.js component to TypeScript #37181

Merged
merged 46 commits into from
Apr 11, 2024

Conversation

allgandalf
Copy link
Contributor

@allgandalf allgandalf commented Feb 25, 2024

Details

This is a typescript migration issue, the file was migrated from js to tsx

Fixed Issues

$ #36130
PROPOSAL: #36130 (comment)

Tests

Same as QA step

  • Verify that no errors appear in the JS console

Offline tests

Same as QA step

QA Steps

  1. Go to workspace chat/ 1:1 chat (Money Request)
  2. Click on + icon
  3. select Money Request
  4. Perform all the steps and get on the final confirmation step
    (This is a migration PR, so test out all options available on the final confirmation page)
  • 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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 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(theme.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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • 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.

Screenshots/Videos

MacOS: Chrome / Safari
simplescreenrecorder-2024-04-04_05.04.47.mp4
MacOS: Desktop
simplescreenrecorder-2024-04-04_05.08.08.mp4
iOS: mWeb Safari
WhatsApp.Video.2024-04-04.at.5.17.22.AM.1.mp4
Android: mWeb Chrome
simplescreenrecorder-2024-04-04_05.24.57.mp4
iOS: Native
WhatsApp.Video.2024-04-04.at.5.17.22.AM.mp4
Android: Native
simplescreenrecorder-2024-04-04_05.27.33.mp4

@allgandalf
Copy link
Contributor Author

Still working on the PR will update once it is ready for review

@blazejkustra
Copy link
Contributor

Is this ready for review? @GandalfGwaihir

@allgandalf
Copy link
Contributor Author

will be ready by monday, have to resolve the merge conflicts now 😅

@allgandalf allgandalf marked this pull request as ready for review March 6, 2024 18:33
@allgandalf allgandalf requested a review from a team as a code owner March 6, 2024 18:33
@melvin-bot melvin-bot bot requested review from hoangzinh and removed request for a team March 6, 2024 18:33
Copy link

melvin-bot bot commented Mar 6, 2024

@hoangzinh Please 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]

@allgandalf
Copy link
Contributor Author

PR is ready for review @hoangzinh @blazejkustra

@allgandalf
Copy link
Contributor Author

allgandalf commented Mar 6, 2024

@hoangzinh @blazejkustra , i can't seem to figure out the exact type error below:

https://github.com/Expensify/App/pull/37181/files#diff-3df3ec8a95215e74368f2f19e50eb6e7383e51a830ffd65ab32ca4b809f97aa7R353

When i type it as number it says number not assignable to string and when i type it as a string it says string not assignable to number, a little help over here please :)

Copy link
Contributor

@blazejkustra blazejkustra left a comment

Choose a reason for hiding this comment

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

The translate error happens because params for each translation key is different:
iou.splitAmount:

type RequestAmountParams = {amount: string};

iou.requestAmount

type SplitAmountParams = {amount: number};

I think you can adjust one so they use the same type

@blazejkustra
Copy link
Contributor

@GandalfGwaihir Bumping this 😄

@allgandalf
Copy link
Contributor Author

sorry for not updating, actually this PR is similar to #37716, this was approved today and will get merged, should we wait to see how this PR performs in staging? the components used are exactly same, so maybe we want to wait but interested to hear what you think, Also i will comment on the review of yours bt today EOD and make necessary changes

@allgandalf
Copy link
Contributor Author

Ah these merge conflicts I tell you, umm I see a discussion going into this android built, Can't we get an internal engineer to approve this making an exception ? These changes didn't touch any native components, and as we tested on all other platforms I guess it would be okay to skip (If the android built didn't get fixed)! , what do you say @hoangzinh ?

@allgandalf
Copy link
Contributor Author

Also typescript fail is unrelated, it is failing in main

Copy link
Contributor

@hoangzinh hoangzinh left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

melvin-bot bot commented Apr 11, 2024

We did not find an internal engineer to review this PR, trying to assign a random engineer to #36130 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@hoangzinh
Copy link
Contributor

@GandalfGwaihir I can build it via VS so no worry. Reg TS, can you report it in the slack?

@melvin-bot melvin-bot bot requested a review from youssef-lr April 11, 2024 01:33
@fabioh8010
Copy link
Contributor

@GandalfGwaihir @hoangzinh Looks like TS checks is passing on main now, so you can just update the branch and it should be enough!

@allgandalf
Copy link
Contributor Author

merged main, lets hope for the best 😅

@fabioh8010
Copy link
Contributor

@GandalfGwaihir I've checked your PR and here is my suggestion to fix the TS issues:

diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts
index 85f5c414db..ad4632f96f 100644
--- a/src/libs/ReportUtils.ts
+++ b/src/libs/ReportUtils.ts
@@ -418,7 +418,7 @@ type OptionData = {
     notificationPreference?: NotificationPreference | null;
     isDisabled?: boolean | null;
     name?: string | null;
-    isSelfDM?: boolean | null;
+    isSelfDM?: boolean;
     reportID?: string;
     enabled?: boolean;
     data?: Partial<TaxRate>;
diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
index 897af48f05..da12e30a00 100644
--- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
+++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx
@@ -2,7 +2,6 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
 import {View} from 'react-native';
 import type {OnyxEntry} from 'react-native-onyx';
 import {withOnyx} from 'react-native-onyx';
-import type {ValueOf} from 'type-fest';
 import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
 import HeaderWithBackButton from '@components/HeaderWithBackButton';
 import * as Expensicons from '@components/Icon/Expensicons';
@@ -30,11 +29,12 @@ import ROUTES from '@src/ROUTES';
 import type SCREENS from '@src/SCREENS';
 import type {Policy, PolicyCategories, PolicyTagList} from '@src/types/onyx';
 import type {Participant} from '@src/types/onyx/IOU';
+import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage';
 import type {Receipt} from '@src/types/onyx/Transaction';
 import type {WithFullTransactionOrNotFoundProps} from './withFullTransactionOrNotFound';
 import withFullTransactionOrNotFound from './withFullTransactionOrNotFound';
-import withWritableReportOrNotFound from './withWritableReportOrNotFound';
 import type {WithWritableReportOrNotFoundProps} from './withWritableReportOrNotFound';
+import withWritableReportOrNotFound from './withWritableReportOrNotFound';
 
 type IOURequestStepConfirmationOnyxProps = {
     /** The policy of the report */
@@ -97,7 +97,7 @@ function IOURequestStepConfirmation({
             transaction?.participants?.map((participant) => {
                 const participantAccountID = participant.accountID ?? 0;
                 return participantAccountID ? OptionsListUtils.getParticipantsOption(participant, personalDetails) : OptionsListUtils.getReportOption(participant);
-            }),
+            }) ?? [],
         [transaction?.participants, personalDetails],
     );
     const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]);
@@ -422,11 +422,9 @@ function IOURequestStepConfirmation({
 
     /**
      * Checks if user has a GOLD wallet then creates a paid IOU report on the fly
-     *
-     * @param {String} paymentMethodType
      */
     const sendMoney = useCallback(
-        (paymentMethodType: ValueOf<typeof CONST.IOU.PAYMENT_TYPE>) => {
+        (paymentMethod: PaymentMethodType | undefined) => {
             const currency = transaction?.currency;
 
             const trimmedComment = transaction?.comment?.comment ? transaction.comment.comment.trim() : '';
@@ -437,12 +435,12 @@ function IOURequestStepConfirmation({
                 return;
             }
 
-            if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
+            if (paymentMethod === CONST.IOU.PAYMENT_TYPE.ELSEWHERE) {
                 IOU.sendMoneyElsewhere(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant);
                 return;
             }
 
-            if (paymentMethodType === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
+            if (paymentMethod === CONST.IOU.PAYMENT_TYPE.EXPENSIFY) {
                 IOU.sendMoneyWithWallet(report, transaction.amount, currency, trimmedComment, currentUserPersonalDetails.accountID, participant);
             }
         },
@@ -490,12 +488,11 @@ function IOURequestStepConfirmation({
                     />
                     {isLoading && <FullScreenLoadingIndicator />}
                     <View style={[styles.flex1, isLoading && styles.opacity0]}>
-                        {/* @ts-expect-error TODO: Remove this once MoneyRequestConfirmationList (https://github.com/Expensify/App/issues/36130) is migrated to TypeScript. */}
                         <MoneyRequestConfirmationList
                             transaction={transaction}
                             hasMultipleParticipants={iouType === CONST.IOU.TYPE.SPLIT}
                             selectedParticipants={participants}
-                            iouAmount={transaction?.amount}
+                            iouAmount={transaction?.amount ?? 0}
                             iouComment={transaction?.comment.comment ?? ''}
                             iouCurrencyCode={transaction?.currency}
                             iouIsBillable={transaction?.billable}

@allgandalf
Copy link
Contributor Author

allgandalf commented Apr 11, 2024

let me fix them ASAP, thanks for the help @fabioh8010

@allgandalf
Copy link
Contributor Author

Fixed the type check fail, let's get this one merged ASAP, @youssef-lr 🚀

<MoneyRequestConfirmationList
transaction={transaction}
hasMultipleParticipants={iouType === CONST.IOU.TYPE.SPLIT}
selectedParticipants={participants}
iouAmount={transaction?.amount}
iouAmount={transaction?.amount ?? 0}
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 this is necessary, unless it was causing a TS error?

Suggested change
iouAmount={transaction?.amount ?? 0}
iouAmount={transaction?.amount}

Copy link
Contributor

Choose a reason for hiding this comment

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

It is causing an TS error @youssef-lr, I checked and it is a required prop

Copy link
Contributor

Choose a reason for hiding this comment

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

okay cool! Testing now locally, then I'll merge if nothing comes up

Copy link
Contributor

@youssef-lr youssef-lr left a comment

Choose a reason for hiding this comment

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

LGTM!

@youssef-lr youssef-lr merged commit ffc8ea9 into Expensify:main Apr 11, 2024
18 checks passed
@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.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/youssef-lr in version: 1.4.63-0 🚀

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

@aldo-expensify
Copy link
Contributor

I think this PR may be causing the deploy blocker: #40476

@allgandalf
Copy link
Contributor Author

@aldo-expensify , this is a known issue which was caused by another PR, we have a slack discussion on this as well, let me attach that here

@allgandalf
Copy link
Contributor Author

here is the slack convo: https://expensify.slack.com/archives/C01GTK53T8Q/p1713382047884229

Long story short, this was caused by #38709

And is already being fixed here #40385

@aldo-expensify
Copy link
Contributor

Yeah, sorry I just noticed that too. Thanks for all the info!

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.4.63-21 🚀

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

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.

7 participants