2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2021-07-19 19:26:06 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { AvatarColorType } from '../types/Colors';
|
|
|
|
import { AvatarColors } from '../types/Colors';
|
|
|
|
import type {
|
2021-08-06 00:17:05 +00:00
|
|
|
AvatarDataType,
|
2022-03-16 00:14:20 +00:00
|
|
|
AvatarUpdateType,
|
2021-08-06 00:17:05 +00:00
|
|
|
DeleteAvatarFromDiskActionType,
|
|
|
|
ReplaceAvatarActionType,
|
|
|
|
SaveAvatarToDiskActionType,
|
|
|
|
} from '../types/Avatar';
|
|
|
|
import { AvatarEditor } from './AvatarEditor';
|
|
|
|
import { AvatarPreview } from './AvatarPreview';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { Button, ButtonVariant } from './Button';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { ConfirmDiscardDialog } from './ConfirmDiscardDialog';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { Emoji } from './emoji/Emoji';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { Props as EmojiButtonProps } from './emoji/EmojiButton';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { EmojiButton, EmojiButtonVariant } from './emoji/EmojiButton';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { EmojiPickDataType } from './emoji/EmojiPicker';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { Input } from './Input';
|
|
|
|
import { Intl } from './Intl';
|
2022-10-18 17:12:02 +00:00
|
|
|
import type { LocalizerType } from '../types/Util';
|
2021-08-06 00:17:05 +00:00
|
|
|
import { Modal } from './Modal';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { PanelRow } from './conversation/conversation-details/PanelRow';
|
2023-07-20 03:14:08 +00:00
|
|
|
import type {
|
|
|
|
ProfileDataType,
|
|
|
|
SaveAttachmentActionCreatorType,
|
|
|
|
} from '../state/ducks/conversations';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { UsernameEditState } from '../state/ducks/usernameEnums';
|
2023-07-20 03:14:08 +00:00
|
|
|
import type { UsernameLinkState } from '../state/ducks/usernameEnums';
|
2022-12-15 00:48:36 +00:00
|
|
|
import { ToastType } from '../types/Toast';
|
2023-04-10 21:38:34 +00:00
|
|
|
import type { ShowToastAction } from '../state/ducks/toast';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { getEmojiData, unifiedToEmoji } from './emoji/lib';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { assertDev } from '../util/assert';
|
2021-07-19 19:26:06 +00:00
|
|
|
import { missingCaseError } from '../util/missingCaseError';
|
2021-11-01 19:13:35 +00:00
|
|
|
import { ConfirmationDialog } from './ConfirmationDialog';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { ContextMenu } from './ContextMenu';
|
2023-07-20 03:14:08 +00:00
|
|
|
import { UsernameLinkModalBody } from './UsernameLinkModalBody';
|
2023-02-13 18:51:41 +00:00
|
|
|
import { UsernameOnboardingModalBody } from './UsernameOnboardingModalBody';
|
2021-11-01 19:13:35 +00:00
|
|
|
import {
|
|
|
|
ConversationDetailsIcon,
|
|
|
|
IconType,
|
|
|
|
} from './conversation/conversation-details/ConversationDetailsIcon';
|
2022-01-26 21:58:00 +00:00
|
|
|
import { isWhitespace, trim } from '../util/whitespaceStringUtil';
|
2023-04-20 17:03:43 +00:00
|
|
|
import { UserText } from './UserText';
|
2023-07-20 03:14:08 +00:00
|
|
|
import { Tooltip, TooltipPlacement } from './Tooltip';
|
2021-07-19 19:26:06 +00:00
|
|
|
|
|
|
|
export enum EditState {
|
|
|
|
None = 'None',
|
2021-08-06 00:17:05 +00:00
|
|
|
BetterAvatar = 'BetterAvatar',
|
2021-07-19 19:26:06 +00:00
|
|
|
ProfileName = 'ProfileName',
|
|
|
|
Bio = 'Bio',
|
2021-11-01 19:13:35 +00:00
|
|
|
Username = 'Username',
|
2023-02-13 18:51:41 +00:00
|
|
|
UsernameOnboarding = 'UsernameOnboarding',
|
2023-07-20 03:14:08 +00:00
|
|
|
UsernameLink = 'UsernameLink',
|
2021-11-01 19:13:35 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
type PropsExternalType = {
|
|
|
|
onEditStateChanged: (editState: EditState) => unknown;
|
|
|
|
onProfileChanged: (
|
|
|
|
profileData: ProfileDataType,
|
2022-03-16 00:14:20 +00:00
|
|
|
avatar: AvatarUpdateType
|
2021-07-19 19:26:06 +00:00
|
|
|
) => unknown;
|
2022-10-18 17:12:02 +00:00
|
|
|
renderEditUsernameModalBody: (props: { onClose: () => void }) => JSX.Element;
|
2021-07-19 19:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsDataType = {
|
|
|
|
aboutEmoji?: string;
|
|
|
|
aboutText?: string;
|
2022-03-16 00:14:20 +00:00
|
|
|
profileAvatarPath?: string;
|
2021-08-06 00:17:05 +00:00
|
|
|
color?: AvatarColorType;
|
|
|
|
conversationId: string;
|
2021-07-19 19:26:06 +00:00
|
|
|
familyName?: string;
|
|
|
|
firstName: string;
|
2023-02-13 18:51:41 +00:00
|
|
|
hasCompletedUsernameOnboarding: boolean;
|
2023-07-20 03:14:08 +00:00
|
|
|
hasCompletedUsernameLinkOnboarding: boolean;
|
2021-07-19 19:26:06 +00:00
|
|
|
i18n: LocalizerType;
|
2021-11-01 19:13:35 +00:00
|
|
|
isUsernameFlagEnabled: boolean;
|
2023-08-14 23:28:47 +00:00
|
|
|
phoneNumber?: string;
|
2022-12-22 00:07:02 +00:00
|
|
|
userAvatarData: ReadonlyArray<AvatarDataType>;
|
2021-11-01 19:13:35 +00:00
|
|
|
username?: string;
|
2022-10-18 17:12:02 +00:00
|
|
|
usernameEditState: UsernameEditState;
|
2023-07-20 03:14:08 +00:00
|
|
|
usernameLinkState: UsernameLinkState;
|
|
|
|
usernameLinkColor?: number;
|
|
|
|
usernameLink?: string;
|
2021-07-19 19:26:06 +00:00
|
|
|
} & Pick<EmojiButtonProps, 'recentEmojis' | 'skinTone'>;
|
|
|
|
|
|
|
|
type PropsActionType = {
|
2021-08-06 00:17:05 +00:00
|
|
|
deleteAvatarFromDisk: DeleteAvatarFromDiskActionType;
|
2023-07-20 03:14:08 +00:00
|
|
|
markCompletedUsernameOnboarding: () => void;
|
|
|
|
markCompletedUsernameLinkOnboarding: () => void;
|
2021-07-19 19:26:06 +00:00
|
|
|
onSetSkinTone: (tone: number) => unknown;
|
2021-08-06 00:17:05 +00:00
|
|
|
replaceAvatar: ReplaceAvatarActionType;
|
2023-07-20 03:14:08 +00:00
|
|
|
saveAttachment: SaveAttachmentActionCreatorType;
|
2021-08-06 00:17:05 +00:00
|
|
|
saveAvatarToDisk: SaveAvatarToDiskActionType;
|
2022-10-18 17:12:02 +00:00
|
|
|
setUsernameEditState: (editState: UsernameEditState) => void;
|
2023-07-20 03:14:08 +00:00
|
|
|
setUsernameLinkColor: (color: number) => void;
|
|
|
|
resetUsernameLink: () => void;
|
2022-10-18 17:12:02 +00:00
|
|
|
deleteUsername: () => void;
|
2023-04-10 21:38:34 +00:00
|
|
|
showToast: ShowToastAction;
|
2022-10-18 17:12:02 +00:00
|
|
|
openUsernameReservationModal: () => void;
|
2021-07-19 19:26:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type PropsType = PropsDataType & PropsActionType & PropsExternalType;
|
|
|
|
|
|
|
|
type DefaultBio = {
|
|
|
|
i18nLabel: string;
|
|
|
|
shortName: string;
|
|
|
|
};
|
|
|
|
|
2023-03-28 18:26:46 +00:00
|
|
|
function getDefaultBios(i18n: LocalizerType): Array<DefaultBio> {
|
|
|
|
return [
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
i18nLabel: i18n('icu:Bio--speak-freely'),
|
2023-03-28 18:26:46 +00:00
|
|
|
shortName: 'wave',
|
|
|
|
},
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
i18nLabel: i18n('icu:Bio--encrypted'),
|
2023-03-28 18:26:46 +00:00
|
|
|
shortName: 'zipper_mouth_face',
|
|
|
|
},
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
i18nLabel: i18n('icu:Bio--free-to-chat'),
|
2023-03-28 18:26:46 +00:00
|
|
|
shortName: '+1',
|
|
|
|
},
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
i18nLabel: i18n('icu:Bio--coffee-lover'),
|
2023-03-28 18:26:46 +00:00
|
|
|
shortName: 'coffee',
|
|
|
|
},
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
i18nLabel: i18n('icu:Bio--taking-break'),
|
2023-03-28 18:26:46 +00:00
|
|
|
shortName: 'mobile_phone_off',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
2021-07-19 19:26:06 +00:00
|
|
|
|
2022-11-18 00:45:19 +00:00
|
|
|
export function ProfileEditor({
|
2021-07-19 19:26:06 +00:00
|
|
|
aboutEmoji,
|
|
|
|
aboutText,
|
2021-08-06 00:17:05 +00:00
|
|
|
color,
|
|
|
|
conversationId,
|
|
|
|
deleteAvatarFromDisk,
|
2022-10-18 17:12:02 +00:00
|
|
|
deleteUsername,
|
2021-07-19 19:26:06 +00:00
|
|
|
familyName,
|
|
|
|
firstName,
|
2023-02-13 18:51:41 +00:00
|
|
|
hasCompletedUsernameOnboarding,
|
2023-07-20 03:14:08 +00:00
|
|
|
hasCompletedUsernameLinkOnboarding,
|
2021-07-19 19:26:06 +00:00
|
|
|
i18n,
|
2021-11-01 19:13:35 +00:00
|
|
|
isUsernameFlagEnabled,
|
2023-02-13 18:51:41 +00:00
|
|
|
markCompletedUsernameOnboarding,
|
2023-07-20 03:14:08 +00:00
|
|
|
markCompletedUsernameLinkOnboarding,
|
2021-07-19 19:26:06 +00:00
|
|
|
onEditStateChanged,
|
|
|
|
onProfileChanged,
|
|
|
|
onSetSkinTone,
|
2022-10-18 17:12:02 +00:00
|
|
|
openUsernameReservationModal,
|
2023-08-14 23:28:47 +00:00
|
|
|
phoneNumber,
|
2022-10-18 17:12:02 +00:00
|
|
|
profileAvatarPath,
|
2021-07-19 19:26:06 +00:00
|
|
|
recentEmojis,
|
2022-10-18 17:12:02 +00:00
|
|
|
renderEditUsernameModalBody,
|
2021-08-06 00:17:05 +00:00
|
|
|
replaceAvatar,
|
2023-07-20 03:14:08 +00:00
|
|
|
resetUsernameLink,
|
|
|
|
saveAttachment,
|
2021-08-06 00:17:05 +00:00
|
|
|
saveAvatarToDisk,
|
2022-10-18 17:12:02 +00:00
|
|
|
setUsernameEditState,
|
2023-07-20 03:14:08 +00:00
|
|
|
setUsernameLinkColor,
|
2022-10-18 17:12:02 +00:00
|
|
|
showToast,
|
2021-07-19 19:26:06 +00:00
|
|
|
skinTone,
|
2021-08-06 00:17:05 +00:00
|
|
|
userAvatarData,
|
2021-11-01 19:13:35 +00:00
|
|
|
username,
|
2022-10-18 17:12:02 +00:00
|
|
|
usernameEditState,
|
2023-07-20 03:14:08 +00:00
|
|
|
usernameLinkState,
|
|
|
|
usernameLinkColor,
|
|
|
|
usernameLink,
|
2022-11-18 00:45:19 +00:00
|
|
|
}: PropsType): JSX.Element {
|
2021-07-19 19:26:06 +00:00
|
|
|
const focusInputRef = useRef<HTMLInputElement | null>(null);
|
|
|
|
const [editState, setEditState] = useState<EditState>(EditState.None);
|
|
|
|
const [confirmDiscardAction, setConfirmDiscardAction] = useState<
|
|
|
|
(() => unknown) | undefined
|
|
|
|
>(undefined);
|
|
|
|
|
|
|
|
// This is here to avoid component re-render jitters in the time it takes
|
|
|
|
// redux to come back with the correct state
|
|
|
|
const [fullName, setFullName] = useState({
|
|
|
|
familyName,
|
|
|
|
firstName,
|
|
|
|
});
|
|
|
|
const [fullBio, setFullBio] = useState({
|
|
|
|
aboutEmoji,
|
|
|
|
aboutText,
|
|
|
|
});
|
2022-03-16 00:14:20 +00:00
|
|
|
const [startingAvatarPath, setStartingAvatarPath] =
|
|
|
|
useState(profileAvatarPath);
|
|
|
|
|
|
|
|
const [oldAvatarBuffer, setOldAvatarBuffer] = useState<
|
|
|
|
Uint8Array | undefined
|
|
|
|
>(undefined);
|
2021-09-24 00:49:05 +00:00
|
|
|
const [avatarBuffer, setAvatarBuffer] = useState<Uint8Array | undefined>(
|
2021-07-19 19:26:06 +00:00
|
|
|
undefined
|
|
|
|
);
|
2022-04-08 02:44:26 +00:00
|
|
|
const [isLoadingAvatar, setIsLoadingAvatar] = useState(
|
|
|
|
Boolean(profileAvatarPath)
|
|
|
|
);
|
2021-07-19 19:26:06 +00:00
|
|
|
const [stagedProfile, setStagedProfile] = useState<ProfileDataType>({
|
|
|
|
aboutEmoji,
|
|
|
|
aboutText,
|
|
|
|
familyName,
|
|
|
|
firstName,
|
|
|
|
});
|
|
|
|
|
2022-10-18 17:12:02 +00:00
|
|
|
// Reset username edit state when leaving
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
setUsernameEditState(UsernameEditState.Editing);
|
|
|
|
};
|
|
|
|
}, [setUsernameEditState]);
|
|
|
|
|
2021-11-01 19:13:35 +00:00
|
|
|
// To make AvatarEditor re-render less often
|
2021-07-19 19:26:06 +00:00
|
|
|
const handleBack = useCallback(() => {
|
|
|
|
setEditState(EditState.None);
|
|
|
|
onEditStateChanged(EditState.None);
|
|
|
|
}, [setEditState, onEditStateChanged]);
|
|
|
|
|
2021-11-01 19:13:35 +00:00
|
|
|
// To make EmojiButton re-render less often
|
2021-07-19 19:26:06 +00:00
|
|
|
const setAboutEmoji = useCallback(
|
|
|
|
(ev: EmojiPickDataType) => {
|
|
|
|
const emojiData = getEmojiData(ev.shortName, skinTone);
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
aboutEmoji: unifiedToEmoji(emojiData.unified),
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
[setStagedProfile, skinTone]
|
|
|
|
);
|
|
|
|
|
2021-11-01 19:13:35 +00:00
|
|
|
// To make AvatarEditor re-render less often
|
2021-07-19 19:26:06 +00:00
|
|
|
const handleAvatarChanged = useCallback(
|
2021-09-24 00:49:05 +00:00
|
|
|
(avatar: Uint8Array | undefined) => {
|
2022-03-16 00:14:20 +00:00
|
|
|
// Do not display stale avatar from disk anymore.
|
|
|
|
setStartingAvatarPath(undefined);
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
setAvatarBuffer(avatar);
|
|
|
|
setEditState(EditState.None);
|
2022-01-26 21:58:00 +00:00
|
|
|
onProfileChanged(
|
|
|
|
{
|
|
|
|
...stagedProfile,
|
|
|
|
firstName: trim(stagedProfile.firstName),
|
|
|
|
familyName: stagedProfile.familyName
|
|
|
|
? trim(stagedProfile.familyName)
|
|
|
|
: undefined,
|
|
|
|
},
|
2022-03-16 00:14:20 +00:00
|
|
|
{ oldAvatar: oldAvatarBuffer, newAvatar: avatar }
|
2022-01-26 21:58:00 +00:00
|
|
|
);
|
2022-03-16 00:14:20 +00:00
|
|
|
setOldAvatarBuffer(avatar);
|
2021-07-19 19:26:06 +00:00
|
|
|
},
|
2022-03-16 00:14:20 +00:00
|
|
|
[onProfileChanged, stagedProfile, oldAvatarBuffer]
|
2021-07-19 19:26:06 +00:00
|
|
|
);
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
const getFullNameText = () => {
|
|
|
|
return [fullName.firstName, fullName.familyName].filter(Boolean).join(' ');
|
|
|
|
};
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
useEffect(() => {
|
|
|
|
const focusNode = focusInputRef.current;
|
|
|
|
if (!focusNode) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
focusNode.focus();
|
2021-10-01 19:27:34 +00:00
|
|
|
focusNode.setSelectionRange(focusNode.value.length, focusNode.value.length);
|
2021-07-19 19:26:06 +00:00
|
|
|
}, [editState]);
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
useEffect(() => {
|
|
|
|
onEditStateChanged(editState);
|
|
|
|
}, [editState, onEditStateChanged]);
|
|
|
|
|
2021-11-01 19:13:35 +00:00
|
|
|
// To make AvatarEditor re-render less often
|
2022-03-16 00:14:20 +00:00
|
|
|
const handleAvatarLoaded = useCallback(
|
|
|
|
avatar => {
|
|
|
|
setAvatarBuffer(avatar);
|
|
|
|
setOldAvatarBuffer(avatar);
|
|
|
|
setIsLoadingAvatar(false);
|
|
|
|
},
|
|
|
|
[setAvatarBuffer, setOldAvatarBuffer, setIsLoadingAvatar]
|
|
|
|
);
|
2021-08-06 00:17:05 +00:00
|
|
|
|
|
|
|
let content: JSX.Element;
|
|
|
|
|
|
|
|
if (editState === EditState.BetterAvatar) {
|
|
|
|
content = (
|
|
|
|
<AvatarEditor
|
|
|
|
avatarColor={color || AvatarColors[0]}
|
2022-03-16 00:14:20 +00:00
|
|
|
avatarPath={startingAvatarPath}
|
2021-08-06 00:17:05 +00:00
|
|
|
avatarValue={avatarBuffer}
|
|
|
|
conversationId={conversationId}
|
|
|
|
conversationTitle={getFullNameText()}
|
|
|
|
deleteAvatarFromDisk={deleteAvatarFromDisk}
|
|
|
|
i18n={i18n}
|
|
|
|
onCancel={handleBack}
|
|
|
|
onSave={handleAvatarChanged}
|
|
|
|
userAvatarData={userAvatarData}
|
|
|
|
replaceAvatar={replaceAvatar}
|
|
|
|
saveAvatarToDisk={saveAvatarToDisk}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else if (editState === EditState.ProfileName) {
|
2021-07-21 20:45:41 +00:00
|
|
|
const shouldDisableSave =
|
2022-03-16 00:14:20 +00:00
|
|
|
isLoadingAvatar ||
|
2021-07-21 20:45:41 +00:00
|
|
|
!stagedProfile.firstName ||
|
|
|
|
(stagedProfile.firstName === fullName.firstName &&
|
2022-01-26 21:58:00 +00:00
|
|
|
stagedProfile.familyName === fullName.familyName) ||
|
|
|
|
isWhitespace(stagedProfile.firstName);
|
2021-07-21 20:45:41 +00:00
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
<Input
|
|
|
|
i18n={i18n}
|
2021-10-05 18:47:47 +00:00
|
|
|
maxLengthCount={26}
|
|
|
|
maxByteCount={128}
|
2021-07-21 20:45:41 +00:00
|
|
|
whenToShowRemainingCount={0}
|
2021-07-19 19:26:06 +00:00
|
|
|
onChange={newFirstName => {
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
firstName: String(newFirstName),
|
|
|
|
}));
|
|
|
|
}}
|
2023-03-30 00:03:25 +00:00
|
|
|
placeholder={i18n('icu:ProfileEditor--first-name')}
|
2021-07-19 19:26:06 +00:00
|
|
|
ref={focusInputRef}
|
|
|
|
value={stagedProfile.firstName}
|
|
|
|
/>
|
|
|
|
<Input
|
|
|
|
i18n={i18n}
|
2021-10-05 18:47:47 +00:00
|
|
|
maxLengthCount={26}
|
|
|
|
maxByteCount={128}
|
2021-07-21 20:45:41 +00:00
|
|
|
whenToShowRemainingCount={0}
|
2021-07-19 19:26:06 +00:00
|
|
|
onChange={newFamilyName => {
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
familyName: newFamilyName,
|
|
|
|
}));
|
|
|
|
}}
|
2023-03-30 00:03:25 +00:00
|
|
|
placeholder={i18n('icu:ProfileEditor--last-name')}
|
2021-07-19 19:26:06 +00:00
|
|
|
value={stagedProfile.familyName}
|
|
|
|
/>
|
2021-08-06 00:17:05 +00:00
|
|
|
<Modal.ButtonFooter>
|
2021-07-19 19:26:06 +00:00
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
const handleCancel = () => {
|
|
|
|
handleBack();
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
familyName,
|
|
|
|
firstName,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasChanges =
|
|
|
|
stagedProfile.familyName !== fullName.familyName ||
|
|
|
|
stagedProfile.firstName !== fullName.firstName;
|
|
|
|
if (hasChanges) {
|
|
|
|
setConfirmDiscardAction(() => handleCancel);
|
|
|
|
} else {
|
|
|
|
handleCancel();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
variant={ButtonVariant.Secondary}
|
|
|
|
>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:cancel')}
|
2021-07-19 19:26:06 +00:00
|
|
|
</Button>
|
|
|
|
<Button
|
2021-07-21 20:45:41 +00:00
|
|
|
disabled={shouldDisableSave}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (!stagedProfile.firstName) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
setFullName({
|
2021-07-21 20:45:41 +00:00
|
|
|
firstName: stagedProfile.firstName,
|
|
|
|
familyName: stagedProfile.familyName,
|
2021-07-19 19:26:06 +00:00
|
|
|
});
|
|
|
|
|
2022-03-16 00:14:20 +00:00
|
|
|
onProfileChanged(stagedProfile, {
|
|
|
|
oldAvatar: oldAvatarBuffer,
|
|
|
|
newAvatar: avatarBuffer,
|
|
|
|
});
|
2021-07-19 19:26:06 +00:00
|
|
|
handleBack();
|
|
|
|
}}
|
|
|
|
>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:save')}
|
2021-07-19 19:26:06 +00:00
|
|
|
</Button>
|
2021-08-06 00:17:05 +00:00
|
|
|
</Modal.ButtonFooter>
|
2021-07-19 19:26:06 +00:00
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else if (editState === EditState.Bio) {
|
2021-07-21 20:45:41 +00:00
|
|
|
const shouldDisableSave =
|
2022-03-16 00:14:20 +00:00
|
|
|
isLoadingAvatar ||
|
|
|
|
(stagedProfile.aboutText === fullBio.aboutText &&
|
|
|
|
stagedProfile.aboutEmoji === fullBio.aboutEmoji);
|
2021-07-21 20:45:41 +00:00
|
|
|
|
2023-03-28 18:26:46 +00:00
|
|
|
const defaultBios = getDefaultBios(i18n);
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
content = (
|
|
|
|
<>
|
|
|
|
<Input
|
|
|
|
expandable
|
|
|
|
hasClearButton
|
|
|
|
i18n={i18n}
|
|
|
|
icon={
|
|
|
|
<div className="module-composition-area__button-cell">
|
|
|
|
<EmojiButton
|
2022-10-18 17:12:02 +00:00
|
|
|
variant={EmojiButtonVariant.ProfileEditor}
|
2021-07-19 19:26:06 +00:00
|
|
|
closeOnPick
|
|
|
|
emoji={stagedProfile.aboutEmoji}
|
|
|
|
i18n={i18n}
|
|
|
|
onPickEmoji={setAboutEmoji}
|
|
|
|
onSetSkinTone={onSetSkinTone}
|
|
|
|
recentEmojis={recentEmojis}
|
|
|
|
skinTone={skinTone}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2021-07-21 20:45:41 +00:00
|
|
|
maxLengthCount={140}
|
2021-10-05 18:47:47 +00:00
|
|
|
maxByteCount={512}
|
2021-07-19 19:26:06 +00:00
|
|
|
moduleClassName="ProfileEditor__about-input"
|
|
|
|
onChange={value => {
|
|
|
|
if (value) {
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
aboutEmoji: stagedProfile.aboutEmoji,
|
2021-10-01 19:27:34 +00:00
|
|
|
aboutText: value.replace(/(\r\n|\n|\r)/gm, ''),
|
2021-07-19 19:26:06 +00:00
|
|
|
}));
|
|
|
|
} else {
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
aboutEmoji: undefined,
|
|
|
|
aboutText: '',
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
ref={focusInputRef}
|
2023-03-30 00:03:25 +00:00
|
|
|
placeholder={i18n('icu:ProfileEditor--about-placeholder')}
|
2021-07-19 19:26:06 +00:00
|
|
|
value={stagedProfile.aboutText}
|
|
|
|
whenToShowRemainingCount={40}
|
|
|
|
/>
|
|
|
|
|
2023-03-28 18:26:46 +00:00
|
|
|
{defaultBios.map(defaultBio => (
|
2021-07-19 19:26:06 +00:00
|
|
|
<PanelRow
|
|
|
|
className="ProfileEditor__row"
|
|
|
|
key={defaultBio.shortName}
|
|
|
|
icon={
|
|
|
|
<div className="ProfileEditor__icon--container">
|
|
|
|
<Emoji shortName={defaultBio.shortName} size={24} />
|
|
|
|
</div>
|
|
|
|
}
|
2023-03-28 18:26:46 +00:00
|
|
|
label={defaultBio.i18nLabel}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
const emojiData = getEmojiData(defaultBio.shortName, skinTone);
|
|
|
|
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
aboutEmoji: unifiedToEmoji(emojiData.unified),
|
2023-03-28 18:26:46 +00:00
|
|
|
aboutText: defaultBio.i18nLabel,
|
2021-07-19 19:26:06 +00:00
|
|
|
}));
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
|
2021-08-06 00:17:05 +00:00
|
|
|
<Modal.ButtonFooter>
|
2021-07-19 19:26:06 +00:00
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
const handleCancel = () => {
|
|
|
|
handleBack();
|
|
|
|
setStagedProfile(profileData => ({
|
|
|
|
...profileData,
|
|
|
|
...fullBio,
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasChanges =
|
|
|
|
stagedProfile.aboutText !== fullBio.aboutText ||
|
|
|
|
stagedProfile.aboutEmoji !== fullBio.aboutEmoji;
|
|
|
|
if (hasChanges) {
|
|
|
|
setConfirmDiscardAction(() => handleCancel);
|
|
|
|
} else {
|
|
|
|
handleCancel();
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
variant={ButtonVariant.Secondary}
|
|
|
|
>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:cancel')}
|
2021-07-19 19:26:06 +00:00
|
|
|
</Button>
|
|
|
|
<Button
|
2021-07-21 20:45:41 +00:00
|
|
|
disabled={shouldDisableSave}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
setFullBio({
|
|
|
|
aboutEmoji: stagedProfile.aboutEmoji,
|
|
|
|
aboutText: stagedProfile.aboutText,
|
|
|
|
});
|
|
|
|
|
2022-03-16 00:14:20 +00:00
|
|
|
onProfileChanged(stagedProfile, {
|
|
|
|
oldAvatar: oldAvatarBuffer,
|
|
|
|
newAvatar: avatarBuffer,
|
|
|
|
});
|
2021-07-19 19:26:06 +00:00
|
|
|
handleBack();
|
|
|
|
}}
|
|
|
|
>
|
2023-03-30 00:03:25 +00:00
|
|
|
{i18n('icu:save')}
|
2021-07-19 19:26:06 +00:00
|
|
|
</Button>
|
2021-08-06 00:17:05 +00:00
|
|
|
</Modal.ButtonFooter>
|
2021-07-19 19:26:06 +00:00
|
|
|
</>
|
|
|
|
);
|
2021-11-01 19:13:35 +00:00
|
|
|
} else if (editState === EditState.Username) {
|
2022-10-18 17:12:02 +00:00
|
|
|
content = renderEditUsernameModalBody({
|
|
|
|
onClose: () => setEditState(EditState.None),
|
|
|
|
});
|
2023-02-13 18:51:41 +00:00
|
|
|
} else if (editState === EditState.UsernameOnboarding) {
|
|
|
|
content = (
|
|
|
|
<UsernameOnboardingModalBody
|
|
|
|
i18n={i18n}
|
|
|
|
onNext={() => {
|
|
|
|
markCompletedUsernameOnboarding();
|
|
|
|
setEditState(EditState.Username);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
2023-07-20 03:14:08 +00:00
|
|
|
} else if (editState === EditState.UsernameLink) {
|
|
|
|
content = (
|
|
|
|
<UsernameLinkModalBody
|
|
|
|
i18n={i18n}
|
|
|
|
link={usernameLink}
|
|
|
|
username={username ?? ''}
|
|
|
|
colorId={usernameLinkColor}
|
|
|
|
usernameLinkState={usernameLinkState}
|
|
|
|
setUsernameLinkColor={setUsernameLinkColor}
|
|
|
|
resetUsernameLink={resetUsernameLink}
|
|
|
|
saveAttachment={saveAttachment}
|
|
|
|
showToast={showToast}
|
|
|
|
/>
|
|
|
|
);
|
2022-10-18 17:12:02 +00:00
|
|
|
} else if (editState === EditState.None) {
|
2023-07-20 03:14:08 +00:00
|
|
|
let maybeUsernameRows: JSX.Element | undefined;
|
2022-10-18 17:12:02 +00:00
|
|
|
if (isUsernameFlagEnabled) {
|
|
|
|
let actions: JSX.Element | undefined;
|
|
|
|
|
|
|
|
if (usernameEditState === UsernameEditState.Deleting) {
|
|
|
|
actions = (
|
|
|
|
<ConversationDetailsIcon
|
2023-03-30 00:03:25 +00:00
|
|
|
ariaLabel={i18n('icu:ProfileEditor--username--deleting-username')}
|
2022-10-18 17:12:02 +00:00
|
|
|
icon={IconType.spinner}
|
|
|
|
disabled
|
|
|
|
fakeButton
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
const menuOptions = [
|
|
|
|
{
|
|
|
|
group: 'copy',
|
|
|
|
icon: 'ProfileEditor__username-menu__copy-icon',
|
2023-03-30 00:03:25 +00:00
|
|
|
label: i18n('icu:ProfileEditor--username--copy'),
|
2022-10-18 17:12:02 +00:00
|
|
|
onClick: () => {
|
|
|
|
assertDev(
|
|
|
|
username !== undefined,
|
|
|
|
'Should not be visible without username'
|
|
|
|
);
|
2022-12-21 18:41:48 +00:00
|
|
|
void window.navigator.clipboard.writeText(username);
|
2023-04-10 21:38:34 +00:00
|
|
|
showToast({ toastType: ToastType.CopiedUsername });
|
2022-10-18 17:12:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Different group to display a divider above it
|
|
|
|
group: 'delete',
|
|
|
|
|
|
|
|
icon: 'ProfileEditor__username-menu__trash-icon',
|
2023-03-30 00:03:25 +00:00
|
|
|
label: i18n('icu:ProfileEditor--username--delete'),
|
2022-10-18 17:12:02 +00:00
|
|
|
onClick: () => {
|
|
|
|
setUsernameEditState(UsernameEditState.ConfirmingDelete);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
if (username) {
|
|
|
|
actions = (
|
|
|
|
<ContextMenu
|
|
|
|
i18n={i18n}
|
|
|
|
menuOptions={menuOptions}
|
|
|
|
popperOptions={{ placement: 'bottom', strategy: 'absolute' }}
|
|
|
|
moduleClassName="ProfileEditor__username-menu"
|
2023-03-30 00:03:25 +00:00
|
|
|
ariaLabel={i18n('icu:ProfileEditor--username--context-menu')}
|
2022-10-18 17:12:02 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 03:14:08 +00:00
|
|
|
let maybeUsernameLinkRow: JSX.Element | undefined;
|
|
|
|
if (username) {
|
|
|
|
maybeUsernameLinkRow = (
|
|
|
|
<PanelRow
|
|
|
|
className="ProfileEditor__row"
|
|
|
|
icon={
|
|
|
|
<i className="ProfileEditor__icon--container ProfileEditor__icon ProfileEditor__icon--username-link" />
|
2023-02-13 18:51:41 +00:00
|
|
|
}
|
2023-07-20 03:14:08 +00:00
|
|
|
label={i18n('icu:ProfileEditor__username-link')}
|
|
|
|
onClick={() => {
|
|
|
|
setEditState(EditState.UsernameLink);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!hasCompletedUsernameLinkOnboarding) {
|
|
|
|
const tooltip = (
|
|
|
|
<div className="ProfileEditor__username-link__tooltip__container">
|
|
|
|
<div className="ProfileEditor__username-link__tooltip__icon" />
|
|
|
|
|
|
|
|
<div className="ProfileEditor__username-link__tooltip__content">
|
|
|
|
<h3>
|
|
|
|
{i18n('icu:ProfileEditor__username-link__tooltip__title')}
|
|
|
|
</h3>
|
|
|
|
<p>{i18n('icu:ProfileEditor__username-link__tooltip__body')}</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="ProfileEditor__username-link__tooltip__close"
|
|
|
|
onClick={markCompletedUsernameLinkOnboarding}
|
|
|
|
aria-label={i18n('icu:close')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
maybeUsernameLinkRow = (
|
|
|
|
<Tooltip
|
|
|
|
className="ProfileEditor__username-link__tooltip"
|
|
|
|
direction={TooltipPlacement.Bottom}
|
|
|
|
sticky
|
|
|
|
content={tooltip}
|
|
|
|
>
|
|
|
|
{maybeUsernameLinkRow}
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maybeUsernameRows = (
|
|
|
|
<>
|
|
|
|
<PanelRow
|
|
|
|
className="ProfileEditor__row"
|
|
|
|
icon={
|
|
|
|
<i className="ProfileEditor__icon--container ProfileEditor__icon ProfileEditor__icon--username" />
|
|
|
|
}
|
|
|
|
label={username || i18n('icu:ProfileEditor--username')}
|
|
|
|
onClick={() => {
|
|
|
|
openUsernameReservationModal();
|
|
|
|
if (username || hasCompletedUsernameOnboarding) {
|
|
|
|
setEditState(EditState.Username);
|
|
|
|
} else {
|
|
|
|
setEditState(EditState.UsernameOnboarding);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
actions={actions}
|
|
|
|
/>
|
|
|
|
{maybeUsernameLinkRow}
|
|
|
|
</>
|
2022-10-18 17:12:02 +00:00
|
|
|
);
|
|
|
|
}
|
2021-11-01 19:13:35 +00:00
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
content = (
|
|
|
|
<>
|
2021-08-06 00:17:05 +00:00
|
|
|
<AvatarPreview
|
|
|
|
avatarColor={color}
|
2022-03-16 00:14:20 +00:00
|
|
|
avatarPath={startingAvatarPath}
|
2021-08-06 00:17:05 +00:00
|
|
|
avatarValue={avatarBuffer}
|
|
|
|
conversationTitle={getFullNameText()}
|
2021-07-19 19:26:06 +00:00
|
|
|
i18n={i18n}
|
2021-08-06 21:35:25 +00:00
|
|
|
isEditable
|
2021-08-06 00:17:05 +00:00
|
|
|
onAvatarLoaded={handleAvatarLoaded}
|
|
|
|
onClick={() => {
|
|
|
|
setEditState(EditState.BetterAvatar);
|
|
|
|
}}
|
|
|
|
style={{
|
2021-08-06 21:35:25 +00:00
|
|
|
height: 80,
|
|
|
|
width: 80,
|
2021-07-19 19:26:06 +00:00
|
|
|
}}
|
|
|
|
/>
|
2023-08-14 23:28:47 +00:00
|
|
|
<h1 className="ProfileEditor__Title">{getFullNameText()}</h1>
|
|
|
|
{phoneNumber != null && (
|
|
|
|
<p className="ProfileEditor__PhoneNumber">{phoneNumber}</p>
|
|
|
|
)}
|
2021-07-19 19:26:06 +00:00
|
|
|
<hr className="ProfileEditor__divider" />
|
|
|
|
<PanelRow
|
|
|
|
className="ProfileEditor__row"
|
|
|
|
icon={
|
|
|
|
<i className="ProfileEditor__icon--container ProfileEditor__icon ProfileEditor__icon--name" />
|
|
|
|
}
|
2023-04-20 17:03:43 +00:00
|
|
|
label={<UserText text={getFullNameText()} />}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
setEditState(EditState.ProfileName);
|
|
|
|
}}
|
|
|
|
/>
|
2023-07-20 03:14:08 +00:00
|
|
|
{maybeUsernameRows}
|
2021-07-19 19:26:06 +00:00
|
|
|
<PanelRow
|
|
|
|
className="ProfileEditor__row"
|
|
|
|
icon={
|
|
|
|
fullBio.aboutEmoji ? (
|
|
|
|
<div className="ProfileEditor__icon--container">
|
|
|
|
<Emoji emoji={fullBio.aboutEmoji} size={24} />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<i className="ProfileEditor__icon--container ProfileEditor__icon ProfileEditor__icon--bio" />
|
|
|
|
)
|
|
|
|
}
|
2022-08-10 21:46:43 +00:00
|
|
|
label={
|
2023-04-20 17:03:43 +00:00
|
|
|
<UserText
|
2023-03-30 00:03:25 +00:00
|
|
|
text={fullBio.aboutText || i18n('icu:ProfileEditor--about')}
|
|
|
|
/>
|
2022-08-10 21:46:43 +00:00
|
|
|
}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClick={() => {
|
|
|
|
setEditState(EditState.Bio);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<hr className="ProfileEditor__divider" />
|
|
|
|
<div className="ProfileEditor__info">
|
|
|
|
<Intl
|
|
|
|
i18n={i18n}
|
2023-04-03 19:03:00 +00:00
|
|
|
id="icu:ProfileEditor--info--link"
|
2021-07-19 19:26:06 +00:00
|
|
|
components={{
|
2023-04-03 19:03:00 +00:00
|
|
|
// This is a render prop, not a component
|
|
|
|
// eslint-disable-next-line react/no-unstable-nested-components
|
|
|
|
learnMoreLink: parts => (
|
2021-07-19 19:26:06 +00:00
|
|
|
<a
|
|
|
|
href="https://support.signal.org/hc/en-us/articles/360007459591"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
>
|
2023-04-03 19:03:00 +00:00
|
|
|
{parts}
|
2021-07-19 19:26:06 +00:00
|
|
|
</a>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
throw missingCaseError(editState);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2021-11-01 19:13:35 +00:00
|
|
|
{usernameEditState === UsernameEditState.ConfirmingDelete && (
|
|
|
|
<ConfirmationDialog
|
2022-09-27 20:24:21 +00:00
|
|
|
dialogName="ProfileEditor.confirmDeleteUsername"
|
2021-11-01 19:13:35 +00:00
|
|
|
i18n={i18n}
|
|
|
|
onClose={() => setUsernameEditState(UsernameEditState.Editing)}
|
|
|
|
actions={[
|
|
|
|
{
|
2023-03-30 00:03:25 +00:00
|
|
|
text: i18n('icu:ProfileEditor--username--confirm-delete-button'),
|
2021-11-01 19:13:35 +00:00
|
|
|
style: 'negative',
|
|
|
|
action: () => deleteUsername(),
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
2023-07-20 03:14:08 +00:00
|
|
|
{i18n('icu:ProfileEditor--username--confirm-delete-body-2', {
|
|
|
|
username,
|
|
|
|
})}
|
2021-11-01 19:13:35 +00:00
|
|
|
</ConfirmationDialog>
|
|
|
|
)}
|
2022-10-18 17:12:02 +00:00
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
{confirmDiscardAction && (
|
2021-08-06 00:17:05 +00:00
|
|
|
<ConfirmDiscardDialog
|
2021-07-19 19:26:06 +00:00
|
|
|
i18n={i18n}
|
2021-08-06 00:17:05 +00:00
|
|
|
onDiscard={confirmDiscardAction}
|
2021-07-19 19:26:06 +00:00
|
|
|
onClose={() => setConfirmDiscardAction(undefined)}
|
2021-08-06 00:17:05 +00:00
|
|
|
/>
|
2021-07-19 19:26:06 +00:00
|
|
|
)}
|
|
|
|
<div className="ProfileEditor">{content}</div>
|
|
|
|
</>
|
|
|
|
);
|
2022-11-18 00:45:19 +00:00
|
|
|
}
|