-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[TS migration] Migrate 'ReportParticipants' page to TypeScript #34882
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
Changes from all commits
075eb78
7d4c8eb
0adfeab
89421fa
5311ff6
73cb922
2af51b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,75 +1,61 @@ | ||
| import lodashGet from 'lodash/get'; | ||
| import PropTypes from 'prop-types'; | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import _ from 'underscore'; | ||
| import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import OptionsList from '@components/OptionsList'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import compose from '@libs/compose'; | ||
| import * as LocalePhoneNumber from '@libs/LocalePhoneNumber'; | ||
| import type * as Localize from '@libs/Localize'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import type {OptionData} from '@libs/ReportUtils'; | ||
| import * as UserUtils from '@libs/UserUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import type {TranslationPaths} from '@src/languages/types'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type {PersonalDetailsList, Report} from '@src/types/onyx'; | ||
| import type {WithReportOrNotFoundProps} from './home/report/withReportOrNotFound'; | ||
| import withReportOrNotFound from './home/report/withReportOrNotFound'; | ||
| import personalDetailsPropType from './personalDetailsPropType'; | ||
| import reportPropTypes from './reportPropTypes'; | ||
|
|
||
| const propTypes = { | ||
| /* Onyx Props */ | ||
|
|
||
| /** The personal details of the person who is logged in */ | ||
| personalDetails: PropTypes.objectOf(personalDetailsPropType), | ||
|
|
||
| /** The active report */ | ||
| report: reportPropTypes.isRequired, | ||
|
|
||
| /** Route params */ | ||
| route: PropTypes.shape({ | ||
| params: PropTypes.shape({ | ||
| /** Report ID passed via route r/:reportID/participants */ | ||
| reportID: PropTypes.string, | ||
| }), | ||
| }).isRequired, | ||
|
|
||
| ...withLocalizePropTypes, | ||
| type ReportParticipantsPageOnyxProps = { | ||
| /** Personal details of all the users */ | ||
| personalDetails: OnyxEntry<PersonalDetailsList>; | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| personalDetails: {}, | ||
| }; | ||
| type ReportParticipantsPageProps = ReportParticipantsPageOnyxProps & WithReportOrNotFoundProps; | ||
|
|
||
| /** | ||
| * Returns all the participants in the active report | ||
| * | ||
| * @param {Object} report The active report object | ||
| * @param {Object} personalDetails The personal details of the users | ||
| * @param {Object} translate The localize | ||
| * @return {Array} | ||
| * @param report The active report object | ||
| * @param personalDetails The personal details of the users | ||
| * @param translate The localize | ||
| */ | ||
| const getAllParticipants = (report, personalDetails, translate) => | ||
| _.chain(ReportUtils.getVisibleMemberIDs(report)) | ||
| const getAllParticipants = ( | ||
| report: OnyxEntry<Report>, | ||
| personalDetails: OnyxEntry<PersonalDetailsList>, | ||
| translate: <TKey extends TranslationPaths>(phraseKey: TKey, ...phraseParameters: Localize.PhraseParameters<Localize.Phrase<TKey>>) => string, | ||
| ): OptionData[] => | ||
| ReportUtils.getVisibleMemberIDs(report) | ||
| .map((accountID, index) => { | ||
| const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''}); | ||
| const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden'); | ||
| const userPersonalDetail = personalDetails?.[accountID]; | ||
| const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail?.login ?? '') ?? translate('common.hidden'); | ||
| const displayName = PersonalDetailsUtils.getDisplayNameOrDefault(userPersonalDetail); | ||
|
|
||
| return { | ||
| alternateText: userLogin, | ||
| displayName, | ||
| accountID: userPersonalDetail.accountID, | ||
| accountID: userPersonalDetail?.accountID ?? accountID, | ||
|
JKobrynski marked this conversation as resolved.
|
||
| icons: [ | ||
| { | ||
| id: accountID, | ||
| source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID), | ||
| source: UserUtils.getAvatar(userPersonalDetail?.avatar ?? '', accountID), | ||
| name: userLogin, | ||
| type: CONST.ICON_TYPE_AVATAR, | ||
| }, | ||
|
|
@@ -79,16 +65,18 @@ const getAllParticipants = (report, personalDetails, translate) => | |
| text: displayName, | ||
| tooltipText: userLogin, | ||
| participantsList: [{accountID, displayName}], | ||
| reportID: report?.reportID ?? '', | ||
| }; | ||
| }) | ||
| .sortBy((participant) => participant.displayName.toLowerCase()) | ||
| .value(); | ||
| .sort((a, b) => a.displayName.localeCompare(b.displayName.toLowerCase())); | ||
|
|
||
| function ReportParticipantsPage(props) { | ||
| function ReportParticipantsPage({report, personalDetails}: ReportParticipantsPageProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({ | ||
|
|
||
| const participants = getAllParticipants(report, personalDetails, translate).map((participant) => ({ | ||
| ...participant, | ||
| isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID), | ||
| isDisabled: participant?.accountID ? ReportUtils.isOptimisticPersonalDetail(participant.accountID) : false, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coming from https://github.com/Expensify/App/pull/35385/files#r1472924653:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc: @JKobrynski |
||
| })); | ||
|
|
||
| return ( | ||
|
|
@@ -97,20 +85,20 @@ function ReportParticipantsPage(props) { | |
| testID={ReportParticipantsPage.displayName} | ||
| > | ||
| {({safeAreaPaddingBottomStyle}) => ( | ||
| <FullPageNotFoundView shouldShow={_.isEmpty(props.report) || ReportUtils.isArchivedRoom(props.report)}> | ||
| <FullPageNotFoundView shouldShow={!report || ReportUtils.isArchivedRoom(report)}> | ||
| <HeaderWithBackButton | ||
| title={props.translate( | ||
| ReportUtils.isChatRoom(props.report) || | ||
| ReportUtils.isPolicyExpenseChat(props.report) || | ||
| ReportUtils.isChatThread(props.report) || | ||
| ReportUtils.isTaskReport(props.report) || | ||
| ReportUtils.isMoneyRequestReport(props.report) | ||
| title={translate( | ||
| ReportUtils.isChatRoom(report) || | ||
| ReportUtils.isPolicyExpenseChat(report) || | ||
| ReportUtils.isChatThread(report) || | ||
| ReportUtils.isTaskReport(report) || | ||
| ReportUtils.isMoneyRequestReport(report) | ||
| ? 'common.members' | ||
| : 'common.details', | ||
| )} | ||
| /> | ||
| <View style={[styles.containerWithSpaceBetween, styles.pointerEventsBoxNone]}> | ||
| {Boolean(participants.length) && ( | ||
| {participants?.length && ( | ||
| <OptionsList | ||
| sections={[ | ||
| { | ||
|
|
@@ -120,7 +108,10 @@ function ReportParticipantsPage(props) { | |
| indexOffset: 0, | ||
| }, | ||
| ]} | ||
| onSelectRow={(option) => { | ||
| onSelectRow={(option: OptionData) => { | ||
| if (!option.accountID) { | ||
| return; | ||
| } | ||
| Navigation.navigate(ROUTES.PROFILE.getRoute(option.accountID)); | ||
| }} | ||
| hideSectionHeaders | ||
|
|
@@ -139,16 +130,12 @@ function ReportParticipantsPage(props) { | |
| ); | ||
| } | ||
|
|
||
| ReportParticipantsPage.propTypes = propTypes; | ||
| ReportParticipantsPage.defaultProps = defaultProps; | ||
| ReportParticipantsPage.displayName = 'ReportParticipantsPage'; | ||
|
|
||
| export default compose( | ||
| withLocalize, | ||
| withReportOrNotFound(), | ||
| withOnyx({ | ||
| export default withReportOrNotFound()( | ||
| withOnyx<ReportParticipantsPageProps, ReportParticipantsPageOnyxProps>({ | ||
|
JKobrynski marked this conversation as resolved.
|
||
| personalDetails: { | ||
| key: ONYXKEYS.PERSONAL_DETAILS_LIST, | ||
| }, | ||
| }), | ||
| )(ReportParticipantsPage); | ||
| })(ReportParticipantsPage), | ||
| ); | ||
Uh oh!
There was an error while loading. Please reload this page.