import React, { useContext, useEffect, useState } from 'react';
import { Flex } from '../basic/Flex';
import { SessionButton } from '../basic/SessionButton';
import { SessionIdEditable } from '../basic/SessionIdEditable';
import { SessionIconButton } from '../icon';
import { RegistrationContext, RegistrationPhase, signUp } from './RegistrationStages';
import { RegistrationUserDetails } from './RegistrationUserDetails';
import { sanitizeDisplayNameOrToast, SignInMode } from './SignInTab';
import { TermsAndConditions } from './TermsAndConditions';
export enum SignUpMode {
Default,
SessionIDShown,
EnterDetails,
}
const CreateSessionIdButton = ({ createSessionID }: { createSessionID: any }) => {
return ;
};
const ContinueSignUpButton = ({ continueSignUp }: { continueSignUp: any }) => {
return ;
};
const SignUpDefault = (props: { createSessionID: () => void }) => {
return (
);
};
export const GoBackMainMenuButton = () => {
const { setRegistrationPhase, setSignInMode, setSignUpMode } = useContext(RegistrationContext);
return (
{
setRegistrationPhase(RegistrationPhase.Start);
setSignInMode(SignInMode.Default);
setSignUpMode(SignUpMode.Default);
}}
/>
);
};
const SignUpSessionIDShown = (props: { continueSignUp: () => void }) => {
return (
{window.i18n('yourUniqueSessionID')}
{window.i18n('allUsersAreRandomly...')}
);
};
export const SignUpTab = () => {
const {
signUpMode,
setRegistrationPhase,
generatedRecoveryPhrase,
hexGeneratedPubKey,
setSignUpMode,
} = useContext(RegistrationContext);
const [displayName, setDisplayName] = useState('');
const [displayNameError, setDisplayNameError] = useState('');
useEffect(() => {
if (signUpMode === SignUpMode.SessionIDShown) {
window.Session.setNewSessionID(hexGeneratedPubKey);
}
}, [signUpMode]);
if (signUpMode === SignUpMode.Default) {
return (
{
setSignUpMode(SignUpMode.SessionIDShown);
setRegistrationPhase(RegistrationPhase.SignUp);
}}
/>
);
}
if (signUpMode === SignUpMode.SessionIDShown) {
return (
{
setSignUpMode(SignUpMode.EnterDetails);
}}
/>
);
}
// can only be the EnterDetails step
// Display name is required
const displayNameOK = !displayNameError && !!displayName;
const enableCompleteSignUp = displayNameOK;
const signUpWithDetails = async () => {
await signUp({
displayName,
generatedRecoveryPhrase: generatedRecoveryPhrase,
});
};
return (
{window.i18n('welcomeToYourSession')}
{
sanitizeDisplayNameOrToast(name, setDisplayName, setDisplayNameError);
}}
stealAutoFocus={true}
/>
);
};