session-desktop/ts/components/session/registration/RegistrationUserDetails.tsx

87 lines
2.6 KiB
TypeScript
Raw Normal View History

import classNames from 'classnames';
import React from 'react';
import { lightTheme } from '../../../state/ducks/SessionTheme';
import { SessionInput } from '../SessionInput';
import { MAX_USERNAME_LENGTH } from './RegistrationTabs';
const DisplayNameInput = (props: {
stealAutoFocus?: boolean;
displayName: string;
onDisplayNameChanged: (val: string) => any;
handlePressEnter: () => any;
}) => {
return (
// tslint:disable-next-line: use-simple-attributes
<SessionInput
autoFocus={props.stealAutoFocus || false}
label={window.i18n('displayName')}
type="text"
placeholder={window.i18n('enterDisplayName')}
value={props.displayName}
maxLength={MAX_USERNAME_LENGTH}
onValueChanged={props.onDisplayNameChanged}
onEnterPressed={props.handlePressEnter}
theme={lightTheme}
/>
);
};
const RecoveryPhraseInput = (props: {
recoveryPhrase: string;
onSeedChanged: (val: string) => any;
handlePressEnter: () => any;
}) => {
return (
<SessionInput
label={window.i18n('recoveryPhrase')}
type="password"
value={props.recoveryPhrase}
autoFocus={true}
placeholder={window.i18n('enterRecoveryPhrase')}
enableShowHide={true}
onValueChanged={props.onSeedChanged}
onEnterPressed={props.handlePressEnter}
theme={lightTheme}
/>
);
};
export interface Props {
// tslint:disable: react-unused-props-and-state
showDisplayNameField: boolean;
showSeedField: boolean;
stealAutoFocus?: boolean;
2021-02-26 05:29:30 +01:00
recoveryPhrase?: string;
displayName: string;
handlePressEnter: () => any;
2021-02-26 05:29:30 +01:00
onSeedChanged?: (val: string) => any;
onDisplayNameChanged: (val: string) => any;
}
export const RegistrationUserDetails = (props: Props) => {
2021-04-22 10:03:58 +02:00
if (props.showSeedField && (props.recoveryPhrase === undefined || !props.onSeedChanged)) {
2021-02-26 05:29:30 +01:00
throw new Error('if show seed is true, we need callback + value');
}
return (
<div className={classNames('session-registration__entry-fields')}>
{props.showSeedField && (
<RecoveryPhraseInput
2021-02-26 05:29:30 +01:00
recoveryPhrase={props.recoveryPhrase as string}
handlePressEnter={props.handlePressEnter}
2021-02-26 05:29:30 +01:00
onSeedChanged={props.onSeedChanged as any}
/>
)}
<div className="inputfields">
{props.showDisplayNameField && (
<DisplayNameInput
stealAutoFocus={props.stealAutoFocus}
displayName={props.displayName}
handlePressEnter={props.handlePressEnter}
onDisplayNameChanged={props.onDisplayNameChanged}
/>
)}
</div>
</div>
);
};