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 'SettingsProfileReport' page to TypeScript #35321

Merged
merged 19 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function isExpensifyGuideTeam(email: string): boolean {
/**
* Checks if the current user is an admin of the policy.
*/
const isPolicyAdmin = (policy: OnyxEntry<Policy> | undefined): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN;
const isPolicyAdmin = (policy: OnyxEntry<Policy>): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN;

const isPolicyMember = (policyID: string, policies: Record<string, Policy>): boolean => Object.values(policies).some((policy) => policy?.id === policyID);

Expand Down
4 changes: 2 additions & 2 deletions src/pages/settings/Report/NotificationPreferencePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function NotificationPreferencePage({report}: NotificationPreferencePageProps) {
<SelectionList
sections={[{data: notificationPreferenceOptions}]}
onSelectRow={(option) =>
ReportActions.updateNotificationPreference(report?.reportID ?? '', report?.notificationPreference, option.value, true, undefined, undefined, report)
report && ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report)
}
initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList}
initiallyFocusedOptionKey={notificationPreferenceOptions.find((locale) => locale.isSelected)?.keyForList}
/>
</FullPageNotFoundView>
</ScreenWrapper>
Expand Down
26 changes: 13 additions & 13 deletions src/pages/settings/Report/ReportSettingsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useMemo} from 'react';
import {ScrollView, View} from 'react-native';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
Expand All @@ -23,6 +22,7 @@ import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type ReportSettingsPageProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.ROOT>;

Expand All @@ -38,7 +38,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
// We only want policy owners and admins to be able to modify the welcome message, but not in thread chat
const shouldDisableWelcomeMessage = ReportUtils.shouldDisableWelcomeMessage(report, linkedWorkspace);

