From 08337c3bc03cea5a74ee0aa22818826fb3f4b964 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Sep 2023 15:31:39 +0700 Subject: [PATCH 01/21] leave room when has no comment --- src/libs/actions/Report.js | 11 +++++++---- src/pages/home/ReportScreen.js | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 2a34c839a94e..759f245ac0a5 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1777,8 +1777,9 @@ function getCurrentUserAccountID() { * Leave a report by setting the state to submitted and closed * * @param {String} reportID + * @param {Boolean} shouldNavigate should navigate after leaving room or not */ -function leaveRoom(reportID) { +function leaveRoom(reportID, shouldNavigate = true) { const report = lodashGet(allReports, [reportID], {}); const reportKeys = _.keys(report); API.write( @@ -1819,10 +1820,12 @@ function leaveRoom(reportID) { }, ); Navigation.dismissModal(); - if (Navigation.getTopmostReportId() === reportID) { - Navigation.goBack(); + if (shouldNavigate) { + if (Navigation.getTopmostReportId() === reportID) { + Navigation.goBack(); + } + navigateToConciergeChat(); } - navigateToConciergeChat(); } /** diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 8528b8f213a9..13e77923ad5c 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,6 +1,6 @@ import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react'; import {withOnyx} from 'react-native-onyx'; -import {useFocusEffect} from '@react-navigation/native'; +import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import PropTypes from 'prop-types'; import {View} from 'react-native'; import lodashGet from 'lodash/get'; @@ -151,6 +151,7 @@ function ReportScreen({ const flatListRef = useRef(); const reactionListRef = useRef(); const prevReport = usePrevious(report); + const isFocused = useIsFocused(); const [skeletonViewContainerHeight, setSkeletonViewContainerHeight] = useState(0); const [isBannerVisible, setIsBannerVisible] = useState(true); @@ -312,6 +313,18 @@ function ReportScreen({ [report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete], ); + useEffect(() => { + if (isFocused) { + return; + } + + if (ReportUtils.isThread(report) && report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + Report.leaveRoom(report.reportID, false); + } + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isFocused]); + return ( Date: Wed, 8 Nov 2023 17:12:29 +0700 Subject: [PATCH 02/21] fix conflict --- src/pages/home/ReportScreen.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index fd741f051618..7abf395644f8 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,11 +1,3 @@ -<<<<<<< HEAD -import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import {useFocusEffect, useIsFocused} from '@react-navigation/native'; -import PropTypes from 'prop-types'; -import {View} from 'react-native'; -======= ->>>>>>> main import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; From 0c63dac9d928589456f66e18d529cdf6660d768d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 8 Nov 2023 17:26:10 +0700 Subject: [PATCH 03/21] fix lint --- src/components/AttachmentModal.js | 2 ++ src/libs/Navigation/AppNavigator/AuthScreens.js | 2 +- src/pages/ReportAvatar.js | 2 +- src/pages/settings/Profile/ProfileAvatar.js | 4 ++-- src/pages/workspace/WorkspaceAvatar.js | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index c541b47ea9c4..098723f941e6 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -41,6 +41,8 @@ import * as Illustrations from './Icon/Illustrations'; import Modal from './Modal'; import SafeAreaConsumer from './SafeAreaConsumer'; import transactionPropTypes from './transactionPropTypes'; +import withLocalize, {withLocalizePropTypes} from './withLocalize'; +import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; /** * Modal render prop component that exposes modal launching triggers that can be used diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 20971041a0d0..719bad9f2c06 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -326,7 +326,7 @@ function AuthScreens({isUsingMemoryOnlyKeys, lastUpdateIDAppliedToClient, sessio getComponent={loadReportAttachments} listeners={modalScreenListeners} /> - `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, }), -)(ReportAvatar); \ No newline at end of file +)(ReportAvatar); diff --git a/src/pages/settings/Profile/ProfileAvatar.js b/src/pages/settings/Profile/ProfileAvatar.js index 3faff62231f1..948636c4a02f 100644 --- a/src/pages/settings/Profile/ProfileAvatar.js +++ b/src/pages/settings/Profile/ProfileAvatar.js @@ -2,12 +2,12 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; import React from 'react'; import {withOnyx} from 'react-native-onyx'; +import _ from 'underscore'; import AttachmentModal from '@components/AttachmentModal'; import participantPropTypes from '@components/participantPropTypes'; import Navigation from '@libs/Navigation/Navigation'; import * as UserUtils from '@libs/UserUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import _ from 'underscore'; const propTypes = { /** React Navigation route */ @@ -60,4 +60,4 @@ export default withOnyx({ isLoadingApp: { key: ONYXKEYS.IS_LOADING_APP, }, -})(ProfileAvatar); \ No newline at end of file +})(ProfileAvatar); diff --git a/src/pages/workspace/WorkspaceAvatar.js b/src/pages/workspace/WorkspaceAvatar.js index da6f4891b2a5..d3e2f700a353 100644 --- a/src/pages/workspace/WorkspaceAvatar.js +++ b/src/pages/workspace/WorkspaceAvatar.js @@ -78,4 +78,4 @@ export default withOnyx({ isLoadingReportData: { key: ONYXKEYS.IS_LOADING_REPORT_DATA, }, -})(WorkspaceAvatar); \ No newline at end of file +})(WorkspaceAvatar); From 30f7f4b450129cbd6936c72ff69dd154dfdf9a19 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 15 Nov 2023 21:36:28 +0700 Subject: [PATCH 04/21] get full size avatar --- src/pages/settings/Profile/ProfileAvatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/ProfileAvatar.js b/src/pages/settings/Profile/ProfileAvatar.js index 948636c4a02f..6fe6ba9c0baa 100644 --- a/src/pages/settings/Profile/ProfileAvatar.js +++ b/src/pages/settings/Profile/ProfileAvatar.js @@ -40,7 +40,7 @@ function ProfileAvatar(props) { { Navigation.goBack(); }} From c781431011d147a1ed27a8a158bfa700e8066b00 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 15 Nov 2023 21:59:51 +0700 Subject: [PATCH 05/21] add get full size for all --- src/pages/ReportAvatar.js | 4 +++- src/pages/workspace/WorkspaceAvatar.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportAvatar.js b/src/pages/ReportAvatar.js index b3d14f169853..a40edb2226d9 100644 --- a/src/pages/ReportAvatar.js +++ b/src/pages/ReportAvatar.js @@ -7,6 +7,7 @@ import AttachmentModal from '@components/AttachmentModal'; import compose from '@libs/compose'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; +import * as UserUtils from '@libs/UserUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import reportPropTypes from './reportPropTypes'; @@ -60,11 +61,12 @@ const defaultProps = { function ReportAvatar(props) { const isArchivedRoom = ReportUtils.isArchivedRoom(props.report); const policyName = isArchivedRoom ? props.report.oldPolicyName : lodashGet(props.policy, 'name', ''); + const avatarURL = lodashGet(props.policy, 'avatar', '') || ReportUtils.getDefaultWorkspaceAvatar(policyName); return ( { Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(props.report.reportID)); }} diff --git a/src/pages/workspace/WorkspaceAvatar.js b/src/pages/workspace/WorkspaceAvatar.js index d3e2f700a353..8495decb842e 100644 --- a/src/pages/workspace/WorkspaceAvatar.js +++ b/src/pages/workspace/WorkspaceAvatar.js @@ -6,6 +6,7 @@ import _ from 'underscore'; import AttachmentModal from '@components/AttachmentModal'; import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; +import * as UserUtils from '@libs/UserUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -51,11 +52,12 @@ const defaultProps = { }; function WorkspaceAvatar(props) { + const avatarURL = lodashGet(props.policy, 'avatar', '') || ReportUtils.getDefaultWorkspaceAvatar(lodashGet(props.policy, 'name', '')); return ( { Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(props.route))); }} From a79b81b2c61643929e50090cdc2aa2ac8e97436b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 27 Nov 2023 18:22:57 +0700 Subject: [PATCH 06/21] fix default avatar display briefly for report avatar --- src/pages/ReportAvatar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportAvatar.js b/src/pages/ReportAvatar.js index a40edb2226d9..a29750636061 100644 --- a/src/pages/ReportAvatar.js +++ b/src/pages/ReportAvatar.js @@ -73,7 +73,7 @@ function ReportAvatar(props) { isWorkspaceAvatar originalFileName={policyName} shouldShowNotFoundPage={_.isEmpty(props.report.reportID) && !props.isLoadingReportData} - isLoading={_.isEmpty(props.report) && props.isLoadingReportData} + isLoading={(_.isEmpty(props.report.reportID) || _.isEmpty(props.policy.id)) && props.isLoadingReportData} /> ); } From 609177efede93a87b8228c7a2587b5e63538c9d0 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 29 Nov 2023 16:01:42 +0700 Subject: [PATCH 07/21] fix lint --- src/ROUTES.ts | 6 +++--- src/libs/Navigation/types.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 20dad2109c09..a8aebf69a7b1 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -136,12 +136,12 @@ const ROUTES = { SETTINGS_STATUS_SET: 'settings/profile/status/set', PROFILE_AVATAR: { route: 'a/:accountID/avatar', - getRoute: (accountID: string) => `a/${accountID}/avatar`, + getRoute: (accountID: string) => `a/${accountID}/avatar` as const, }, WORKSPACE_AVATAR: { route: 'workspace/:policyID/avatar', - getRoute: (policyID: string) => `workspace/${policyID}/avatar`, + getRoute: (policyID: string) => `workspace/${policyID}/avatar` as const, }, KEYBOARD_SHORTCUTS: 'keyboard-shortcuts', @@ -157,7 +157,7 @@ const ROUTES = { }, REPORT_AVATAR: { route: 'r/:reportID/avatar', - getRoute: (reportID: string) => `r/${reportID}/avatar`, + getRoute: (reportID: string) => `r/${reportID}/avatar` as const, }, EDIT_REQUEST: { route: 'r/:threadReportID/edit/:field', diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index 41df21d8e237..6e7aff6df71f 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -390,6 +390,15 @@ type AuthScreensParamList = { reportID: string; source: string; }; + [SCREENS.PROFILE_AVATAR]: { + accountID: string; + }; + [SCREENS.WORKSPACE_AVATAR]: { + policyID: string; + }; + [SCREENS.REPORT_AVATAR]: { + reportID: string; + }; [SCREENS.NOT_FOUND]: undefined; [NAVIGATORS.RIGHT_MODAL_NAVIGATOR]: NavigatorScreenParams; [SCREENS.DESKTOP_SIGN_IN_REDIRECT]: undefined; From 090d4244b8ed5c2541c532ad82727b487dba65c0 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 29 Nov 2023 22:04:23 +0700 Subject: [PATCH 08/21] fix original file name --- src/pages/ReportAvatar.js | 2 +- src/pages/settings/Profile/ProfileAvatar.js | 1 + src/pages/workspace/WorkspaceAvatar.js | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportAvatar.js b/src/pages/ReportAvatar.js index a29750636061..7e152476f007 100644 --- a/src/pages/ReportAvatar.js +++ b/src/pages/ReportAvatar.js @@ -71,7 +71,7 @@ function ReportAvatar(props) { Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(props.report.reportID)); }} isWorkspaceAvatar - originalFileName={policyName} + originalFileName={lodashGet(props.policy, 'originalFileName', '')} shouldShowNotFoundPage={_.isEmpty(props.report.reportID) && !props.isLoadingReportData} isLoading={(_.isEmpty(props.report.reportID) || _.isEmpty(props.policy.id)) && props.isLoadingReportData} /> diff --git a/src/pages/settings/Profile/ProfileAvatar.js b/src/pages/settings/Profile/ProfileAvatar.js index 6fe6ba9c0baa..43c98c7223b5 100644 --- a/src/pages/settings/Profile/ProfileAvatar.js +++ b/src/pages/settings/Profile/ProfileAvatar.js @@ -44,6 +44,7 @@ function ProfileAvatar(props) { onModalClose={() => { Navigation.goBack(); }} + originalFileName={lodashGet(personalDetail, 'originalFileName', '')} isLoading={props.isLoadingApp && _.isEmpty(props.personalDetails)} /> ); diff --git a/src/pages/workspace/WorkspaceAvatar.js b/src/pages/workspace/WorkspaceAvatar.js index 8495decb842e..f0384ac924b5 100644 --- a/src/pages/workspace/WorkspaceAvatar.js +++ b/src/pages/workspace/WorkspaceAvatar.js @@ -62,7 +62,7 @@ function WorkspaceAvatar(props) { Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(props.route))); }} isWorkspaceAvatar - originalFileName={lodashGet(props.policy, 'name', '')} + originalFileName={lodashGet(props.policy, 'originalFileName', '')} shouldShowNotFoundPage={_.isEmpty(props.policy) && !props.isLoadingReportData} isLoading={_.isEmpty(props.policy) && props.isLoadingReportData} /> From 0af6d790645bb6cfd3e292203468d9ce0189d7d5 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 4 Dec 2023 20:57:29 +0700 Subject: [PATCH 09/21] call openProfilePage if personal detail is empty --- src/pages/settings/Profile/ProfileAvatar.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/pages/settings/Profile/ProfileAvatar.js b/src/pages/settings/Profile/ProfileAvatar.js index 43c98c7223b5..8536de612226 100644 --- a/src/pages/settings/Profile/ProfileAvatar.js +++ b/src/pages/settings/Profile/ProfileAvatar.js @@ -1,12 +1,14 @@ import lodashGet from 'lodash/get'; import PropTypes from 'prop-types'; -import React from 'react'; +import React, {useEffect} from 'react'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; import AttachmentModal from '@components/AttachmentModal'; import participantPropTypes from '@components/participantPropTypes'; import Navigation from '@libs/Navigation/Navigation'; import * as UserUtils from '@libs/UserUtils'; +import * as ValidationUtils from '@libs/ValidationUtils'; +import * as PersonalDetails from '@userActions/PersonalDetails'; import ONYXKEYS from '@src/ONYXKEYS'; const propTypes = { @@ -34,7 +36,15 @@ const defaultProps = { function ProfileAvatar(props) { const personalDetail = props.personalDetails[props.route.params.accountID]; const avatarURL = lodashGet(personalDetail, 'avatar', ''); - const accountID = lodashGet(personalDetail, 'accountID', ''); + const accountID = lodashGet(props.route.params, 'accountID', ''); + const isLoading = lodashGet(personalDetail, 'isLoading', false) || (props.isLoadingApp && _.isEmpty(props.personalDetails)); + + useEffect(() => { + if (!ValidationUtils.isValidAccountRoute(Number(accountID)) || !!avatarURL) { + return; + } + PersonalDetails.openPublicProfilePage(accountID); + }, [accountID, avatarURL]); return ( ); } From a078e1e51503ae027998d5a35930857693bcd263 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 7 Dec 2023 13:34:38 +0700 Subject: [PATCH 10/21] fix ts check --- src/libs/Navigation/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/Navigation/types.ts b/src/libs/Navigation/types.ts index ba703d0df0c0..88fa742e9454 100644 --- a/src/libs/Navigation/types.ts +++ b/src/libs/Navigation/types.ts @@ -406,6 +406,7 @@ type AuthScreensParamList = { }; [SCREENS.REPORT_AVATAR]: { reportID: string; + }; [CONST.DEMO_PAGES.SAASTR]: { name: string; }; From 575b0a379af8adcb20cba11548e6211678d6da11 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 28 Dec 2023 10:03:51 +0700 Subject: [PATCH 11/21] resolve conflict --- src/components/RoomHeaderAvatars.js | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index 14975d2ca49a..ca44ce47ca65 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -23,7 +23,6 @@ const defaultProps = { }; function RoomHeaderAvatars(props) { -<<<<<<< HEAD const navigateToAvatarPage = (icon) => { if (icon.type === CONST.ICON_TYPE_WORKSPACE) { Navigation.navigate(ROUTES.REPORT_AVATAR.getRoute(props.reportID)); @@ -33,8 +32,6 @@ function RoomHeaderAvatars(props) { }; const theme = useTheme(); -======= ->>>>>>> main const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); if (!props.icons.length) { @@ -83,10 +80,8 @@ function RoomHeaderAvatars(props) { accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} accessibilityLabel={icon.name} > -<<<<<<< HEAD -======= - {({show}) => ( - - - - )} - ->>>>>>> main {index === CONST.REPORT.MAX_PREVIEW_AVATARS - 1 && props.icons.length - CONST.REPORT.MAX_PREVIEW_AVATARS !== 0 && ( <> Date: Thu, 28 Dec 2023 10:18:43 +0700 Subject: [PATCH 12/21] fix lint --- src/components/RoomHeaderAvatars.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/RoomHeaderAvatars.js b/src/components/RoomHeaderAvatars.js index ca44ce47ca65..64cc9ac7abf3 100644 --- a/src/components/RoomHeaderAvatars.js +++ b/src/components/RoomHeaderAvatars.js @@ -31,7 +31,6 @@ function RoomHeaderAvatars(props) { Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(icon.id)); }; - const theme = useTheme(); const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); if (!props.icons.length) { From e16f43a3a3eadee57f1af553bf3de6d708ca42b7 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 16 Jan 2024 12:35:57 +0700 Subject: [PATCH 13/21] Update src/ROUTES.ts Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/ROUTES.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ROUTES.ts b/src/ROUTES.ts index b49174707a7b..c495c2851227 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -140,7 +140,6 @@ const ROUTES = { getRoute: (backTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo), }, SETTINGS_STATUS: 'settings/profile/status', - SETTINGS_STATUS_SET: 'settings/profile/status/set', PROFILE_AVATAR: { route: 'a/:accountID/avatar', getRoute: (accountID: string) => `a/${accountID}/avatar` as const, From 8885fb8d98533d2ab323c0fd3830bb2a9e4fcb0a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 16 Jan 2024 15:53:53 +0700 Subject: [PATCH 14/21] migrate new component to typescript --- src/ROUTES.ts | 16 ++-- src/pages/ReportAvatar.js | 99 -------------------- src/pages/ReportAvatar.tsx | 64 +++++++++++++ src/pages/settings/Profile/ProfileAvatar.js | 75 --------------- src/pages/settings/Profile/ProfileAvatar.tsx | 59 ++++++++++++ src/pages/workspace/WorkspaceAvatar.js | 83 ---------------- src/pages/workspace/WorkspaceAvatar.tsx | 55 +++++++++++ src/types/onyx/Policy.ts | 3 + 8 files changed, 189 insertions(+), 265 deletions(-) delete mode 100644 src/pages/ReportAvatar.js create mode 100644 src/pages/ReportAvatar.tsx delete mode 100644 src/pages/settings/Profile/ProfileAvatar.js create mode 100644 src/pages/settings/Profile/ProfileAvatar.tsx delete mode 100644 src/pages/workspace/WorkspaceAvatar.js create mode 100644 src/pages/workspace/WorkspaceAvatar.tsx diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 2b6feed8b1a7..f6c3ac095ba4 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -29,6 +29,10 @@ const ROUTES = { route: 'a/:accountID', getRoute: (accountID: string | number, backTo?: string) => getUrlWithBackToParam(`a/${accountID}`, backTo), }, + PROFILE_AVATAR: { + route: 'a/:accountID/avatar', + getRoute: (accountID: string) => `a/${accountID}/avatar` as const, + }, TRANSITION_BETWEEN_APPS: 'transition', VALIDATE_LOGIN: 'v/:accountID/:validateCode', @@ -140,15 +144,7 @@ const ROUTES = { getRoute: (backTo?: string) => getUrlWithBackToParam('settings/security/two-factor-auth', backTo), }, SETTINGS_STATUS: 'settings/profile/status', - PROFILE_AVATAR: { - route: 'a/:accountID/avatar', - getRoute: (accountID: string) => `a/${accountID}/avatar` as const, - }, - WORKSPACE_AVATAR: { - route: 'workspace/:policyID/avatar', - getRoute: (policyID: string) => `workspace/${policyID}/avatar` as const, - }, SETTINGS_STATUS_CLEAR_AFTER: 'settings/profile/status/clear-after', SETTINGS_STATUS_CLEAR_AFTER_DATE: 'settings/profile/status/clear-after/date', SETTINGS_STATUS_CLEAR_AFTER_TIME: 'settings/profile/status/clear-after/time', @@ -447,6 +443,10 @@ const ROUTES = { route: 'workspace/:policyID/settings', getRoute: (policyID: string) => `workspace/${policyID}/settings` as const, }, + WORKSPACE_AVATAR: { + route: 'workspace/:policyID/avatar', + getRoute: (policyID: string) => `workspace/${policyID}/avatar` as const, + }, WORKSPACE_SETTINGS_CURRENCY: { route: 'workspace/:policyID/settings/currency', getRoute: (policyID: string) => `workspace/${policyID}/settings/currency` as const, diff --git a/src/pages/ReportAvatar.js b/src/pages/ReportAvatar.js deleted file mode 100644 index 7e152476f007..000000000000 --- a/src/pages/ReportAvatar.js +++ /dev/null @@ -1,99 +0,0 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; -import React from 'react'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; -import AttachmentModal from '@components/AttachmentModal'; -import compose from '@libs/compose'; -import Navigation from '@libs/Navigation/Navigation'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as UserUtils from '@libs/UserUtils'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; -import reportPropTypes from './reportPropTypes'; - -/** - * @param {Object} route - * @returns {String} - */ -function getReportIDFromRoute(route) { - return lodashGet(route, 'params.reportID', '0'); -} - -const propTypes = { - /** React Navigation route */ - route: PropTypes.shape({ - /** Params from the route */ - params: PropTypes.shape({ - /** The reportID of the user */ - reportID: PropTypes.string.isRequired, - }), - }).isRequired, - - /** The report currently being looked at */ - report: reportPropTypes, - - /** The policy of the report */ - policy: PropTypes.shape({ - /** The ID of the policy */ - id: PropTypes.string, - - /** The name of the policy */ - name: PropTypes.string, - - /** The URL for the policy avatar */ - avatar: PropTypes.string, - - /** File name of the avatar */ - originalFileName: PropTypes.string, - }), - - /** Indicates whether the app is loading initial data */ - isLoadingReportData: PropTypes.bool, -}; - -const defaultProps = { - report: {}, - policy: {}, - isLoadingReportData: true, -}; - -function ReportAvatar(props) { - const isArchivedRoom = ReportUtils.isArchivedRoom(props.report); - const policyName = isArchivedRoom ? props.report.oldPolicyName : lodashGet(props.policy, 'name', ''); - const avatarURL = lodashGet(props.policy, 'avatar', '') || ReportUtils.getDefaultWorkspaceAvatar(policyName); - return ( - { - Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(props.report.reportID)); - }} - isWorkspaceAvatar - originalFileName={lodashGet(props.policy, 'originalFileName', '')} - shouldShowNotFoundPage={_.isEmpty(props.report.reportID) && !props.isLoadingReportData} - isLoading={(_.isEmpty(props.report.reportID) || _.isEmpty(props.policy.id)) && props.isLoadingReportData} - /> - ); -} - -ReportAvatar.propTypes = propTypes; -ReportAvatar.defaultProps = defaultProps; -ReportAvatar.displayName = 'ReportAvatar'; - -export default compose( - withOnyx({ - report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportIDFromRoute(route)}`, - }, - isLoadingReportData: { - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - }, - }), - withOnyx({ - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, - }, - }), -)(ReportAvatar); diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx new file mode 100644 index 000000000000..77ecf4366d85 --- /dev/null +++ b/src/pages/ReportAvatar.tsx @@ -0,0 +1,64 @@ +import type {RouteProp} from '@react-navigation/native'; +import React from 'react'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; +import AttachmentModal from '@components/AttachmentModal'; +import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; +import * as UserUtils from '@libs/UserUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import type {Policy, Report} from '@src/types/onyx'; + +type ReportRoute = RouteProp<{params: {reportID: string}}>; + +type ReportAvatarOnyxProps = { + report: OnyxEntry; + isLoadingApp: OnyxEntry; + policies: OnyxCollection; +}; + +type ReportAvatarProps = ReportAvatarOnyxProps & { + // eslint-disable-next-line react/no-unused-prop-types + route: ReportRoute; +}; + +function getReportIDFromRoute(route: ReportRoute) { + return route.params.reportID ?? ''; +} + +function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: ReportAvatarProps) { + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; + const isArchivedRoom = ReportUtils.isArchivedRoom(report); + const policyName = isArchivedRoom ? report?.oldPolicyName : policy?.name; + const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policyName); + + return ( + { + Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '')); + }} + isWorkspaceAvatar + originalFileName={policyName} + shouldShowNotFoundPage={!report?.reportID && !isLoadingApp} + isLoading={(!report?.reportID || !policy?.id) && isLoadingApp} + /> + ); +} + +ReportAvatar.displayName = 'ReportAvatar'; + +export default withOnyx({ + report: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportIDFromRoute(route)}`, + }, + isLoadingApp: { + key: ONYXKEYS.IS_LOADING_APP, + }, + policies: { + key: ONYXKEYS.COLLECTION.POLICY, + }, +})(ReportAvatar); diff --git a/src/pages/settings/Profile/ProfileAvatar.js b/src/pages/settings/Profile/ProfileAvatar.js deleted file mode 100644 index 8536de612226..000000000000 --- a/src/pages/settings/Profile/ProfileAvatar.js +++ /dev/null @@ -1,75 +0,0 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; -import React, {useEffect} from 'react'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; -import AttachmentModal from '@components/AttachmentModal'; -import participantPropTypes from '@components/participantPropTypes'; -import Navigation from '@libs/Navigation/Navigation'; -import * as UserUtils from '@libs/UserUtils'; -import * as ValidationUtils from '@libs/ValidationUtils'; -import * as PersonalDetails from '@userActions/PersonalDetails'; -import ONYXKEYS from '@src/ONYXKEYS'; - -const propTypes = { - /** React Navigation route */ - route: PropTypes.shape({ - /** Params from the route */ - params: PropTypes.shape({ - /** The acountID of the user */ - accountID: PropTypes.string.isRequired, - }), - }).isRequired, - - /** Personal details of all the users */ - personalDetails: PropTypes.objectOf(participantPropTypes), - - /** Indicates whether the app is loading initial data */ - isLoadingApp: PropTypes.bool, -}; - -const defaultProps = { - personalDetails: {}, - isLoadingApp: true, -}; - -function ProfileAvatar(props) { - const personalDetail = props.personalDetails[props.route.params.accountID]; - const avatarURL = lodashGet(personalDetail, 'avatar', ''); - const accountID = lodashGet(props.route.params, 'accountID', ''); - const isLoading = lodashGet(personalDetail, 'isLoading', false) || (props.isLoadingApp && _.isEmpty(props.personalDetails)); - - useEffect(() => { - if (!ValidationUtils.isValidAccountRoute(Number(accountID)) || !!avatarURL) { - return; - } - PersonalDetails.openPublicProfilePage(accountID); - }, [accountID, avatarURL]); - - return ( - { - Navigation.goBack(); - }} - originalFileName={lodashGet(personalDetail, 'originalFileName', '')} - isLoading={isLoading} - shouldShowNotFoundPage={!avatarURL} - /> - ); -} - -ProfileAvatar.propTypes = propTypes; -ProfileAvatar.defaultProps = defaultProps; -ProfileAvatar.displayName = 'ProfileAvatar'; - -export default withOnyx({ - personalDetails: { - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - }, - isLoadingApp: { - key: ONYXKEYS.IS_LOADING_APP, - }, -})(ProfileAvatar); diff --git a/src/pages/settings/Profile/ProfileAvatar.tsx b/src/pages/settings/Profile/ProfileAvatar.tsx new file mode 100644 index 000000000000..ad879ca3206b --- /dev/null +++ b/src/pages/settings/Profile/ProfileAvatar.tsx @@ -0,0 +1,59 @@ +import type {RouteProp} from '@react-navigation/native'; +import React, {useEffect} from 'react'; +import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; +import AttachmentModal from '@components/AttachmentModal'; +import Navigation from '@libs/Navigation/Navigation'; +import * as UserUtils from '@libs/UserUtils'; +import * as ValidationUtils from '@libs/ValidationUtils'; +import * as PersonalDetails from '@userActions/PersonalDetails'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {PersonalDetailsList} from '@src/types/onyx'; + +type ProfileAvatarOnyxProps = { + personalDetails: OnyxEntry; + isLoadingApp: OnyxEntry; +}; + +type ProfileAvatarProps = ProfileAvatarOnyxProps & { + route: RouteProp<{params: {accountID: string}}>; +}; + +function ProfileAvatar({route, personalDetails, isLoadingApp = true}: ProfileAvatarProps) { + const personalDetail = personalDetails?.[route.params.accountID]; + const avatarURL = personalDetail?.avatar ?? ''; + const accountID = Number(route.params.accountID ?? ''); + const isLoading = personalDetail?.isLoading ?? (isLoadingApp && !Object.keys(personalDetail ?? {}).length); + + useEffect(() => { + if (!ValidationUtils.isValidAccountRoute(Number(accountID)) ?? !!avatarURL) { + return; + } + PersonalDetails.openPublicProfilePage(accountID); + }, [accountID, avatarURL]); + + return ( + { + Navigation.goBack(); + }} + originalFileName={personalDetail?.originalFileName ?? ''} + isLoading={isLoading} + shouldShowNotFoundPage={!avatarURL} + /> + ); +} + +ProfileAvatar.displayName = 'ProfileAvatar'; + +export default withOnyx({ + personalDetails: { + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + }, + isLoadingApp: { + key: ONYXKEYS.IS_LOADING_APP, + }, +})(ProfileAvatar); diff --git a/src/pages/workspace/WorkspaceAvatar.js b/src/pages/workspace/WorkspaceAvatar.js deleted file mode 100644 index f0384ac924b5..000000000000 --- a/src/pages/workspace/WorkspaceAvatar.js +++ /dev/null @@ -1,83 +0,0 @@ -import lodashGet from 'lodash/get'; -import PropTypes from 'prop-types'; -import React from 'react'; -import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; -import AttachmentModal from '@components/AttachmentModal'; -import Navigation from '@libs/Navigation/Navigation'; -import * as ReportUtils from '@libs/ReportUtils'; -import * as UserUtils from '@libs/UserUtils'; -import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; - -/** - * @param {Object} route - * @returns {String} - */ -function getPolicyIDFromRoute(route) { - return lodashGet(route, 'params.policyID', ''); -} - -const propTypes = { - /** React Navigation route */ - route: PropTypes.shape({ - /** Params from the route */ - params: PropTypes.shape({ - /** The policyID of the user */ - policyID: PropTypes.string.isRequired, - }), - }).isRequired, - - /** The policy object for the current route */ - policy: PropTypes.shape({ - /** The ID of the policy */ - id: PropTypes.string, - - /** The name of the policy */ - name: PropTypes.string, - - /** The URL for the policy avatar */ - avatar: PropTypes.string, - - /** File name of the avatar */ - originalFileName: PropTypes.string, - }).isRequired, - - /** Indicates whether the app is loading initial data */ - isLoadingReportData: PropTypes.bool, -}; - -const defaultProps = { - isLoadingReportData: true, -}; - -function WorkspaceAvatar(props) { - const avatarURL = lodashGet(props.policy, 'avatar', '') || ReportUtils.getDefaultWorkspaceAvatar(lodashGet(props.policy, 'name', '')); - return ( - { - Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(props.route))); - }} - isWorkspaceAvatar - originalFileName={lodashGet(props.policy, 'originalFileName', '')} - shouldShowNotFoundPage={_.isEmpty(props.policy) && !props.isLoadingReportData} - isLoading={_.isEmpty(props.policy) && props.isLoadingReportData} - /> - ); -} - -WorkspaceAvatar.propTypes = propTypes; -WorkspaceAvatar.defaultProps = defaultProps; -WorkspaceAvatar.displayName = 'WorkspaceAvatar'; - -export default withOnyx({ - policy: { - key: (props) => `${ONYXKEYS.COLLECTION.POLICY}${getPolicyIDFromRoute(props.route)}`, - }, - isLoadingReportData: { - key: ONYXKEYS.IS_LOADING_REPORT_DATA, - }, -})(WorkspaceAvatar); diff --git a/src/pages/workspace/WorkspaceAvatar.tsx b/src/pages/workspace/WorkspaceAvatar.tsx new file mode 100644 index 000000000000..84363ea55bac --- /dev/null +++ b/src/pages/workspace/WorkspaceAvatar.tsx @@ -0,0 +1,55 @@ +import type {RouteProp} from '@react-navigation/native'; +import React from 'react'; +import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; +import AttachmentModal from '@components/AttachmentModal'; +import Navigation from '@libs/Navigation/Navigation'; +import * as ReportUtils from '@libs/ReportUtils'; +import * as UserUtils from '@libs/UserUtils'; +import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; +import type {Policy} from '@src/types/onyx'; + +type PolicyRoute = RouteProp<{params: {policyID: string}}>; + +type WorkspaceAvatarOnyxProps = { + policy: OnyxEntry; + isLoadingApp: OnyxEntry; +}; + +type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & { + route: PolicyRoute; +}; + +function getPolicyIDFromRoute(route: PolicyRoute) { + return route.params.policyID ?? ''; +} + +function WorkspaceAvatar({route, policy, isLoadingApp = true}: WorkspaceAvatarProps) { + const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? ''); + return ( + { + Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(route))); + }} + isWorkspaceAvatar + originalFileName={policy?.name ?? ''} + shouldShowNotFoundPage={!Object.keys(policy ?? {}).length && !isLoadingApp} + isLoading={!Object.keys(policy ?? {}).length && isLoadingApp} + /> + ); +} + +WorkspaceAvatar.displayName = 'WorkspaceAvatar'; + +export default withOnyx({ + policy: { + key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${getPolicyIDFromRoute(route)}`, + }, + isLoadingApp: { + key: ONYXKEYS.IS_LOADING_APP, + }, +})(WorkspaceAvatar); diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index da4522487a7a..37f01dfb0fe2 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -82,6 +82,9 @@ type Policy = { /** The employee list of the policy */ employeeList?: []; + + /** The original file name of workspace's avatar */ + originalFileName?: string; }; export default Policy; From acc52a45caf6069b6dc48da57e5918b15a199898 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 16 Jan 2024 16:00:20 +0700 Subject: [PATCH 15/21] fix policy originalFileName case --- src/pages/ReportAvatar.tsx | 2 +- src/pages/workspace/WorkspaceAvatar.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 77ecf4366d85..271eba50031e 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -42,7 +42,7 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(report?.reportID ?? '')); }} isWorkspaceAvatar - originalFileName={policyName} + originalFileName={policy?.originalFileName ?? policyName} shouldShowNotFoundPage={!report?.reportID && !isLoadingApp} isLoading={(!report?.reportID || !policy?.id) && isLoadingApp} /> diff --git a/src/pages/workspace/WorkspaceAvatar.tsx b/src/pages/workspace/WorkspaceAvatar.tsx index 84363ea55bac..c1c1bf373203 100644 --- a/src/pages/workspace/WorkspaceAvatar.tsx +++ b/src/pages/workspace/WorkspaceAvatar.tsx @@ -36,7 +36,7 @@ function WorkspaceAvatar({route, policy, isLoadingApp = true}: WorkspaceAvatarPr Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(route))); }} isWorkspaceAvatar - originalFileName={policy?.name ?? ''} + originalFileName={policy?.originalFileName ?? policy?.name ?? ''} shouldShowNotFoundPage={!Object.keys(policy ?? {}).length && !isLoadingApp} isLoading={!Object.keys(policy ?? {}).length && isLoadingApp} /> From fe48bc247ee44bc7731e52f6aa6533aa48568bab Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 18 Jan 2024 17:26:40 +0700 Subject: [PATCH 16/21] fix some minior case --- src/pages/ReportAvatar.tsx | 11 +++++++---- src/pages/settings/Profile/ProfileAvatar.tsx | 11 +++++++---- src/pages/workspace/WorkspaceAvatar.tsx | 11 ++++++++--- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 271eba50031e..8049bbec03c9 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -1,13 +1,16 @@ import type {RouteProp} from '@react-navigation/native'; +import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import AttachmentModal from '@components/AttachmentModal'; import Navigation from '@libs/Navigation/Navigation'; +import type {AuthScreensParamList} from '@libs/Navigation/types'; import * as ReportUtils from '@libs/ReportUtils'; import * as UserUtils from '@libs/UserUtils'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; +import type SCREENS from '@src/SCREENS'; import type {Policy, Report} from '@src/types/onyx'; type ReportRoute = RouteProp<{params: {reportID: string}}>; @@ -18,10 +21,7 @@ type ReportAvatarOnyxProps = { policies: OnyxCollection; }; -type ReportAvatarProps = ReportAvatarOnyxProps & { - // eslint-disable-next-line react/no-unused-prop-types - route: ReportRoute; -}; +type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps; function getReportIDFromRoute(route: ReportRoute) { return route.params.reportID ?? ''; @@ -34,6 +34,9 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policyName); return ( + /** + * @ts-expect-error TODO: Remove this once AttachmentModal (https://github.com/Expensify/App/issues/25130) is migrated to TypeScript. + */ ; }; -type ProfileAvatarProps = ProfileAvatarOnyxProps & { - route: RouteProp<{params: {accountID: string}}>; -}; +type ProfileAvatarProps = ProfileAvatarOnyxProps & StackScreenProps; function ProfileAvatar({route, personalDetails, isLoadingApp = true}: ProfileAvatarProps) { const personalDetail = personalDetails?.[route.params.accountID]; @@ -33,6 +33,9 @@ function ProfileAvatar({route, personalDetails, isLoadingApp = true}: ProfileAva }, [accountID, avatarURL]); return ( + /** + * @ts-expect-error TODO: Remove this once AttachmentModal (https://github.com/Expensify/App/issues/25130) is migrated to TypeScript. + */ ; @@ -17,9 +20,7 @@ type WorkspaceAvatarOnyxProps = { isLoadingApp: OnyxEntry; }; -type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & { - route: PolicyRoute; -}; +type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & StackScreenProps; function getPolicyIDFromRoute(route: PolicyRoute) { return route.params.policyID ?? ''; @@ -27,7 +28,11 @@ function getPolicyIDFromRoute(route: PolicyRoute) { function WorkspaceAvatar({route, policy, isLoadingApp = true}: WorkspaceAvatarProps) { const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? ''); + return ( + /** + * @ts-expect-error TODO: Remove this once AttachmentModal (https://github.com/Expensify/App/issues/25130) is migrated to TypeScript. + */ Date: Thu, 18 Jan 2024 17:34:45 +0700 Subject: [PATCH 17/21] add ts-expect-error comment --- src/pages/ReportAvatar.tsx | 4 +--- src/pages/settings/Profile/ProfileAvatar.tsx | 4 +--- src/pages/workspace/WorkspaceAvatar.tsx | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index 8049bbec03c9..a0c7fe60f106 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -34,10 +34,8 @@ function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: Re const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policyName); return ( - /** - * @ts-expect-error TODO: Remove this once AttachmentModal (https://github.com/Expensify/App/issues/25130) is migrated to TypeScript. - */ Date: Thu, 18 Jan 2024 17:49:13 +0700 Subject: [PATCH 18/21] remove unused function --- src/pages/ReportAvatar.tsx | 9 +-------- src/pages/workspace/WorkspaceAvatar.tsx | 10 ++-------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/pages/ReportAvatar.tsx b/src/pages/ReportAvatar.tsx index a0c7fe60f106..2a8114da744d 100644 --- a/src/pages/ReportAvatar.tsx +++ b/src/pages/ReportAvatar.tsx @@ -1,4 +1,3 @@ -import type {RouteProp} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; @@ -13,8 +12,6 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Policy, Report} from '@src/types/onyx'; -type ReportRoute = RouteProp<{params: {reportID: string}}>; - type ReportAvatarOnyxProps = { report: OnyxEntry; isLoadingApp: OnyxEntry; @@ -23,10 +20,6 @@ type ReportAvatarOnyxProps = { type ReportAvatarProps = ReportAvatarOnyxProps & StackScreenProps; -function getReportIDFromRoute(route: ReportRoute) { - return route.params.reportID ?? ''; -} - function ReportAvatar({report = {} as Report, policies, isLoadingApp = true}: ReportAvatarProps) { const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? '0'}`]; const isArchivedRoom = ReportUtils.isArchivedRoom(report); @@ -54,7 +47,7 @@ ReportAvatar.displayName = 'ReportAvatar'; export default withOnyx({ report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${getReportIDFromRoute(route)}`, + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID ?? ''}`, }, isLoadingApp: { key: ONYXKEYS.IS_LOADING_APP, diff --git a/src/pages/workspace/WorkspaceAvatar.tsx b/src/pages/workspace/WorkspaceAvatar.tsx index 3f43b7e456d1..9dd180321e62 100644 --- a/src/pages/workspace/WorkspaceAvatar.tsx +++ b/src/pages/workspace/WorkspaceAvatar.tsx @@ -1,4 +1,3 @@ -import type {RouteProp} from '@react-navigation/native'; import type {StackScreenProps} from '@react-navigation/stack'; import React from 'react'; import type {OnyxEntry} from 'react-native-onyx'; @@ -13,7 +12,6 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Policy} from '@src/types/onyx'; -type PolicyRoute = RouteProp<{params: {policyID: string}}>; type WorkspaceAvatarOnyxProps = { policy: OnyxEntry; @@ -22,10 +20,6 @@ type WorkspaceAvatarOnyxProps = { type WorkspaceAvatarProps = WorkspaceAvatarOnyxProps & StackScreenProps; -function getPolicyIDFromRoute(route: PolicyRoute) { - return route.params.policyID ?? ''; -} - function WorkspaceAvatar({route, policy, isLoadingApp = true}: WorkspaceAvatarProps) { const avatarURL = policy?.avatar ?? '' ? policy?.avatar ?? '' : ReportUtils.getDefaultWorkspaceAvatar(policy?.name ?? ''); @@ -36,7 +30,7 @@ function WorkspaceAvatar({route, policy, isLoadingApp = true}: WorkspaceAvatarPr defaultOpen source={UserUtils.getFullSizeAvatar(avatarURL, 0)} onModalClose={() => { - Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(getPolicyIDFromRoute(route))); + Navigation.goBack(ROUTES.WORKSPACE_SETTINGS.getRoute(route.params.policyID ?? '')); }} isWorkspaceAvatar originalFileName={policy?.originalFileName ?? policy?.name ?? ''} @@ -50,7 +44,7 @@ WorkspaceAvatar.displayName = 'WorkspaceAvatar'; export default withOnyx({ policy: { - key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${getPolicyIDFromRoute(route)}`, + key: ({route}) => `${ONYXKEYS.COLLECTION.POLICY}${route.params.policyID ?? ''}`, }, isLoadingApp: { key: ONYXKEYS.IS_LOADING_APP, From 5703ba3db4cce9105da15bedc741b4d14a676826 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 19 Jan 2024 14:18:50 +0700 Subject: [PATCH 19/21] fix lint --- src/pages/workspace/WorkspaceAvatar.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/workspace/WorkspaceAvatar.tsx b/src/pages/workspace/WorkspaceAvatar.tsx index 9dd180321e62..1a420ee0fbd3 100644 --- a/src/pages/workspace/WorkspaceAvatar.tsx +++ b/src/pages/workspace/WorkspaceAvatar.tsx @@ -12,7 +12,6 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type {Policy} from '@src/types/onyx'; - type WorkspaceAvatarOnyxProps = { policy: OnyxEntry; isLoadingApp: OnyxEntry; From 78cf3492cb6043b68ed1d54b024534ffde4fcb50 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Tue, 23 Jan 2024 09:45:04 +0700 Subject: [PATCH 20/21] Update src/components/AttachmentModal.js Co-authored-by: Aimane Chnaif <96077027+aimane-chnaif@users.noreply.github.com> --- src/components/AttachmentModal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index d2c3ce42cbcc..e1f9e72ebff1 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -496,7 +496,7 @@ function AttachmentModal(props) { onLinkPress={() => Navigation.dismissModal()} /> )} - {!_.isEmpty(props.report) ? ( + {!_.isEmpty(props.report) && !props.isReceiptAttachment ? ( Date: Tue, 23 Jan 2024 09:46:09 +0700 Subject: [PATCH 21/21] merge main --- src/components/AttachmentModal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/AttachmentModal.js b/src/components/AttachmentModal.js index e1f9e72ebff1..fdc7840c9b38 100755 --- a/src/components/AttachmentModal.js +++ b/src/components/AttachmentModal.js @@ -519,6 +519,7 @@ function AttachmentModal(props) { isWorkspaceAvatar={props.isWorkspaceAvatar} fallbackSource={props.fallbackSource} isUsedInAttachmentModal + transactionID={props.transaction.transactionID} /> ) )}