signal-desktop/ts/components/ProfileEditorModal.tsx

144 lines
4.4 KiB
TypeScript
Raw Normal View History

2021-07-19 19:26:06 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useState } from 'react';
import { Modal } from './Modal';
import { ConfirmationDialog } from './ConfirmationDialog';
import type { PropsType as ProfileEditorPropsType } from './ProfileEditor';
import { ProfileEditor, EditState } from './ProfileEditor';
import type { ProfileDataType } from '../state/ducks/conversations';
import type { AvatarUpdateOptionsType } from '../types/Avatar';
2021-07-19 19:26:06 +00:00
export type PropsDataType = {
hasError: boolean;
2022-10-18 17:12:02 +00:00
} & Pick<ProfileEditorPropsType, 'renderEditUsernameModalBody'>;
2021-07-19 19:26:06 +00:00
type PropsType = {
myProfileChanged: (
profileData: ProfileDataType,
avatarUpdateOptions: AvatarUpdateOptionsType
2021-07-19 19:26:06 +00:00
) => unknown;
toggleProfileEditor: () => unknown;
toggleProfileEditorHasError: () => unknown;
} & PropsDataType &
Omit<ProfileEditorPropsType, 'onEditStateChanged' | 'onProfileChanged'>;
2021-07-19 19:26:06 +00:00
2022-11-18 00:45:19 +00:00
export function ProfileEditorModal({
aboutEmoji,
aboutText,
color,
conversationId,
deleteAvatarFromDisk,
deleteUsername,
familyName,
firstName,
hasCompletedUsernameLinkOnboarding,
2021-07-19 19:26:06 +00:00
hasError,
i18n,
initialEditState,
markCompletedUsernameLinkOnboarding,
2021-07-19 19:26:06 +00:00
myProfileChanged,
onSetSkinTone,
openUsernameReservationModal,
2024-07-11 19:44:09 +00:00
profileAvatarUrl,
recentEmojis,
renderEditUsernameModalBody,
replaceAvatar,
resetUsernameLink,
saveAttachment,
saveAvatarToDisk,
setUsernameEditState,
setUsernameLinkColor,
showToast,
skinTone,
2021-07-19 19:26:06 +00:00
toggleProfileEditor,
toggleProfileEditorHasError,
userAvatarData,
username,
usernameCorrupted,
usernameEditState,
usernameLink,
usernameLinkColor,
usernameLinkCorrupted,
usernameLinkState,
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
2023-02-13 18:51:41 +00:00
const MODAL_TITLES_BY_EDIT_STATE: Record<EditState, string | undefined> = {
2023-03-30 00:03:25 +00:00
[EditState.BetterAvatar]: i18n('icu:ProfileEditorModal--avatar'),
[EditState.Bio]: i18n('icu:ProfileEditorModal--about'),
[EditState.None]: i18n('icu:ProfileEditorModal--profile'),
[EditState.ProfileName]: i18n('icu:ProfileEditorModal--name'),
[EditState.Username]: i18n('icu:ProfileEditorModal--username'),
2023-07-20 03:14:08 +00:00
[EditState.UsernameLink]: undefined,
2021-07-19 19:26:06 +00:00
};
const [modalTitle, setModalTitle] = useState(
MODAL_TITLES_BY_EDIT_STATE[EditState.None]
);
2021-07-19 19:26:06 +00:00
if (hasError) {
return (
<ConfirmationDialog
2022-09-27 20:24:21 +00:00
dialogName="ProfileEditorModal.error"
2023-03-30 00:03:25 +00:00
cancelText={i18n('icu:Confirmation--confirm')}
2021-07-19 19:26:06 +00:00
i18n={i18n}
onClose={toggleProfileEditorHasError}
>
2023-03-30 00:03:25 +00:00
{i18n('icu:ProfileEditorModal--error')}
2021-07-19 19:26:06 +00:00
</ConfirmationDialog>
);
}
return (
2022-11-18 00:45:19 +00:00
<Modal
modalName="ProfileEditorModal"
hasXButton
i18n={i18n}
onClose={toggleProfileEditor}
title={modalTitle}
>
<ProfileEditor
aboutEmoji={aboutEmoji}
aboutText={aboutText}
color={color}
conversationId={conversationId}
deleteAvatarFromDisk={deleteAvatarFromDisk}
deleteUsername={deleteUsername}
familyName={familyName}
firstName={firstName}
hasCompletedUsernameLinkOnboarding={hasCompletedUsernameLinkOnboarding}
2021-07-19 19:26:06 +00:00
i18n={i18n}
initialEditState={initialEditState}
markCompletedUsernameLinkOnboarding={
markCompletedUsernameLinkOnboarding
}
2022-11-18 00:45:19 +00:00
onEditStateChanged={editState => {
setModalTitle(MODAL_TITLES_BY_EDIT_STATE[editState]);
}}
onProfileChanged={myProfileChanged}
onSetSkinTone={onSetSkinTone}
openUsernameReservationModal={openUsernameReservationModal}
2024-07-11 19:44:09 +00:00
profileAvatarUrl={profileAvatarUrl}
recentEmojis={recentEmojis}
renderEditUsernameModalBody={renderEditUsernameModalBody}
replaceAvatar={replaceAvatar}
resetUsernameLink={resetUsernameLink}
saveAttachment={saveAttachment}
saveAvatarToDisk={saveAvatarToDisk}
setUsernameEditState={setUsernameEditState}
setUsernameLinkColor={setUsernameLinkColor}
showToast={showToast}
skinTone={skinTone}
2024-02-06 18:35:59 +00:00
toggleProfileEditor={toggleProfileEditor}
userAvatarData={userAvatarData}
username={username}
usernameCorrupted={usernameCorrupted}
usernameEditState={usernameEditState}
usernameLink={usernameLink}
usernameLinkColor={usernameLinkColor}
usernameLinkCorrupted={usernameLinkCorrupted}
usernameLinkState={usernameLinkState}
2022-11-18 00:45:19 +00:00
/>
</Modal>
2021-07-19 19:26:06 +00:00
);
2022-11-18 00:45:19 +00:00
}