signal-desktop/ts/components/ProfileEditorModal.tsx

80 lines
2.3 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 { AvatarUpdateType } 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,
avatar: AvatarUpdateType
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({
2021-07-19 19:26:06 +00:00
hasError,
i18n,
myProfileChanged,
onSetSkinTone,
toggleProfileEditor,
toggleProfileEditorHasError,
...restProps
2022-11-18 00:45:19 +00:00
}: PropsType): JSX.Element {
const MODAL_TITLES_BY_EDIT_STATE: Record<EditState, string> = {
[EditState.BetterAvatar]: i18n('ProfileEditorModal--avatar'),
[EditState.Bio]: i18n('ProfileEditorModal--about'),
[EditState.None]: i18n('ProfileEditorModal--profile'),
[EditState.ProfileName]: i18n('ProfileEditorModal--name'),
[EditState.Username]: i18n('ProfileEditorModal--username'),
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"
2021-07-19 19:26:06 +00:00
cancelText={i18n('Confirmation--confirm')}
i18n={i18n}
onClose={toggleProfileEditorHasError}
>
{i18n('ProfileEditorModal--error')}
</ConfirmationDialog>
);
}
return (
2022-11-18 00:45:19 +00:00
<Modal
modalName="ProfileEditorModal"
hasXButton
i18n={i18n}
onClose={toggleProfileEditor}
title={modalTitle}
>
<ProfileEditor
{...restProps}
2021-07-19 19:26:06 +00:00
i18n={i18n}
2022-11-18 00:45:19 +00:00
onEditStateChanged={editState => {
setModalTitle(MODAL_TITLES_BY_EDIT_STATE[editState]);
}}
onProfileChanged={myProfileChanged}
onSetSkinTone={onSetSkinTone}
/>
</Modal>
2021-07-19 19:26:06 +00:00
);
2022-11-18 00:45:19 +00:00
}