Skip to content

Commit

Permalink
Merge pull request #35321 from shahinyan11/issues/25215
Browse files Browse the repository at this point in the history
[TS migration] Migrate 'SettingsProfileReport' page to TypeScript
  • Loading branch information
nkuoch authored Feb 5, 2024
2 parents b2c3100 + 84317af commit 4722815
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 245 deletions.
4 changes: 2 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,8 @@ type OnyxValues = {
[ONYXKEYS.FORMS.PROFILE_SETTINGS_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.DISPLAY_NAME_FORM]: OnyxTypes.DisplayNameForm;
[ONYXKEYS.FORMS.DISPLAY_NAME_FORM_DRAFT]: OnyxTypes.DisplayNameForm;
[ONYXKEYS.FORMS.ROOM_NAME_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.ROOM_NAME_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.ROOM_NAME_FORM]: OnyxTypes.RoomNameForm;
[ONYXKEYS.FORMS.ROOM_NAME_FORM_DRAFT]: OnyxTypes.RoomNameForm;
[ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM]: OnyxTypes.Form;
[ONYXKEYS.FORMS.WELCOME_MESSAGE_FORM_DRAFT]: OnyxTypes.Form;
[ONYXKEYS.FORMS.LEGAL_NAME_FORM]: OnyxTypes.Form;
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisplayNames/DisplayNamesWithTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function DisplayNamesWithToolTip({shouldUseFullTitle, fullTitle, displayNamesWit
>
{shouldUseFullTitle
? ReportUtils.formatReportLastMessageText(fullTitle)
: displayNamesWithTooltips.map(({displayName, accountID, avatar, login}, index) => (
: displayNamesWithTooltips?.map(({displayName, accountID, avatar, login}, index) => (
// eslint-disable-next-line react/no-array-index-key
<Fragment key={index}>
<DisplayNamesTooltipItem
Expand Down
12 changes: 11 additions & 1 deletion src/components/DisplayNames/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ function DisplayNames({fullTitle, tooltipEnabled, textStyles, numberOfLines, sho
);
}

if (shouldUseFullTitle) {
return (
<DisplayNamesWithToolTip
shouldUseFullTitle
fullTitle={title}
textStyles={textStyles}
numberOfLines={numberOfLines}
/>
);
}

return (
<DisplayNamesWithToolTip
shouldUseFullTitle={shouldUseFullTitle}
fullTitle={title}
displayNamesWithTooltips={displayNamesWithTooltips}
textStyles={textStyles}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DisplayNames/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type DisplayNamesProps = {
fullTitle: string;

/** Array of objects that map display names to their corresponding tooltip */
displayNamesWithTooltips: DisplayNameWithTooltip[];
displayNamesWithTooltips?: DisplayNameWithTooltip[];

/** Number of lines before wrapping */
numberOfLines: number;
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ export default {
always: 'Immediately',
daily: 'Daily',
mute: 'Mute',
hidden: 'Hidden',
},
},
loginField: {
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@ export default {
always: 'Inmediatamente',
daily: 'Cada día',
mute: 'Nunca',
hidden: 'Oculto',
},
},
loginField: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ type ErrorsList = Record<string, string | [string, {isTranslated: boolean}]>;
* @param errors - An object containing current errors in the form
* @param message - Message to assign to the inputID errors
*/
function addErrorMessage<TKey extends TranslationPaths>(errors: ErrorsList, inputID?: string, message?: TKey) {
function addErrorMessage<TKey extends TranslationPaths>(errors: ErrorsList, inputID?: string, message?: TKey | Localize.MaybePhraseKey) {
if (!message || !inputID) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {URL_REGEX_WITH_REQUIRED_PROTOCOL} from 'expensify-common/lib/Url';
import isDate from 'lodash/isDate';
import isEmpty from 'lodash/isEmpty';
import isObject from 'lodash/isObject';
import type {OnyxCollection} from 'react-native-onyx';
import CONST from '@src/CONST';
import type {Report} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -361,8 +362,8 @@ function isReservedRoomName(roomName: string): boolean {
/**
* Checks if the room name already exists.
*/
function isExistingRoomName(roomName: string, reports: Record<string, Report>, policyID: string): boolean {
return Object.values(reports).some((report) => report && report.policyID === policyID && report.reportName === roomName);
function isExistingRoomName(roomName: string, reports: OnyxCollection<Report>, policyID: string): boolean {
return Object.values(reports ?? {}).some((report) => report && report.policyID === policyID && report.reportName === roomName);
}

/**
Expand Down
59 changes: 0 additions & 59 deletions src/pages/settings/Report/NotificationPreferencePage.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/pages/settings/Report/NotificationPreferencePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React from 'react';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import useLocalize from '@hooks/useLocalize';
import * as ReportUtils from '@libs/ReportUtils';
import type {ReportSettingsNavigatorParamList} from '@navigation/types';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import type {WithReportOrNotFoundProps} from '@pages/home/report/withReportOrNotFound';
import * as ReportActions from '@userActions/Report';
import CONST from '@src/CONST';
import type SCREENS from '@src/SCREENS';

type NotificationPreferencePageProps = WithReportOrNotFoundProps & StackScreenProps<ReportSettingsNavigatorParamList, typeof SCREENS.REPORT_SETTINGS.NOTIFICATION_PREFERENCES>;

function NotificationPreferencePage({report}: NotificationPreferencePageProps) {
const {translate} = useLocalize();
const shouldDisableNotificationPreferences = ReportUtils.isArchivedRoom(report);
const notificationPreferenceOptions = Object.values(CONST.REPORT.NOTIFICATION_PREFERENCE)
.filter((pref) => pref !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN)
.map((preference) => ({
value: preference,
text: translate(`notificationPreferencesPage.notificationPreferences.${preference}`),
keyForList: preference,
isSelected: preference === report?.notificationPreference,
}));

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={NotificationPreferencePage.displayName}
>
<FullPageNotFoundView shouldShow={shouldDisableNotificationPreferences}>
<HeaderWithBackButton
title={translate('notificationPreferencesPage.header')}
onBackButtonPress={() => ReportUtils.goBackToDetailsPage(report)}
/>
<SelectionList
sections={[{data: notificationPreferenceOptions}]}
onSelectRow={(option) =>
report && ReportActions.updateNotificationPreference(report.reportID, report.notificationPreference, option.value, true, undefined, undefined, report)
}
initiallyFocusedOptionKey={notificationPreferenceOptions.find((locale) => locale.isSelected)?.keyForList}
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}

NotificationPreferencePage.displayName = 'NotificationPreferencePage';

export default withReportOrNotFound()(NotificationPreferencePage);
Loading

0 comments on commit 4722815

Please sign in to comment.