Skip to content

Commit

Permalink
[Eligibility Questionnaire] Add form validation (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
elenm authored Aug 5, 2021
1 parent 7320e38 commit 1bd7556
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. The format

- Added:
- Added fields to Listing and Property to accommodate Detroit listing data ([#311](https://github.com/CityOfDetroit/bloom/pull/311))
- Add eligibility questionnaire validation ([#327](https://github.com/CityOfDetroit/bloom/pull/327))

## Detroit Team M8

Expand Down
28 changes: 19 additions & 9 deletions sites/public/pages/eligibility/age.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,23 @@ import { ELIGIBILITY_ROUTE, ELIGIBILITY_SECTIONS } from "../../lib/constants"

const EligibilityAge = () => {
const router = useRouter()
// Check if they need to be 18 or older to apply?
const MIN_AGE = 0
const MAX_AGE = 120

/* Form Handler */
const { handleSubmit, register } = useForm()
const onSubmit = () => {
// Not yet implemented.
// eslint-disable-next-line @typescript-eslint/unbound-method
const { handleSubmit, register, errors, setError } = useForm()
const onSubmit = (data) => {
if (isAgeValid(data.age)) {
void router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[3]}`)
} else {
setError("age", { type: "manual", message: "" })
}
}

function isAgeValid(age: number) {
return age >= MIN_AGE && age <= MAX_AGE
}

return (
Expand Down Expand Up @@ -53,18 +65,16 @@ const EligibilityAge = () => {
describedBy="age-description"
isLabelAfterField={true}
inputProps={{ maxLength: 3 }}
type={"number"}
validation={{ required: true }}
error={errors.age}
errorMessage={t("eligibility.age.error")}
register={register}
/>
</div>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
<Button
styleType={AppearanceStyleType.primary}
onClick={() => router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[3]}`)}
>
{t("t.next")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.next")}</Button>
</div>
</div>
</Form>
Expand Down
10 changes: 3 additions & 7 deletions sites/public/pages/eligibility/bedrooms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const EligibilityBedrooms = () => {
const router = useRouter()

/* Form Handler */
// eslint-disable-next-line @typescript-eslint/unbound-method
const { handleSubmit, register, errors } = useForm()
const onSubmit = () => {
// Not yet implemented.
void router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[2]}`)
}

const preferredUnitOptions = [
Expand Down Expand Up @@ -64,12 +65,7 @@ const EligibilityBedrooms = () => {
</div>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
<Button
styleType={AppearanceStyleType.primary}
onClick={() => router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[2]}`)}
>
{t("t.next")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.next")}</Button>
</div>
</div>
</Form>
Expand Down
10 changes: 3 additions & 7 deletions sites/public/pages/eligibility/disability.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const EligibilityDisability = () => {
const router = useRouter()

/* Form Handler */
// eslint-disable-next-line @typescript-eslint/unbound-method
const { handleSubmit, register, errors } = useForm()
const onSubmit = () => {
// Not yet implemented.
void router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[4]}`)
}

const disabilityValues = [
Expand Down Expand Up @@ -75,12 +76,7 @@ const EligibilityDisability = () => {
</div>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
<Button
styleType={AppearanceStyleType.primary}
onClick={() => router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[4]}`)}
>
{t("t.next")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.next")}</Button>
</div>
</div>
</Form>
Expand Down
12 changes: 4 additions & 8 deletions sites/public/pages/eligibility/income.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const EligibilityIncome = () => {
const incomeRanges = ["below10k", "10kTo20k", "30kTo40k", "40kTo50k", "over50k"]

/* Form Handler */
// eslint-disable-next-line @typescript-eslint/unbound-method
const { handleSubmit, register } = useForm()
const onSubmit = () => {
// Not yet implemented.
void router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[5]}`)
}

return (
Expand All @@ -49,7 +50,7 @@ const EligibilityIncome = () => {
label={t("eligibility.income.label")}
describedBy="income-description"
validation={{ required: true }}
defaultValue={t("eligibility.income.ranges")}
defaultValue={t("eligibility.income.ranges.below10k")}
register={register}
controlClassName="control"
options={incomeRanges}
Expand All @@ -58,12 +59,7 @@ const EligibilityIncome = () => {
</div>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
<Button
styleType={AppearanceStyleType.primary}
onClick={() => router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[5]}`)}
>
{t("t.next")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.next")}</Button>
</div>
</div>
</Form>
Expand Down
6 changes: 2 additions & 4 deletions sites/public/pages/eligibility/section8.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useForm } from "react-hook-form"

const EligibilitySection8 = () => {
/* Form Handler */
// eslint-disable-next-line @typescript-eslint/unbound-method
const { handleSubmit, register, errors } = useForm()
const onSubmit = () => {
// Not yet implemented.
Expand Down Expand Up @@ -63,10 +64,7 @@ const EligibilitySection8 = () => {
</div>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
{/*TODO: Implement onClick method to display results.*/}
<Button styleType={AppearanceStyleType.primary} onClick={() => {}}>
{t("t.done")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.done")}</Button>
</div>
</div>
</Form>
Expand Down
9 changes: 2 additions & 7 deletions sites/public/pages/eligibility/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EligibilityWelcome = () => {
/* Form Handler */
const { handleSubmit } = useForm()
const onSubmit = () => {
// Not implemented yet.
void router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[1]}`)
}

return (
Expand All @@ -44,12 +44,7 @@ const EligibilityWelcome = () => {
<Form onSubmit={handleSubmit(onSubmit)}>
<div className="form-card__pager">
<div className="form-card__pager-row primary">
<Button
styleType={AppearanceStyleType.primary}
onClick={() => router.push(`/${ELIGIBILITY_ROUTE}/${ELIGIBILITY_SECTIONS[1]}`)}
>
{t("t.next")}
</Button>
<Button styleType={AppearanceStyleType.primary}>{t("t.next")}</Button>
</div>
</div>
</Form>
Expand Down
3 changes: 2 additions & 1 deletion ui-components/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,8 @@
"age": {
"prompt": "كم عمرك؟",
"description": "تقبل بعض العقارات الأفراد الذين تزيد أعمارهم عن 62 عامًا فقط.",
"label": "سنة"
"label": "سنة",
"error": "الرجاء إدخال عمر صالح."
},
"disability": {
"prompt": "هل لديك اعاقة؟",
Expand Down
3 changes: 2 additions & 1 deletion ui-components/src/locales/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,8 @@
"age": {
"prompt": "আপনার বয়স কত?",
"description": "কিছু বৈশিষ্ট্য শুধুমাত্র 62 বছরের বেশি বয়সী ব্যক্তিদের গ্রহণ করে।",
"label": "বছর পুরনো"
"label": "বছর পুরনো",
"error": "দয়া করে একটি বৈধ বয়স লিখুন"
},
"disability": {
"prompt": "আপনি একটি অক্ষমতা আছে?",
Expand Down
3 changes: 2 additions & 1 deletion ui-components/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,8 @@
"age": {
"prompt": "¿Cuántos años tienes?",
"description": "Algunas propiedades solo aceptan personas mayores de 62 años.",
"label": "años"
"label": "años",
"error": "Ingrese una edad válida."
},
"disability": {
"prompt": "¿Tienes alguna discapacidad?",
Expand Down
3 changes: 2 additions & 1 deletion ui-components/src/locales/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,8 @@
"age" : {
"prompt": "How old are you?",
"description": "Some properties only accept individuals over 62 years of age.",
"label": "years old"
"label": "years old",
"error": "Please enter a valid age."
},
"disability" : {
"prompt" : "Do you have a disability?",
Expand Down

0 comments on commit 1bd7556

Please sign in to comment.