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 'WorkspaceInvite' page to TypeScript #35080

Merged
merged 17 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ type OnyxValues = {
[ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES]: OnyxTypes.RecentlyUsedCategories;
[ONYXKEYS.COLLECTION.POLICY_REPORT_FIELDS]: OnyxTypes.PolicyReportFields;
[ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST]: OnyxTypes.PolicyMembers;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: Record<string, number>;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT]: OnyxTypes.InvitedEmailsToAccountIDs | undefined;
[ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MESSAGE_DRAFT]: string | undefined;
[ONYXKEYS.COLLECTION.REPORT]: OnyxTypes.Report;
[ONYXKEYS.COLLECTION.REPORT_METADATA]: OnyxTypes.ReportMetadata;
[ONYXKEYS.COLLECTION.REPORT_ACTIONS]: OnyxTypes.ReportActions;
Expand Down
5 changes: 4 additions & 1 deletion src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type User = {
login?: string;

/** Element to show on the right side of the item */
rightElement?: ReactElement;
rightElement?: ReactNode;

/** Icons for the user (can be multiple if it's a Workspace) */
icons?: Icon[];
Expand Down Expand Up @@ -129,6 +129,9 @@ type Section<TItem extends User | RadioItem> = {

/** Whether this section items disabled for selection */
isDisabled?: boolean;

/** Whether this section should be shown or not */
shouldShow?: boolean;
};

type BaseSelectionListProps<TItem extends User | RadioItem> = Partial<ChildrenProps> & {
Expand Down
22 changes: 13 additions & 9 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import lodashGet from 'lodash/get';
import lodashOrderBy from 'lodash/orderBy';
import lodashSet from 'lodash/set';
import lodashSortBy from 'lodash/sortBy';
import type {ReactElement} from 'react';
import Onyx from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import CONST from '@src/CONST';
Expand All @@ -29,7 +30,6 @@ import type {Participant} from '@src/types/onyx/IOU';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {PolicyTaxRate, PolicyTaxRates} from '@src/types/onyx/PolicyTaxRates';
import type DeepValueOf from '@src/types/utils/DeepValueOf';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import times from '@src/utils/times';
import Timing from './actions/Timing';
Expand Down Expand Up @@ -118,13 +118,13 @@ type GetOptionsConfig = {

type MemberForList = {
text: string;
alternateText: string | null;
keyForList: string | null;
alternateText: string;
keyForList: string;
isSelected: boolean;
isDisabled: boolean | null;
accountID?: number | null;
login: string | null;
rightElement: React.ReactNode | null;
isDisabled: boolean;
accountID?: number;
login: string;
rightElement: ReactElement | null;
icons?: OnyxCommon.Icon[];
pendingAction?: OnyxCommon.PendingAction;
};
Expand Down Expand Up @@ -1837,12 +1837,14 @@ function getShareDestinationOptions(
* @param member - personalDetails or userToInvite
* @param config - keys to overwrite the default values
*/
function formatMemberForList(member: ReportUtils.OptionData, config: ReportUtils.OptionData | EmptyObject = {}): MemberForList | undefined {
function formatMemberForList(member: ReportUtils.OptionData, config?: Partial<MemberForList>): MemberForList;
function formatMemberForList(member: null | undefined, config?: Partial<MemberForList>): undefined;
function formatMemberForList(member: ReportUtils.OptionData | null | undefined, config: Partial<MemberForList> = {}): MemberForList | undefined {
if (!member) {
return undefined;
}

const accountID = member.accountID;
const accountID = member.accountID ?? undefined;

return {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down Expand Up @@ -2022,3 +2024,5 @@ export {
formatSectionsFromSearchTerm,
transformedTaxRates,
};

export type {MemberForList};
VickyStash marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 16 additions & 4 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, PolicyMember, PolicyTags, RecentlyUsedCategories, RecentlyUsedTags, ReimbursementAccount, Report, ReportAction, Transaction} from '@src/types/onyx';
import type {
InvitedEmailsToAccountIDs,
PersonalDetailsList,
Policy,
PolicyMember,
PolicyTags,
RecentlyUsedCategories,
RecentlyUsedTags,
ReimbursementAccount,
Report,
ReportAction,
Transaction,
} from '@src/types/onyx';
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {CustomUnit} from '@src/types/onyx/Policy';
import type {EmptyObject} from '@src/types/utils/EmptyObject';
Expand Down Expand Up @@ -518,7 +530,7 @@ function removeMembers(accountIDs: number[], policyID: string) {
*
* @returns - object with onyxSuccessData, onyxOptimisticData, and optimisticReportIDs (map login to reportID)
*/
function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: Record<string, number>, hasOutstandingChildRequest = false): WorkspaceMembersChats {
function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs, hasOutstandingChildRequest = false): WorkspaceMembersChats {
const workspaceMembersChats: WorkspaceMembersChats = {
onyxSuccessData: [],
onyxOptimisticData: [],
Expand Down Expand Up @@ -607,7 +619,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: R
/**
* Adds members to the specified workspace/policyID
*/
function addMembersToWorkspace(invitedEmailsToAccountIDs: Record<string, number>, welcomeNote: string, policyID: string) {
function addMembersToWorkspace(invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs, welcomeNote: string, policyID: string) {
const membersListKey = `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}` as const;
const logins = Object.keys(invitedEmailsToAccountIDs).map((memberLogin) => OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin));
const accountIDs = Object.values(invitedEmailsToAccountIDs);
Expand Down Expand Up @@ -1499,7 +1511,7 @@ function openDraftWorkspaceRequest(policyID: string) {
API.read(READ_COMMANDS.OPEN_DRAFT_WORKSPACE_REQUEST, params);
}

function setWorkspaceInviteMembersDraft(policyID: string, invitedEmailsToAccountIDs: Record<string, number>) {
function setWorkspaceInviteMembersDraft(policyID: string, invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs) {
Onyx.set(`${ONYXKEYS.COLLECTION.WORKSPACE_INVITE_MEMBERS_DRAFT}${policyID}`, invitedEmailsToAccountIDs);
}

Expand Down
6 changes: 3 additions & 3 deletions src/pages/RoomInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function RoomInvitePage(props) {

// Update selectedOptions with the latest personalDetails information
const detailsMap = {};
_.forEach(inviteOptions.personalDetails, (detail) => (detailsMap[detail.login] = OptionsListUtils.formatMemberForList(detail, false)));
_.forEach(inviteOptions.personalDetails, (detail) => (detailsMap[detail.login] = OptionsListUtils.formatMemberForList(detail)));
const newSelectedOptions = [];
_.forEach(selectedOptions, (option) => {
newSelectedOptions.push(_.has(detailsMap, option.login) ? {...detailsMap[option.login], isSelected: true} : option);
Expand Down Expand Up @@ -142,7 +142,7 @@ function RoomInvitePage(props) {
// Filtering out selected users from the search results
const selectedLogins = _.map(selectedOptions, ({login}) => login);
const personalDetailsWithoutSelected = _.filter(personalDetails, ({login}) => !_.contains(selectedLogins, login));
const personalDetailsFormatted = _.map(personalDetailsWithoutSelected, (personalDetail) => OptionsListUtils.formatMemberForList(personalDetail, false));
const personalDetailsFormatted = _.map(personalDetailsWithoutSelected, (personalDetail) => OptionsListUtils.formatMemberForList(personalDetail));
const hasUnselectedUserToInvite = userToInvite && !_.contains(selectedLogins, userToInvite.login);

sectionsArr.push({
Expand All @@ -156,7 +156,7 @@ function RoomInvitePage(props) {
if (hasUnselectedUserToInvite) {
sectionsArr.push({
title: undefined,
data: [OptionsListUtils.formatMemberForList(userToInvite, false)],
data: [OptionsListUtils.formatMemberForList(userToInvite)],
shouldShow: true,
indexOffset,
});
Expand Down
Loading
Loading