signal-desktop/ts/state/smart/ProfileEditorModal.tsx

128 lines
4.4 KiB
TypeScript
Raw Normal View History

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, { memo } from 'react';
import { useSelector } from 'react-redux';
import { ProfileEditorModal } from '../../components/ProfileEditorModal';
import { useConversationsActions } from '../ducks/conversations';
import { useGlobalModalActions } from '../ducks/globalModals';
import { useItemsActions } from '../ducks/items';
import { useToastActions } from '../ducks/toast';
import { useUsernameActions } from '../ducks/username';
import { getMe } from '../selectors/conversations';
import { selectRecentEmojis } from '../selectors/emojis';
import {
getProfileEditorHasError,
getProfileEditorInitialEditState,
} from '../selectors/globalModals';
2023-02-13 18:51:41 +00:00
import {
getEmojiSkinTone,
2023-07-20 03:14:08 +00:00
getHasCompletedUsernameLinkOnboarding,
getUsernameCorrupted,
2023-07-20 03:14:08 +00:00
getUsernameLink,
getUsernameLinkColor,
getUsernameLinkCorrupted,
2023-02-13 18:51:41 +00:00
} from '../selectors/items';
import { getIntl } from '../selectors/user';
2023-07-20 03:14:08 +00:00
import {
getUsernameEditState,
getUsernameLinkState,
} from '../selectors/username';
import type { SmartEditUsernameModalBodyProps } from './EditUsernameModalBody';
import { SmartEditUsernameModalBody } from './EditUsernameModalBody';
2022-10-18 17:12:02 +00:00
function renderEditUsernameModalBody(
props: SmartEditUsernameModalBodyProps
): JSX.Element {
2022-10-18 17:12:02 +00:00
return <SmartEditUsernameModalBody {...props} />;
}
2021-07-19 19:26:06 +00:00
export const SmartProfileEditorModal = memo(function SmartProfileEditorModal() {
const i18n = useSelector(getIntl);
2021-08-06 00:17:05 +00:00
const {
aboutEmoji,
aboutText,
avatars: userAvatarData = [],
2021-08-06 00:17:05 +00:00
color,
familyName,
firstName,
2021-08-06 00:17:05 +00:00
id: conversationId,
2024-07-11 19:44:09 +00:00
profileAvatarUrl,
username,
} = useSelector(getMe);
const hasCompletedUsernameLinkOnboarding = useSelector(
getHasCompletedUsernameLinkOnboarding
);
const hasError = useSelector(getProfileEditorHasError);
const initialEditState = useSelector(getProfileEditorInitialEditState);
const recentEmojis = useSelector(selectRecentEmojis);
const skinTone = useSelector(getEmojiSkinTone);
const usernameCorrupted = useSelector(getUsernameCorrupted);
const usernameEditState = useSelector(getUsernameEditState);
const usernameLink = useSelector(getUsernameLink);
const usernameLinkColor = useSelector(getUsernameLinkColor);
const usernameLinkCorrupted = useSelector(getUsernameLinkCorrupted);
const usernameLinkState = useSelector(getUsernameLinkState);
2022-10-18 17:12:02 +00:00
const {
replaceAvatar,
saveAvatarToDisk,
saveAttachment,
deleteAvatarFromDisk,
myProfileChanged,
} = useConversationsActions();
const {
resetUsernameLink,
setUsernameLinkColor,
setUsernameEditState,
openUsernameReservationModal,
markCompletedUsernameLinkOnboarding,
deleteUsername,
} = useUsernameActions();
const { toggleProfileEditor, toggleProfileEditorHasError } =
useGlobalModalActions();
const { showToast } = useToastActions();
const { onSetSkinTone } = useItemsActions();
2021-07-19 19:26:06 +00:00
return (
<ProfileEditorModal
aboutEmoji={aboutEmoji}
aboutText={aboutText}
color={color}
conversationId={conversationId}
deleteAvatarFromDisk={deleteAvatarFromDisk}
deleteUsername={deleteUsername}
familyName={familyName}
firstName={firstName ?? ''}
hasCompletedUsernameLinkOnboarding={hasCompletedUsernameLinkOnboarding}
hasError={hasError}
i18n={i18n}
initialEditState={initialEditState}
markCompletedUsernameLinkOnboarding={markCompletedUsernameLinkOnboarding}
myProfileChanged={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}
toggleProfileEditor={toggleProfileEditor}
toggleProfileEditorHasError={toggleProfileEditorHasError}
userAvatarData={userAvatarData}
username={username}
usernameCorrupted={usernameCorrupted}
usernameEditState={usernameEditState}
usernameLink={usernameLink}
usernameLinkColor={usernameLinkColor}
usernameLinkCorrupted={usernameLinkCorrupted}
usernameLinkState={usernameLinkState}
/>
);
});