diff --git a/src/App.tsx b/src/App.tsx index b3af1b9..8a2dd13 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import './App.css'; import { Header } from "./components/header"; -import { Registration } from './components/registration'; +import { RegForm } from './components/regForm'; import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; export default function App() { @@ -12,7 +12,7 @@ export default function App() { - + ); diff --git a/src/components/regForm.tsx b/src/components/regForm.tsx new file mode 100644 index 0000000..19ce50a --- /dev/null +++ b/src/components/regForm.tsx @@ -0,0 +1,113 @@ +import { Button, Checkbox, Col, Form, Input, Row, Select, Space } from 'antd'; +import { useParams } from 'react-router'; +import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; + +import "./../styles/registration.css" +import { addVisitor } from '../api'; +import { capFirstLetter } from './utils'; +import { Visitor } from '../model/visitor'; + +const { Option } = Select; + +const { TextArea } = Input; + +interface ParamTypes { + id: string; +} + +interface FormValues { + visitors: Visitor[]; +} + +const preferences = ["vegan", "vegetarian", "everything goes"].map(preference => { + return {capFirstLetter(preference)} +}); + +const allergies = ["lactose", "dairy", "gluten", "wheat"].map(allergy => { + return {capFirstLetter(allergy)} +}); + +export const RegForm = () => { + const { id } = useParams(); + + const onFinish = (values: FormValues) => { + values.visitors.map(visitor => { + addVisitor({ + ...visitor, + allergies: visitor.allergies ? visitor.allergies.toString() : "", + services: visitor.services ? visitor.services.toString() : "", + preferences: visitor.preferences ?? "", + invitationId: visitor.invitationId = atob(id), + }); + }); + } + + const [form] = Form.useForm(); + + return ( + + + {(fields, { add, remove }) => ( + <> + { + fields.map(field => ( + + + + + + remove(field.name)} className="deleteButton" /> + + + + {allergies} + + + + + {preferences} + + + + + + + + Ride + + + + + Accomodation + + + + + + + ))} + + add()} block icon={}> + Add visitor + + + > + )} + + + + Submit + + + + ); +}; \ No newline at end of file diff --git a/src/components/utils.ts b/src/components/utils.ts new file mode 100644 index 0000000..ba38f7c --- /dev/null +++ b/src/components/utils.ts @@ -0,0 +1,3 @@ +export const capFirstLetter = (string: string) => { + return string.charAt(0).toUpperCase() + string.slice(1); +} \ No newline at end of file diff --git a/src/model/visitor.ts b/src/model/visitor.ts index 09c9f0e..ea3e4ac 100644 --- a/src/model/visitor.ts +++ b/src/model/visitor.ts @@ -1,10 +1,7 @@ export type Visitor = { name: string; - lactoseFree: boolean; - dairyFree: boolean; - wheatFree: boolean; - vegan: boolean; - vegatarian: boolean; - accomodation: boolean; - ride: boolean; + invitationId: string; + allergies: any; + services: any; + preferences: string; } \ No newline at end of file diff --git a/src/styles/registration.css b/src/styles/registration.css new file mode 100644 index 0000000..1f62477 --- /dev/null +++ b/src/styles/registration.css @@ -0,0 +1,18 @@ +form#registration { + max-width: 24.5em; + padding: 1em; +} + +.nameBar { + display: flex; + justify-content: space-between; + align-items: baseline; +} + +.visitorContainer { + margin-top: 1em; + margin-bottom: 1em; + padding: 1em; + border-radius: 5px; + background-color: rgb(235, 235, 235); +}