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

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-10-18 17:12:02 +00:00
// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { connect } from 'react-redux';
import { mapDispatchToProps } from '../actions';
import type { PropsDataType } from '../../components/EditUsernameModalBody';
import { EditUsernameModalBody } from '../../components/EditUsernameModalBody';
import { getMinNickname, getMaxNickname } from '../../util/Username';
2022-10-18 17:12:02 +00:00
import type { StateType } from '../reducer';
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';
import { getUsernameCorrupted } from '../selectors/items';
2022-10-18 17:12:02 +00:00
import { getMe } from '../selectors/conversations';
function mapStateToProps(state: StateType): PropsDataType {
const i18n = getIntl(state);
const { username } = getMe(state);
const usernameCorrupted = getUsernameCorrupted(state);
2022-10-18 17:12:02 +00:00
return {
i18n,
2024-02-06 18:35:59 +00:00
usernameCorrupted,
currentUsername: usernameCorrupted ? undefined : username,
minNickname: getMinNickname(),
maxNickname: getMaxNickname(),
2022-10-18 17:12:02 +00:00
state: getUsernameReservationState(state),
2024-02-06 18:35:59 +00:00
recoveredUsername: getRecoveredUsername(state),
2022-10-18 17:12:02 +00:00
reservation: getUsernameReservationObject(state),
error: getUsernameReservationError(state),
};
}
const smart = connect(mapStateToProps, mapDispatchToProps);
export const SmartEditUsernameModalBody = smart(EditUsernameModalBody);