From d8c0ca5737e6aaea1fb8b3e5f068c34f3d564bdc Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Fri, 15 May 2020 10:10:24 +0200 Subject: [PATCH] update useForm hook to handle checkboxes --- src/hooks/index.ts | 6 +- src/pages/AddEducation.tsx | 175 +++++++++++++++++++++++++------------ 2 files changed, 125 insertions(+), 56 deletions(-) diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 9651bd0..392cfd5 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -24,7 +24,11 @@ const useForm = (initFormData: T) => { /** clean form after successful submition */ const resetForm = () => setFormData(initFormData); - return {formData, handleChange, resetForm}; + // /** update checkboxes */ + const handleCheckboxesChange = (e: ChangeEvent): void => + setFormData({...formData, [e.target.name]: e.target.checked}); + + return {formData, handleChange, handleCheckboxesChange, resetForm}; }; export default useForm; diff --git a/src/pages/AddEducation.tsx b/src/pages/AddEducation.tsx index 0ad839b..b85895e 100644 --- a/src/pages/AddEducation.tsx +++ b/src/pages/AddEducation.tsx @@ -1,65 +1,130 @@ -import React, {FC} from 'react'; +import React, {FC, useState} from 'react'; import FormHeader from '../components/FormHeader'; +import {enhance} from '../store/firebase'; +import Routes from '../constants/routes'; +import {Link} from 'react-router-dom'; +import Dev from '../models/Dev'; +import {WithFirebaseProps, withFirebase} from 'react-redux-firebase'; +import User from '../models/User'; +import IAlert, {formAlert} from '../types/Alert'; +import Alert from '../components/Alert'; +import useForm from '../hooks'; + +interface FormData { + school: string; + degree: string; + from?: string; + to?: string; + current?: boolean; + description?: string; +} /** * Form to add an Education step to Profile */ -const AddEducation: FC = () => ( -
- + + icon="graduation-cap" + /> -
-
+ +
+ +
+
+ +
+
+ +
+
+

From Date

+ +
+
+

To Date

+ +
+
+

+ + Current School +

+
+
+ +
+ {alert.show && } -
-
- -
-
- -
-
-

From Date

- -
-
-

To Date

- -
-
-

- Current School -

-
-
- -
- - - Go Back - -
-
-); + + Go Back + + + + ); +}; -export default AddEducation; +export default withFirebase(AddEducation);