|
| 1 | +/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 | + |
| 5 | +import React, { useCallback, useState } from 'react'; |
| 6 | +import { RouteComponentProps } from '@reach/router'; |
| 7 | +import { useForm } from 'react-hook-form'; |
| 8 | +import { FtlMsg } from 'fxa-react/lib/utils'; |
| 9 | +import AppLayout from '../../../components/AppLayout'; |
| 10 | +import InputPassword from '../../../components/InputPassword'; |
| 11 | + |
| 12 | +export type SigninPasskeyFallbackProps = {}; |
| 13 | + |
| 14 | +type FormData = { |
| 15 | + password: string; |
| 16 | +}; |
| 17 | + |
| 18 | +export const viewName = 'signin-passkey-fallback'; |
| 19 | + |
| 20 | +const SigninPasskeyFallback = ( |
| 21 | + _props: SigninPasskeyFallbackProps & RouteComponentProps |
| 22 | +) => { |
| 23 | + // State |
| 24 | + const [passwordErrorText, setPasswordErrorText] = useState(''); |
| 25 | + |
| 26 | + // Form |
| 27 | + const { handleSubmit, register } = useForm<FormData>({ |
| 28 | + mode: 'onTouched', |
| 29 | + criteriaMode: 'all', |
| 30 | + defaultValues: { password: '' }, |
| 31 | + }); |
| 32 | + |
| 33 | + // Handlers |
| 34 | + const onContinue = useCallback(async (data: FormData) => { |
| 35 | + // TODO: FXA-13100 - Hook up password verification when container is added |
| 36 | + }, []); |
| 37 | + |
| 38 | + const onGoToSettings = useCallback(() => { |
| 39 | + // TODO: FXA-13100 - Hook up navigation when container is added |
| 40 | + }, []); |
| 41 | + |
| 42 | + return ( |
| 43 | + <AppLayout> |
| 44 | + <FtlMsg id="signin-passkey-fallback-header"> |
| 45 | + <p className="text-sm text-grey-500 mb-2">Finish sign in</p> |
| 46 | + </FtlMsg> |
| 47 | + |
| 48 | + <FtlMsg id="signin-passkey-fallback-heading"> |
| 49 | + <h1 className="card-header mb-4">Enter your password to sync</h1> |
| 50 | + </FtlMsg> |
| 51 | + |
| 52 | + <FtlMsg id="signin-passkey-fallback-body"> |
| 53 | + <p className="text-sm mb-6"> |
| 54 | + To keep your data safe, you need to enter your password when you use |
| 55 | + this passkey. |
| 56 | + </p> |
| 57 | + </FtlMsg> |
| 58 | + |
| 59 | + <form onSubmit={handleSubmit(onContinue)}> |
| 60 | + <FtlMsg |
| 61 | + id="signin-passkey-fallback-password-label" |
| 62 | + attrs={{ label: true }} |
| 63 | + > |
| 64 | + <InputPassword |
| 65 | + name="password" |
| 66 | + label="Password" |
| 67 | + className="mb-6" |
| 68 | + errorText={passwordErrorText} |
| 69 | + anchorPosition="start" |
| 70 | + autoFocus |
| 71 | + onChange={() => setPasswordErrorText('')} |
| 72 | + inputRef={register({ required: true })} |
| 73 | + prefixDataTestId="password" |
| 74 | + /> |
| 75 | + </FtlMsg> |
| 76 | + |
| 77 | + {/* TODO: FXA-13100 - Add disabled={isSubmitting} while the password is submitting. */} |
| 78 | + <div className="flex flex-col tablet:flex-row gap-4"> |
| 79 | + <FtlMsg id="signin-passkey-fallback-go-to-settings"> |
| 80 | + <button |
| 81 | + type="button" |
| 82 | + className="cta-neutral cta-base-p tablet:flex-1" |
| 83 | + onClick={onGoToSettings} |
| 84 | + data-testid="go-to-settings-button" |
| 85 | + > |
| 86 | + Go to settings |
| 87 | + </button> |
| 88 | + </FtlMsg> |
| 89 | + |
| 90 | + <FtlMsg id="signin-passkey-fallback-continue"> |
| 91 | + <button |
| 92 | + type="submit" |
| 93 | + className="cta-primary cta-base-p tablet:flex-1" |
| 94 | + data-testid="continue-button" |
| 95 | + > |
| 96 | + Continue |
| 97 | + </button> |
| 98 | + </FtlMsg> |
| 99 | + </div> |
| 100 | + </form> |
| 101 | + </AppLayout> |
| 102 | + ); |
| 103 | +}; |
| 104 | + |
| 105 | +export default SigninPasskeyFallback; |
0 commit comments