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 12 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
4 changes: 2 additions & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,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
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[];
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved

/** 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 @@ -674,6 +674,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 @@ -668,6 +668,7 @@ export default {
always: 'Inmediatamente',
daily: 'Cada día',
mute: 'Nunca',
hidden: 'Oculto',
},
},
loginField: {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/API/parameters/UpdatePolicyRoomNameParams.ts
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type UpdatePolicyRoomNameParams = {
reportID: string;
policyRoomName: string;
policyRoomName?: string;
};

export default UpdatePolicyRoomNameParams;
2 changes: 1 addition & 1 deletion src/libs/ErrorUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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
2 changes: 1 addition & 1 deletion src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function isExpensifyGuideTeam(email: string): boolean {
/**
* Checks if the current user is an admin of the policy.
*/
const isPolicyAdmin = (policy: OnyxEntry<Policy>): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN;
const isPolicyAdmin = (policy: OnyxEntry<Policy> | undefined): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN;
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
6 changes: 3 additions & 3 deletions src/libs/ReportUtils.ts
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4269,7 +4269,7 @@ function getWorkspaceChats(policyID: string, accountIDs: number[]): Array<OnyxEn
/**
* @param policy - the workspace the report is on, null if the user isn't a member of the workspace
*/
function shouldDisableRename(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
function shouldDisableRename(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> | undefined): boolean {
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
if (isDefaultRoom(report) || isArchivedRoom(report) || isThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) {
return true;
}
Expand All @@ -4287,7 +4287,7 @@ function shouldDisableRename(report: OnyxEntry<Report>, policy: OnyxEntry<Policy
/**
* @param policy - the workspace the report is on, null if the user isn't a member of the workspace
*/
function canEditWriteCapability(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
function canEditWriteCapability(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> | undefined): boolean {
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
return PolicyUtils.isPolicyAdmin(policy) && !isAdminRoom(report) && !isArchivedRoom(report) && !isThread(report);
}

Expand Down Expand Up @@ -4575,7 +4575,7 @@ function getRoom(type: ValueOf<typeof CONST.REPORT.CHAT_TYPE>, policyID: string)
/**
* We only want policy owners and admins to be able to modify the welcome message, but not in thread chat.
*/
function shouldDisableWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>): boolean {
function shouldDisableWelcomeMessage(report: OnyxEntry<Report>, policy: OnyxEntry<Policy> | undefined): boolean {
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
return isMoneyRequestReport(report) || isArchivedRoom(report) || !isChatRoom(report) || isChatThread(report) || !PolicyUtils.isPolicyAdmin(policy);
}
/**
Expand Down
5 changes: 3 additions & 2 deletions src/libs/ValidationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,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 @@ -354,8 +355,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 {
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
return Object.values(reports ?? {}).some((report) => report && report.policyID === policyID && report.reportName === roomName);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1806,7 +1806,7 @@ function navigateToConciergeChatAndDeleteReport(reportID: string) {
/**
* @param policyRoomName The updated name for the policy room
*/
function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string) {
function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomName: string | undefined) {
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
const reportID = policyRoomReport.reportID;
const previousName = policyRoomReport.reportName;

Expand Down Expand Up @@ -1852,7 +1852,7 @@ function updatePolicyRoomNameAndNavigate(policyRoomReport: Report, policyRoomNam
},
];

const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName};
const parameters: UpdatePolicyRoomNameParams = {reportID, policyRoomName: policyRoomName ?? ''};

API.write(WRITE_COMMANDS.UPDATE_POLICY_ROOM_NAME, parameters, {optimisticData, successData, failureData});
Navigation.goBack(ROUTES.REPORT_SETTINGS.getRoute(reportID));
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) =>
ReportActions.updateNotificationPreference(report?.reportID ?? '', report?.notificationPreference, option.value, true, undefined, undefined, report)
}
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
initiallyFocusedOptionKey={Object.values(notificationPreferenceOptions ?? {}).find((locale) => locale.isSelected)?.keyForList}
shahinyan11 marked this conversation as resolved.
Show resolved Hide resolved
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}

NotificationPreferencePage.displayName = 'NotificationPreferencePage';

export default withReportOrNotFound()(NotificationPreferencePage);
Loading
Loading