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

99 lines
2.9 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
2022-10-18 17:12:02 +00:00
import React from 'react';
2021-07-19 19:26:06 +00:00
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import type { PropsDataType as ProfileEditorModalPropsType } from '../../components/ProfileEditorModal';
import { ProfileEditorModal } from '../../components/ProfileEditorModal';
import type { PropsDataType } from '../../components/ProfileEditor';
2022-10-18 17:12:02 +00:00
import { SmartEditUsernameModalBody } from './EditUsernameModalBody';
import type { StateType } from '../reducer';
2021-07-19 19:26:06 +00:00
import { getIntl } from '../selectors/user';
2023-02-13 18:51:41 +00:00
import {
getEmojiSkinTone,
getUsernamesEnabled,
getHasCompletedUsernameOnboarding,
2023-07-20 03:14:08 +00:00
getHasCompletedUsernameLinkOnboarding,
getUsernameCorrupted,
2023-07-20 03:14:08 +00:00
getUsernameLinkColor,
getUsernameLink,
getUsernameLinkCorrupted,
2023-02-13 18:51:41 +00:00
} from '../selectors/items';
2022-10-18 17:12:02 +00:00
import { getMe } from '../selectors/conversations';
2021-07-19 19:26:06 +00:00
import { selectRecentEmojis } from '../selectors/emojis';
2023-07-20 03:14:08 +00:00
import {
getUsernameEditState,
getUsernameLinkState,
} from '../selectors/username';
2022-10-18 17:12:02 +00:00
function renderEditUsernameModalBody(props: {
onClose: () => void;
}): JSX.Element {
return <SmartEditUsernameModalBody {...props} />;
}
2021-07-19 19:26:06 +00:00
function mapStateToProps(
state: StateType
): Omit<PropsDataType, 'onEditStateChange' | 'onProfileChanged'> &
ProfileEditorModalPropsType {
2021-08-06 00:17:05 +00:00
const {
profileAvatarPath,
2021-08-06 00:17:05 +00:00
avatars: userAvatarData = [],
aboutText,
aboutEmoji,
color,
firstName,
familyName,
id: conversationId,
phoneNumber,
username,
2021-08-06 00:17:05 +00:00
} = getMe(state);
2021-07-19 19:26:06 +00:00
const recentEmojis = selectRecentEmojis(state);
const skinTone = getEmojiSkinTone(state);
const isUsernameFlagEnabled = getUsernamesEnabled(state);
2023-02-13 18:51:41 +00:00
const hasCompletedUsernameOnboarding =
getHasCompletedUsernameOnboarding(state);
2023-07-20 03:14:08 +00:00
const hasCompletedUsernameLinkOnboarding =
getHasCompletedUsernameLinkOnboarding(state);
2022-10-18 17:12:02 +00:00
const usernameEditState = getUsernameEditState(state);
2023-07-20 03:14:08 +00:00
const usernameLinkState = getUsernameLinkState(state);
const usernameLinkColor = getUsernameLinkColor(state);
const usernameLink = getUsernameLink(state);
const usernameCorrupted = getUsernameCorrupted(state);
const usernameLinkCorrupted = getUsernameLinkCorrupted(state);
2021-07-19 19:26:06 +00:00
return {
aboutEmoji,
aboutText,
profileAvatarPath,
2021-08-06 00:17:05 +00:00
color,
conversationId,
2021-07-19 19:26:06 +00:00
familyName,
firstName: String(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
hasError: state.globalModals.profileEditorHasError,
i18n: getIntl(state),
isUsernameFlagEnabled,
2021-07-19 19:26:06 +00:00
recentEmojis,
skinTone,
phoneNumber,
2021-08-06 00:17:05 +00:00
userAvatarData,
username,
usernameCorrupted,
2022-10-18 17:12:02 +00:00
usernameEditState,
2023-07-20 03:14:08 +00:00
usernameLinkState,
usernameLinkColor,
usernameLinkCorrupted,
2023-07-20 03:14:08 +00:00
usernameLink,
2022-10-18 17:12:02 +00:00
renderEditUsernameModalBody,
2021-07-19 19:26:06 +00:00
};
}
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartProfileEditorModal = smart(ProfileEditorModal);