From f115032ae34891cb0871bd3fde4855cc16a4fa39 Mon Sep 17 00:00:00 2001 From: codevictory Date: Tue, 2 Nov 2021 23:33:04 +0200 Subject: [PATCH] Add registration form v1. --- src/App.tsx | 4 +- src/components/regForm.tsx | 113 ++++++++++++++++++++++++++++++++++++ src/components/utils.ts | 3 + src/model/visitor.ts | 11 ++-- src/styles/registration.css | 18 ++++++ 5 files changed, 140 insertions(+), 9 deletions(-) create mode 100644 src/components/regForm.tsx create mode 100644 src/components/utils.ts create mode 100644 src/styles/registration.css 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 +}); + +const allergies = ["lactose", "dairy", "gluten", "wheat"].map(allergy => { + return +}); + +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" /> +
+ + + + + + + + + + + + Ride + + + + + Accomodation + + + + + +
+ ))} + + + + + )} +
+ + + +
+ ); +}; \ 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); +}