Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 64 additions & 66 deletions app/assets/javascripts/components/AccountMenu/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SignInPane: FunctionComponent<Props> = observer(

useEffect(() => {
if (emailInputRef?.current) {
emailInputRef.current!.focus();
emailInputRef.current?.focus();
}
}, []);

Expand Down Expand Up @@ -73,8 +73,8 @@ export const SignInPane: FunctionComponent<Props> = observer(

const signIn = () => {
setIsSigningIn(true);
emailInputRef?.current!.blur();
passwordInputRef?.current!.blur();
emailInputRef?.current?.blur();
passwordInputRef?.current?.blur();

application
.signIn(email, password, isStrictSignin, isEphemeral, shouldMergeLocal)
Expand All @@ -92,7 +92,7 @@ export const SignInPane: FunctionComponent<Props> = observer(
application.alertService.alert(err);
}
setPassword('');
passwordInputRef?.current!.blur();
passwordInputRef?.current?.blur();
})
.finally(() => {
setIsSigningIn(false);
Expand All @@ -109,12 +109,12 @@ export const SignInPane: FunctionComponent<Props> = observer(
e.preventDefault();

if (!email || email.length === 0) {
emailInputRef?.current!.focus();
emailInputRef?.current?.focus();
return;
}

if (!password || password.length === 0) {
passwordInputRef?.current!.focus();
passwordInputRef?.current?.focus();
return;
}

Expand All @@ -134,69 +134,67 @@ export const SignInPane: FunctionComponent<Props> = observer(
/>
<div className="sn-account-menu-headline">Sign in</div>
</div>
<form onSubmit={handleSignInFormSubmit}>
<div className="px-3 mb-1">
<InputWithIcon
className={`mb-2 ${isInvalid ? 'border-dark-red' : null}`}
icon="email"
inputType="email"
placeholder="Email"
value={email}
onChange={handleEmailChange}
onFocus={resetInvalid}
onKeyDown={handleKeyDown}
disabled={isSigningIn}
ref={emailInputRef}
/>
<InputWithIcon
className={`mb-2 ${isInvalid ? 'border-dark-red' : null}`}
icon="password"
inputType={showPassword ? 'text' : 'password'}
placeholder="Password"
value={password}
onChange={handlePasswordChange}
onFocus={resetInvalid}
onKeyDown={handleKeyDown}
disabled={isSigningIn}
toggle={{
toggleOnIcon: 'eye-off',
toggleOffIcon: 'eye',
title: 'Show password',
toggled: showPassword,
onClick: setShowPassword,
}}
ref={passwordInputRef}
/>
{isInvalid ? (
<div className="color-dark-red my-2">
Invalid email or password.
</div>
) : null}
<Button
className="btn-w-full mt-1 mb-3"
label={isSigningIn ? 'Signing in...' : 'Sign in'}
type="primary"
onClick={handleSignInFormSubmit}
disabled={isSigningIn}
/>
<div className="px-3 mb-1">
<InputWithIcon
className={`mb-2 ${isInvalid ? 'border-dark-red' : null}`}
icon="email"
inputType="email"
placeholder="Email"
value={email}
onChange={handleEmailChange}
onFocus={resetInvalid}
onKeyDown={handleKeyDown}
disabled={isSigningIn}
ref={emailInputRef}
/>
<InputWithIcon
className={`mb-2 ${isInvalid ? 'border-dark-red' : null}`}
icon="password"
inputType={showPassword ? 'text' : 'password'}
placeholder="Password"
value={password}
onChange={handlePasswordChange}
onFocus={resetInvalid}
onKeyDown={handleKeyDown}
disabled={isSigningIn}
toggle={{
toggleOnIcon: 'eye-off',
toggleOffIcon: 'eye',
title: 'Show password',
toggled: showPassword,
onClick: setShowPassword,
}}
ref={passwordInputRef}
/>
{isInvalid ? (
<div className="color-dark-red my-2">
Invalid email or password.
</div>
) : null}
<Button
className="btn-w-full mt-1 mb-3"
label={isSigningIn ? 'Signing in...' : 'Sign in'}
type="primary"
onClick={handleSignInFormSubmit}
disabled={isSigningIn}
/>
<Checkbox
name="is-ephemeral"
label="Stay signed in"
checked={!isEphemeral}
disabled={isSigningIn}
onChange={handleEphemeralChange}
/>
{notesAndTagsCount > 0 ? (
<Checkbox
name="is-ephemeral"
label="Stay signed in"
checked={!isEphemeral}
name="should-merge-local"
label={`Merge local data (${notesAndTagsCount} notes and tags)`}
checked={shouldMergeLocal}
disabled={isSigningIn}
onChange={handleEphemeralChange}
onChange={handleShouldMergeChange}
/>
{notesAndTagsCount > 0 ? (
<Checkbox
name="should-merge-local"
label={`Merge local data (${notesAndTagsCount} notes and tags)`}
checked={shouldMergeLocal}
disabled={isSigningIn}
onChange={handleShouldMergeChange}
/>
) : null}
</div>
</form>
) : null}
</div>
<div className="h-1px my-2 bg-border"></div>
<AdvancedOptions
appState={appState}
Expand Down