diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 02f5985..b2bbd34 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -80,7 +80,8 @@ def person_params :is_home_during_day, :transportation, :available_from, - :available_to + :available_to, + :availability_notes, ) end end diff --git a/app/controllers/signups_controller.rb b/app/controllers/signups_controller.rb index 6bcfb44..87cdb1d 100644 --- a/app/controllers/signups_controller.rb +++ b/app/controllers/signups_controller.rb @@ -51,6 +51,7 @@ def person_params :transportation, :available_from, :available_to, + :availability_notes, animal_kind_preferences_attributes: [:animal_value], animal_gender_preferences_attributes: [:animal_value], animal_age_preferences_attributes: [:animal_value], diff --git a/app/javascript/components/signups/SignUpForm.tsx b/app/javascript/components/signups/SignUpForm.tsx index 1030338..356c696 100644 --- a/app/javascript/components/signups/SignUpForm.tsx +++ b/app/javascript/components/signups/SignUpForm.tsx @@ -1,387 +1,393 @@ -import React, { useEffect, useState } from "react"; +import React, {useEffect, useState} from "react"; import ReactDOM from "react-dom"; import axios from 'axios' -import { DatePicker } from "antd"; +import {DatePicker} from "antd"; import { - Button, - Col, - Form, - Input, - Divider, - Checkbox, - Radio, - Row, - Space, - Typography, + Button, + Col, + Form, + Input, + Divider, + Checkbox, + Radio, + Row, + Space, + Typography, } from "antd"; -const { Title, Paragraph } = Typography; +const {Title, Paragraph} = Typography; const formTarget = document.getElementById("signup-form"); const SignUp = () => { - const [formData, setFormData] = useState(); - const [errors, setErrors] = useState(); - - useEffect(() => { - axios.get("/signup.json") - .then(({ data }) => { - setFormData(data) - }) - .catch((errors) => setErrors(errors)) - }, []); - - const homeOptions = [ - { label: "Apartment/Condo", value: 1 }, - { label: "House", value: 2 }, - { label: "Townhome", value: 3 }, - ]; - - const sizeOptions = [ - { label: "less than 20 lbs", value: 1 }, - { label: "20 - 40 lbs", value: 2 }, - { label: "40 - 60 lbs", value: 3 }, - { label: "60lbs +", value: 4 }, - ]; - - const ageOptions = [ - { label: "Newborn (up to 3 months)", value: 1 }, - { label: "Young (3 months - 2 years)", value: 2 }, - { label: "Adult (2 - 5 years)", value: 3 }, - { label: "Senior (5 years + )", value: 4 }, - ]; - - const genderOptions = [ - { label: "Male", value: 1 }, - { label: "Female", value: 2 }, - ]; - - const kindOptions = [ - { label: "Dog", value: 1 }, - { label: "Cat", value: 2, disabled: true }, - ]; - - const onFinish = (values) => { - let age, - gender, - kind, - size, - home = {}, - { - animal_age_preferences_attributes, - animal_gender_preferences_attributes, - animal_kind_preferences_attributes, - animal_size_preferences_attributes, - homes_attributes, - home_type, - street, - apt, - city, - state, - zip, - } = values - - homes_attributes?.forEach((value) => { - home[value] = 1 - }) - - if (animal_age_preferences_attributes?.length) age = [] - animal_age_preferences_attributes?.forEach((value, i) => { - age[i] = { animal_value: value } - }) - - if (animal_gender_preferences_attributes?.length) gender = [] - animal_gender_preferences_attributes?.forEach((value, i) => { - gender[i] = { animal_value: value } - }) - - if (animal_kind_preferences_attributes?.length) kind = [] - animal_kind_preferences_attributes?.forEach((value, i) => { - kind[i] = { animal_value: value } - }) - - if (animal_size_preferences_attributes?.length) size = [] - animal_size_preferences_attributes?.forEach((value, i) => { - size[i] = { animal_value: value } - }) - - const addressAttributes = { street, apt, city, state, zip_code: zip }, - newHomeAttributes = { ...home, ...addressAttributes, home_type } - - const payload = { - authenticity_token: formData.token, - person: { - ...values, - homes_attributes: [newHomeAttributes], - animal_age_preferences_attributes: age, - animal_gender_preferences_attributes: gender, - animal_kind_preferences_attributes: kind, - animal_size_preferences_attributes: size, - }, - } - - delete payload.person['home_type'] - delete payload.person['street'] - delete payload.person['apt'] - delete payload.person['city'] - delete payload.person['state'] - delete payload.person['zip'] - - axios.post(`${formData.path}.json`, payload) - .then(({ data, status }: any) => { - if (status === 201) { - window.location.href = data.path - } else { - alert('Failed to create foster application') + const [formData, setFormData] = useState(); + const [errors, setErrors] = useState(); + + useEffect(() => { + axios.get("/signup.json") + .then(({data}) => { + setFormData(data) + }) + .catch((errors) => setErrors(errors)) + }, []); + + const homeOptions = [ + {label: "Apartment/Condo", value: 1}, + {label: "House", value: 2}, + {label: "Townhome", value: 3}, + ]; + + const sizeOptions = [ + {label: "less than 20 lbs", value: 1}, + {label: "20 - 40 lbs", value: 2}, + {label: "40 - 60 lbs", value: 3}, + {label: "60lbs +", value: 4}, + ]; + + const ageOptions = [ + {label: "Newborn (up to 3 months)", value: 1}, + {label: "Young (3 months - 2 years)", value: 2}, + {label: "Adult (2 - 5 years)", value: 3}, + {label: "Senior (5 years + )", value: 4}, + ]; + + const genderOptions = [ + {label: "Male", value: 1}, + {label: "Female", value: 2}, + ]; + + const kindOptions = [ + {label: "Dog", value: 1}, + {label: "Cat", value: 2, disabled: true}, + ]; + + const onFinish = (values) => { + let age, + gender, + kind, + size, + home = {}, + { + animal_age_preferences_attributes, + animal_gender_preferences_attributes, + animal_kind_preferences_attributes, + animal_size_preferences_attributes, + homes_attributes, + home_type, + street, + apt, + city, + state, + zip, + } = values + + homes_attributes?.forEach((value) => { + home[value] = 1 + }) + + if (animal_age_preferences_attributes?.length) age = [] + animal_age_preferences_attributes?.forEach((value, i) => { + age[i] = {animal_value: value} + }) + + if (animal_gender_preferences_attributes?.length) gender = [] + animal_gender_preferences_attributes?.forEach((value, i) => { + gender[i] = {animal_value: value} + }) + + if (animal_kind_preferences_attributes?.length) kind = [] + animal_kind_preferences_attributes?.forEach((value, i) => { + kind[i] = {animal_value: value} + }) + + if (animal_size_preferences_attributes?.length) size = [] + animal_size_preferences_attributes?.forEach((value, i) => { + size[i] = {animal_value: value} + }) + + const addressAttributes = {street, apt, city, state, zip_code: zip}, + newHomeAttributes = {...home, ...addressAttributes, home_type} + + const payload = { + authenticity_token: formData.token, + person: { + ...values, + homes_attributes: [newHomeAttributes], + animal_age_preferences_attributes: age, + animal_gender_preferences_attributes: gender, + animal_kind_preferences_attributes: kind, + animal_size_preferences_attributes: size, + }, } - }) - .catch((error) => console.dir(error)) - }; - - return ( -