-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user): add personal details form to modal
- Loading branch information
Showing
10 changed files
with
409 additions
and
5 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
36 changes: 36 additions & 0 deletions
36
src/components/PersonalDetailsForm/PersonalDetailsForm.module.scss
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,36 @@ | ||
@use '../../styles/variables'; | ||
@use '../../styles/theme'; | ||
|
||
.title { | ||
margin-bottom: 24px; | ||
font-family: theme.$body-alt-font-family; | ||
font-weight: 700; | ||
font-size: 24px; | ||
} | ||
|
||
.error { | ||
margin-bottom: 24px; | ||
padding: 16px; | ||
color: variables.$white; | ||
font-family: theme.$body-font-family; | ||
font-size: 18px; | ||
background-color: theme.$form-error-bg-color; | ||
border-radius: 4px; | ||
} | ||
|
||
.continue { | ||
margin: variables.$base-spacing 0; | ||
} | ||
|
||
.form { | ||
max-height: 500px; | ||
overflow-y: auto; | ||
-ms-overflow-style: none; /* for Internet Explorer, Edge */ | ||
scrollbar-width: none; /* for Firefox */ | ||
&::-webkit-scrollbar { | ||
display: none; /* for Chrome, Safari, and Opera */ | ||
} | ||
> div { | ||
margin: 12px 0; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/components/PersonalDetailsForm/PersonalDetailsForm.test.tsx
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,12 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import PersonalDetailsForm from './PersonalDetailsForm'; | ||
|
||
describe.skip('<PersonalDetailsForm>', () => { | ||
test('renders and matches snapshot', () => { | ||
const { container } = render(<PersonalDetailsForm />); | ||
|
||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
101 changes: 101 additions & 0 deletions
101
src/components/PersonalDetailsForm/PersonalDetailsForm.tsx
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,101 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import type { PersonalDetailsFormData, PersonalDetailsCustomField } from 'types/account'; | ||
|
||
import type { FormErrors } from '../../hooks/useForm'; | ||
import TextField from '../TextField/TextField'; | ||
import Button from '../Button/Button'; | ||
import Dropdown from '../Dropdown/Dropdown'; | ||
import Checkbox from '../Checkbox/Checkbox'; | ||
import Radio from '../Radio/Radio'; | ||
import DateField from '../DateField/DateField'; | ||
|
||
import styles from './PersonalDetailsForm.module.scss'; | ||
|
||
type Props = { | ||
onSubmit: React.FormEventHandler<HTMLFormElement>; | ||
onChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>; | ||
error?: string; | ||
errors: FormErrors<PersonalDetailsFormData>; | ||
values: PersonalDetailsFormData; | ||
submitting: boolean; | ||
fields: PersonalDetailsCustomField[]; | ||
}; | ||
|
||
const PersonalDetailsForm: React.FC<Props> = ({ onSubmit, onChange, values, errors, submitting, fields }: Props) => { | ||
const { t } = useTranslation('account'); | ||
|
||
const renderCustomFields = () => | ||
fields.map((field, index) => { | ||
if (field.type === 'dropdown') { | ||
return ( | ||
<Dropdown | ||
key={index} | ||
value={values[field.name]} | ||
onChange={onChange} | ||
label={field.question} | ||
options={field.values} | ||
name={field.name} | ||
fullWidth | ||
/> | ||
); | ||
} | ||
|
||
if (field.type === 'radio') { | ||
return <Radio name={field.name} header={field.question} key={index} values={field.values} onChange={onChange} />; | ||
} | ||
|
||
if (field.type === 'checkbox') { | ||
return <Checkbox header={field.question} key={index} value={false} onChange={onChange} label={field.value} name={field.name} />; | ||
} | ||
|
||
if (field.type === 'date') { | ||
return ( | ||
<DateField | ||
key={index} | ||
value={values[field.name]} | ||
onChange={onChange} | ||
label={t(`personal_details.${field.name}`)} | ||
placeholder={'mm/dd/yyyy'} | ||
error={!!errors[field.name]} | ||
helperText={errors[field.name]} | ||
name={field.name} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<TextField | ||
key={index} | ||
value={values[field.name]} | ||
onChange={onChange} | ||
label={t(`personal_details.${field.name}`)} | ||
placeholder={t(`personal_details.${field.name}`)} | ||
error={!!errors[field.name] || !!errors.form} | ||
helperText={errors[field.name]} | ||
name={field.name} | ||
type={field.type} | ||
/> | ||
); | ||
}); | ||
|
||
return ( | ||
<form className={styles.form} onSubmit={onSubmit} data-testid="personal_details-form"> | ||
<h2 className={styles.title}>{t('personal_details.personal_details')}</h2> | ||
{errors.form ? <div className={styles.error}>{errors.form}</div> : null} | ||
{renderCustomFields()} | ||
<Button | ||
className={styles.continue} | ||
type="submit" | ||
label={t('personal_details.continue')} | ||
variant="contained" | ||
color="primary" | ||
size="large" | ||
disabled={submitting} | ||
fullWidth | ||
/> | ||
</form> | ||
); | ||
}; | ||
|
||
export default PersonalDetailsForm; |
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
Oops, something went wrong.