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';
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { PropsDataType as ProfileEditorModalPropsType } from '../../components/ProfileEditorModal';
|
|
|
|
import { ProfileEditorModal } from '../../components/ProfileEditorModal';
|
|
|
|
import type { PropsDataType } from '../../components/ProfileEditor';
|
2023-02-13 18:51:41 +00:00
|
|
|
import { storageServiceUploadJob } from '../../services/storage';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { SmartEditUsernameModalBody } from './EditUsernameModalBody';
|
2021-10-26 19:15:33 +00:00
|
|
|
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,
|
|
|
|
} 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';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { getUsernameEditState } from '../selectors/username';
|
|
|
|
|
|
|
|
function renderEditUsernameModalBody(props: {
|
|
|
|
onClose: () => void;
|
|
|
|
}): JSX.Element {
|
|
|
|
return <SmartEditUsernameModalBody {...props} />;
|
|
|
|
}
|
2021-07-19 19:26:06 +00:00
|
|
|
|
2023-02-13 18:51:41 +00:00
|
|
|
async function markCompletedUsernameOnboarding(): Promise<void> {
|
|
|
|
await window.storage.put('hasCompletedUsernameOnboarding', true);
|
|
|
|
|
|
|
|
storageServiceUploadJob();
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:26:06 +00:00
|
|
|
function mapStateToProps(
|
|
|
|
state: StateType
|
2021-09-13 02:36:41 +00:00
|
|
|
): Omit<PropsDataType, 'onEditStateChange' | 'onProfileChanged'> &
|
|
|
|
ProfileEditorModalPropsType {
|
2021-08-06 00:17:05 +00:00
|
|
|
const {
|
2022-03-16 00:14:20 +00:00
|
|
|
profileAvatarPath,
|
2021-08-06 00:17:05 +00:00
|
|
|
avatars: userAvatarData = [],
|
|
|
|
aboutText,
|
|
|
|
aboutEmoji,
|
|
|
|
color,
|
|
|
|
firstName,
|
|
|
|
familyName,
|
|
|
|
id: conversationId,
|
2021-11-01 19:13:35 +00:00
|
|
|
username,
|
2021-08-06 00:17:05 +00:00
|
|
|
} = getMe(state);
|
2021-07-19 19:26:06 +00:00
|
|
|
const recentEmojis = selectRecentEmojis(state);
|
2021-09-09 16:29:01 +00:00
|
|
|
const skinTone = getEmojiSkinTone(state);
|
2021-11-01 19:13:35 +00:00
|
|
|
const isUsernameFlagEnabled = getUsernamesEnabled(state);
|
2023-02-13 18:51:41 +00:00
|
|
|
const hasCompletedUsernameOnboarding =
|
|
|
|
getHasCompletedUsernameOnboarding(state);
|
2022-10-18 17:12:02 +00:00
|
|
|
const usernameEditState = getUsernameEditState(state);
|
2021-07-19 19:26:06 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
aboutEmoji,
|
|
|
|
aboutText,
|
2022-03-16 00:14:20 +00:00
|
|
|
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,
|
2021-07-19 19:26:06 +00:00
|
|
|
hasError: state.globalModals.profileEditorHasError,
|
|
|
|
i18n: getIntl(state),
|
2021-11-01 19:13:35 +00:00
|
|
|
isUsernameFlagEnabled,
|
2023-02-13 18:51:41 +00:00
|
|
|
markCompletedUsernameOnboarding,
|
2021-07-19 19:26:06 +00:00
|
|
|
recentEmojis,
|
|
|
|
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,
|
|
|
|
|
|
|
|
renderEditUsernameModalBody,
|
2021-07-19 19:26:06 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export const SmartProfileEditorModal = smart(ProfileEditorModal);
|