const shouldDisableSettings = isEmpty(report) || ReportUtils.isArchivedRoom(report);
const shouldDisableSettings = isEmptyObject(report) || ReportUtils.isArchivedRoom(report);
const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(report) && !ReportUtils.isChatThread(report);
const notificationPreference =
report?.notificationPreference && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN
Expand All @@ -60,23 +60,23 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
<FullPageNotFoundView shouldShow={shouldDisableSettings}>
<HeaderWithBackButton
title={translate('common.settings')}
onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID ?? ''))}
onBackButtonPress={() => Navigation.goBack(ROUTES.REPORT_WITH_ID_DETAILS.getRoute(reportID))}
/>
<ScrollView style={[styles.flex1]}>
{shouldShowNotificationPref && (
<MenuItemWithTopDescription
shouldShowRightIcon
title={notificationPreference}
description={translate('notificationPreferencesPage.label')}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(reportID ?? ''))}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(reportID))}
/>
)}
{shouldShowRoomName && (
<OfflineWithFeedback
pendingAction={report?.pendingFields?.reportName}
errors={report?.errorFields?.reportName}
errorRowStyles={[styles.ph5]}
onClose={() => ReportActions.clearPolicyRoomNameErrors(reportID ?? '')}
onClose={() => ReportActions.clearPolicyRoomNameErrors(reportID)}
>
{shouldDisableRename ? (
<View style={[styles.ph5, styles.pv3]}>
Expand All @@ -99,7 +99,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
shouldShowRightIcon
title={report?.reportName}
description={translate('newRoomPage.roomName')}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID ?? ''))}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_ROOM_NAME.getRoute(reportID))}
/>
)}
</OfflineWithFeedback>
Expand All @@ -110,7 +110,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
shouldShowRightIcon
title={writeCapabilityText}
description={translate('writeCapabilityPage.label')}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID ?? ''))}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY.getRoute(reportID))}
/>
) : (
<View style={[styles.ph5, styles.pv3]}>
Expand All @@ -129,7 +129,7 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
</View>
))}
<View style={[styles.ph5]}>
{Boolean(linkedWorkspace) && (
{linkedWorkspace !== null && (
<View style={[styles.pv3]}>
<Text
style={[styles.textLabelSupporting, styles.lh16, styles.mb1]}
Expand All @@ -138,15 +138,15 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
{translate('workspace.common.workspace')}
</Text>
<DisplayNames
fullTitle={linkedWorkspace?.name ?? ''}
fullTitle={linkedWorkspace?.name}
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
tooltipEnabled
numberOfLines={1}
textStyles={[styles.optionAlternateText, styles.pre]}
shouldUseFullTitle
/>
</View>
)}
{Boolean(report?.visibility) && (
{report?.visibility !== undefined && (
Copy link
Contributor

Choose a reason for hiding this comment

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

This change introduced a bug #37445

<View style={[styles.pv3]}>
<Text
style={[styles.textLabelSupporting, styles.lh16, styles.mb1]}
Expand All @@ -158,17 +158,17 @@ function ReportSettingsPage({report, policies}: ReportSettingsPageProps) {
numberOfLines={1}
style={[styles.reportSettingsVisibilityText]}
>
{report?.visibility && translate(`newRoomPage.visibilityOptions.${report.visibility}`)}
{translate(`newRoomPage.visibilityOptions.${report.visibility}`)}
</Text>
<Text style={[styles.textLabelSupporting, styles.mt1]}>{report?.visibility && translate(`newRoomPage.${report.visibility}Description`)}</Text>
<Text style={[styles.textLabelSupporting, styles.mt1]}>{report.visibility && translate(`newRoomPage.${report.visibility}Description`)}</Text>
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
</View>
)}
</View>
{!shouldDisableWelcomeMessage && (
<MenuItem
title={translate('welcomeMessagePage.welcomeMessage')}
icon={Expensicons.ChatBubble}
onPress={() => Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(reportID ?? ''))}
onPress={() => Navigation.navigate(ROUTES.REPORT_WELCOME_MESSAGE.getRoute(reportID))}
shouldShowRightIcon
/>
)}
Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Report/RoomNamePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Policy, Report} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type RoomNamePageOnyxProps = {
/** All reports shared with the user */
Expand Down Expand Up @@ -87,7 +86,7 @@ function RoomNamePage({report, policy, reports}: RoomNamePageProps) {
<FormProvider
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.ROOM_NAME_FORM}
onSubmit={(values) => !isEmptyObject(report) && ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)}
onSubmit={(values) => report && ReportActions.updatePolicyRoomNameAndNavigate(report, values.roomName)}
validate={validate}
submitButtonText={translate('common.save')}
enabledWhenOffline
Expand Down
5 changes: 2 additions & 3 deletions src/pages/settings/Report/WriteCapabilityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Policy} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type WriteCapabilityPageOnyxProps = {
/** The policy object for the current route */
Expand Down Expand Up @@ -53,8 +52,8 @@ function WriteCapabilityPage({report, policy}: WriteCapabilityPageProps) {
/>
<SelectionList
sections={[{data: writeCapabilityOptions}]}
onSelectRow={(option) => !isEmptyObject(report) && ReportActions.updateWriteCapabilityAndNavigate(report, option.value)}
initiallyFocusedOptionKey={Object.values(writeCapabilityOptions).find((locale) => locale.isSelected)?.keyForList}
onSelectRow={(option) => report && ReportActions.updateWriteCapabilityAndNavigate(report, option.value)}
initiallyFocusedOptionKey={writeCapabilityOptions.find((locale) => locale.isSelected)?.keyForList}
/>
</FullPageNotFoundView>
</ScreenWrapper>
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/Form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type WorkspaceSettingsForm = Form<{

type ReportFieldEditForm = Form<Record<string, string>>;

type CloseAccountForm = Form<{
reasonForLeaving: string;
phoneOrEmail: string;
}>;

type RoomNameForm = Form<{
roomName: string;
}>;
Expand All @@ -82,5 +87,6 @@ export type {
PersonalBankAccountForm,
WorkspaceSettingsForm,
ReportFieldEditForm,
CloseAccountForm,
RoomNameForm,
};
Loading