-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from IFRCGo/feature/forget-password-page
Add Forget password page
- Loading branch information
Showing
6 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"namespace": "recoverAccount", | ||
"strings": { | ||
"pageTitle": "IFRC Alert-Hub - Recover Account", | ||
"pageHeading": "Recover Account", | ||
"pageDescription": "Enter the email/username you used during registration", | ||
"emailInputLabel": "Email/Username", | ||
"submitButtonLabel": "Submit recovery request" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import { useMemo } from 'react'; | ||
import { | ||
Button, | ||
TextInput, | ||
} from '@ifrc-go/ui'; | ||
import { useTranslation } from '@ifrc-go/ui/hooks'; | ||
import { | ||
createSubmitHandler, | ||
getErrorObject, | ||
ObjectSchema, | ||
requiredStringCondition, | ||
useForm, | ||
} from '@togglecorp/toggle-form'; | ||
|
||
import HCaptcha from '#components/Captcha'; | ||
import Page from '#components/Page'; | ||
|
||
import i18n from './i18n.json'; | ||
import styles from './styles.module.css'; | ||
|
||
interface FormFields { | ||
email?: string; | ||
captcha?: string; | ||
} | ||
|
||
const defaultFormValue: FormFields = { | ||
}; | ||
|
||
type FormSchema = ObjectSchema<FormFields>; | ||
type FormSchemaFields = ReturnType<FormSchema['fields']>; | ||
|
||
const formSchema: FormSchema = { | ||
fields: (): FormSchemaFields => ({ | ||
email: { | ||
required: true, | ||
requiredValidation: requiredStringCondition, | ||
}, | ||
captcha: { | ||
required: true, | ||
requiredValidation: requiredStringCondition, | ||
}, | ||
}), | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export function Component() { | ||
const strings = useTranslation(i18n); | ||
|
||
const { | ||
value: formValue, | ||
error: formError, | ||
setFieldValue, | ||
setError, | ||
validate, | ||
} = useForm(formSchema, { value: defaultFormValue }); | ||
|
||
const handleFormSubmit = useMemo( | ||
() => createSubmitHandler( | ||
validate, | ||
setError, | ||
// FIXME: Add form submission logic here | ||
() => {}, | ||
), | ||
[validate, setError], | ||
); | ||
|
||
const fieldError = getErrorObject(formError); | ||
|
||
return ( | ||
<Page | ||
title={strings.pageTitle} | ||
heading={strings.pageHeading} | ||
description={strings.pageDescription} | ||
className={styles.recoverAccount} | ||
> | ||
<form | ||
className={styles.form} | ||
onSubmit={handleFormSubmit} | ||
> | ||
<TextInput | ||
name="email" | ||
label={strings.emailInputLabel} | ||
value={formValue.email} | ||
onChange={setFieldValue} | ||
error={fieldError?.email} | ||
withAsterisk | ||
autoFocus | ||
/> | ||
<div className={styles.actions}> | ||
<HCaptcha | ||
name="captcha" | ||
onChange={setFieldValue} | ||
/> | ||
<Button | ||
name={undefined} | ||
type="submit" | ||
className={styles.submitButton} | ||
> | ||
{strings.submitButtonLabel} | ||
</Button> | ||
</div> | ||
</form> | ||
</Page> | ||
); | ||
} | ||
Component.displayName = 'RecoverAccount'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.recover-account { | ||
.form { | ||
display: flex; | ||
flex-direction: column; | ||
flex-grow: 1; | ||
gap: var(--go-ui-spacing-lg); | ||
margin: 0 auto; | ||
max-width: var(--go-ui-width-content-max); | ||
|
||
.submit-button { | ||
align-self: center; | ||
} | ||
|
||
.actions { | ||
display: flex; | ||
flex-direction: column; | ||
gap: var(--go-ui-spacing-lg); | ||
align-items: center; | ||
} | ||
} | ||
} |