|
| 1 | +import { useRouter } from 'next/router' |
| 2 | +import { useRef, useState } from 'react' |
| 3 | +import { Alert, Button, Text } from 'theme-ui' |
| 4 | +import FormContainer from './form-container' |
| 5 | +import OrganizationInfoForm from './org-form' |
| 6 | +import PersonalInfoForm from './personal-form' |
| 7 | +import { onSubmit } from './submit' |
| 8 | +import TeenagerOrAdultForm from './teenager-or-adult-form' |
| 9 | +import MultiStepForm from './multi-step-form' |
| 10 | + |
| 11 | +export default function ApplicationForm() { |
| 12 | + const router = useRouter() |
| 13 | + const formContainer = useRef() |
| 14 | + const [formError, setFormError] = useState(null) |
| 15 | + const [isSubmitting, setIsSubmitting] = useState(false) |
| 16 | + |
| 17 | + const requiredFields = { |
| 18 | + // Key: form field name |
| 19 | + // Value: humanize field name used in error message |
| 20 | + eventTeenagerLed: 'are you a teenager?', |
| 21 | + eventName: 'project name', |
| 22 | + eventPostalCode: 'project zip/postal code', |
| 23 | + eventDescription: 'project description', |
| 24 | + eventIsPolitical: "project's political activity", |
| 25 | + eventPoliticalActivity: "project's political activity", |
| 26 | + eventHasWebsite: 'project website', |
| 27 | + eventAnnualBudget: 'project annual budget', |
| 28 | + firstName: 'first name', |
| 29 | + lastName: 'last name', |
| 30 | + userEmail: 'email', |
| 31 | + userPhone: 'phone number', |
| 32 | + userBirthday: 'birthday', |
| 33 | + userAddressLine1: 'address line 1', |
| 34 | + userAddressCity: 'city', |
| 35 | + userAddressProvince: 'state/province', |
| 36 | + userAddressPostalCode: 'ZIP/postal code', |
| 37 | + userAddressCountry: 'country', |
| 38 | + |
| 39 | + referredBy: 'how did you hear about HCB?' |
| 40 | + } |
| 41 | + |
| 42 | + const submitButton = ( |
| 43 | + <Button |
| 44 | + variant="ctaLg" |
| 45 | + type="submit" |
| 46 | + disabled={isSubmitting} |
| 47 | + sx={{ |
| 48 | + backgroundImage: theme => theme.util.gx('cyan', 'blue'), |
| 49 | + '&:disabled': { |
| 50 | + background: 'muted', |
| 51 | + cursor: 'not-allowed', |
| 52 | + transform: 'none !important' |
| 53 | + }, |
| 54 | + width: 'fit-content' |
| 55 | + }} |
| 56 | + > |
| 57 | + {isSubmitting ? 'Submitting…' : 'Submit'} |
| 58 | + </Button> |
| 59 | + ) |
| 60 | + |
| 61 | + return ( |
| 62 | + <FormContainer |
| 63 | + ref={formContainer} |
| 64 | + className={formError ? 'has-errors' : null} |
| 65 | + onSubmit={event => |
| 66 | + onSubmit({ |
| 67 | + event, |
| 68 | + router, |
| 69 | + form: formContainer, |
| 70 | + setFormError, |
| 71 | + setIsSubmitting, |
| 72 | + requiredFields |
| 73 | + }) |
| 74 | + } |
| 75 | + > |
| 76 | + <MultiStepForm |
| 77 | + submitButton={submitButton} |
| 78 | + validationErrors={ |
| 79 | + formError && ( |
| 80 | + <Alert bg="primary" sx={{ mt: 4 }}> |
| 81 | + {formError} |
| 82 | + </Alert> |
| 83 | + ) |
| 84 | + } |
| 85 | + > |
| 86 | + {/* Step 1 */} |
| 87 | + <MultiStepForm.Step title="Let's get started"> |
| 88 | + <Text as="p" variant="caption" sx={{ marginBottom: '1rem' }}> |
| 89 | + Fill out this quick application to run your project on HCB. If you |
| 90 | + are a teenager, there is a very high likelihood we will accept your |
| 91 | + project. We just need to collect a few pieces of information first. |
| 92 | + </Text> |
| 93 | + <TeenagerOrAdultForm requiredFields={requiredFields} /> |
| 94 | + </MultiStepForm.Step> |
| 95 | + {/* Step 2 */} |
| 96 | + <MultiStepForm.Step> |
| 97 | + <OrganizationInfoForm requiredFields={requiredFields} /> |
| 98 | + </MultiStepForm.Step> |
| 99 | + {/* Step 3 */} |
| 100 | + <MultiStepForm.Step title="Personal details"> |
| 101 | + <PersonalInfoForm requiredFields={requiredFields} /> |
| 102 | + </MultiStepForm.Step> |
| 103 | + </MultiStepForm> |
| 104 | + </FormContainer> |
| 105 | + ) |
| 106 | +} |
0 commit comments