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 ( -
- {errors ? JSON.stringify(errors) : null} - {formData && ( - - - Foster Application - - Thank you for your interest in becoming a Foster! Please fill out - the below application and someone from our team will be in touched - as soon as possible. Once approved, you will be able to access - your Foster Profile and be able to edit your informtion as you - need. - -
- - Contact Info - - - - - - - - - - - - - - - - - - - - - - - - - - Address - - - - - - - - - - - - - - - - - - Home Information - - Are you or another adult home during the day? - - - - - - - Tell us about your household - - - - Fenced Yard - - - Kids - - - Other Adults - - - Dog(s) - - - Cat(s) - - - - - Home Type - - - - - Animal Kind - - - - - Gender Preference - - - - - Age Preference - - - - - Size Preference - - - - - Transportation - - - - - Availability - - - - - - - - - - - - - - - {/* - - */} - - - - -
-
-
-
- -
- )} -
- ); + + 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') + } + }) + .catch((error) => console.dir(error)) + }; + + return ( +
+ {errors ? JSON.stringify(errors) : null} + {formData && ( + + + Foster Application + + Thank you for your interest in becoming a Foster! Please fill out + the below application and someone from our team will be in touched + as soon as possible. Once approved, you will be able to access + your Foster Profile and be able to edit your informtion as you + need. + +
+ + Contact Info + + + + + + + + + + + + + + + + + + + + + + + + + + Address + + + + + + + + + + + + + + + + + + Home Information + + Are you or another adult home during the day? + + + + + + + Tell us about your household + + + + Fenced Yard + + + Kids + + + Other Adults + + + Dog(s) + + + Cat(s) + + + + + Home Type + + + + + Animal Kind + + + + + Gender Preference + + + + + Age Preference + + + + + Size Preference + + + + + Transportation + + + + + Availability + + + + + + + + + + + + + + + + + Are there things we need to know about your schedule? + + + + + + + + + + +
+
+
+
+ +
+ )} +
+ ); }; -ReactDOM.render(, formTarget); +ReactDOM.render(, formTarget); diff --git a/db/migrate/20220613223104_add_availability_notes_to_person.rb b/db/migrate/20220613223104_add_availability_notes_to_person.rb new file mode 100644 index 0000000..d6fdf37 --- /dev/null +++ b/db/migrate/20220613223104_add_availability_notes_to_person.rb @@ -0,0 +1,5 @@ +class AddAvailabilityNotesToPerson < ActiveRecord::Migration[7.0] + def change + add_column :people, :availability_notes, :string, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ca7b7e..6156b16 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_05_05_020054) do +ActiveRecord::Schema[7.0].define(version: 2022_06_13_223104) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -112,6 +112,7 @@ t.datetime "remember_created_at" t.datetime "available_from" t.datetime "available_to", null: true + t.string "availability_notes", null: true t.index ["email"], name: "index_people_on_email", unique: true t.index ["reset_password_token"], name: "index_people_on_reset_password_token", unique: true end diff --git a/test/controllers/people_controller_test.rb b/test/controllers/people_controller_test.rb index 407ca2c..6a7e0d1 100644 --- a/test/controllers/people_controller_test.rb +++ b/test/controllers/people_controller_test.rb @@ -27,6 +27,8 @@ class PeopleControllerTest < ActionDispatch::IntegrationTest is_home_during_day: true, transportation: "car", available_from: 5.days.from_now, + available_to: 7.days.from_now, + availability_notes: "I cannot do the first week of next month because I am on vacation." } } end @@ -53,6 +55,8 @@ class PeopleControllerTest < ActionDispatch::IntegrationTest is_home_during_day: true, transportation: Person.transportations(), available_from: 5.days.from_now, + available_to: 7.days.from_now, + availability_notes: "I cannot do the first week of next month because I am on vacation." } } assert_redirected_to person_url(@person)