2022-10-18 17:12:02 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
2024-03-13 20:44:13 +00:00
|
|
|
import React, { memo } from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { EditUsernameModalBody } from '../../components/EditUsernameModalBody';
|
2022-10-24 20:46:36 +00:00
|
|
|
import { getMinNickname, getMaxNickname } from '../../util/Username';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { getIntl } from '../selectors/user';
|
|
|
|
import {
|
|
|
|
getUsernameReservationState,
|
|
|
|
getUsernameReservationObject,
|
|
|
|
getUsernameReservationError,
|
2024-02-06 18:35:59 +00:00
|
|
|
getRecoveredUsername,
|
2022-10-18 17:12:02 +00:00
|
|
|
} from '../selectors/username';
|
2023-11-03 22:05:11 +00:00
|
|
|
import { getUsernameCorrupted } from '../selectors/items';
|
2022-10-18 17:12:02 +00:00
|
|
|
import { getMe } from '../selectors/conversations';
|
2024-03-13 20:44:13 +00:00
|
|
|
import { useUsernameActions } from '../ducks/username';
|
|
|
|
import { useToastActions } from '../ducks/toast';
|
2022-10-18 17:12:02 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export type SmartEditUsernameModalBodyProps = Readonly<{
|
|
|
|
isRootModal: boolean;
|
|
|
|
onClose(): void;
|
|
|
|
}>;
|
2022-10-18 17:12:02 +00:00
|
|
|
|
2024-03-13 20:44:13 +00:00
|
|
|
export const SmartEditUsernameModalBody = memo(
|
|
|
|
function SmartEditUsernameModalBody({
|
|
|
|
isRootModal,
|
|
|
|
onClose,
|
|
|
|
}: SmartEditUsernameModalBodyProps) {
|
|
|
|
const i18n = useSelector(getIntl);
|
|
|
|
const { username } = useSelector(getMe);
|
|
|
|
const usernameCorrupted = useSelector(getUsernameCorrupted);
|
|
|
|
const currentUsername = usernameCorrupted ? undefined : username;
|
|
|
|
const minNickname = getMinNickname();
|
|
|
|
const maxNickname = getMaxNickname();
|
|
|
|
const state = useSelector(getUsernameReservationState);
|
|
|
|
const recoveredUsername = useSelector(getRecoveredUsername);
|
|
|
|
const reservation = useSelector(getUsernameReservationObject);
|
|
|
|
const error = useSelector(getUsernameReservationError);
|
|
|
|
const {
|
|
|
|
setUsernameReservationError,
|
|
|
|
clearUsernameReservation,
|
|
|
|
reserveUsername,
|
|
|
|
confirmUsername,
|
|
|
|
} = useUsernameActions();
|
|
|
|
const { showToast } = useToastActions();
|
|
|
|
return (
|
|
|
|
<EditUsernameModalBody
|
|
|
|
i18n={i18n}
|
|
|
|
usernameCorrupted={usernameCorrupted}
|
|
|
|
currentUsername={currentUsername}
|
|
|
|
minNickname={minNickname}
|
|
|
|
maxNickname={maxNickname}
|
|
|
|
state={state}
|
|
|
|
recoveredUsername={recoveredUsername}
|
|
|
|
reservation={reservation}
|
|
|
|
error={error}
|
|
|
|
setUsernameReservationError={setUsernameReservationError}
|
|
|
|
clearUsernameReservation={clearUsernameReservation}
|
|
|
|
reserveUsername={reserveUsername}
|
|
|
|
confirmUsername={confirmUsername}
|
|
|
|
showToast={showToast}
|
|
|
|
isRootModal={isRootModal}
|
|
|
|
onClose={onClose}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|