From 71512a1294279a8df7856a40fa3ed8a2177d41e2 Mon Sep 17 00:00:00 2001 From: mcarre20 Date: Mon, 11 Sep 2023 20:17:40 -0400 Subject: [PATCH 1/2] update create home function value --- .../src/pages/Admin/home/CreateNewHome.js | 82 ++++++++++++++----- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/frontend/front/src/pages/Admin/home/CreateNewHome.js b/frontend/front/src/pages/Admin/home/CreateNewHome.js index 546c299c..2e25263e 100644 --- a/frontend/front/src/pages/Admin/home/CreateNewHome.js +++ b/frontend/front/src/pages/Admin/home/CreateNewHome.js @@ -1,28 +1,40 @@ -import { Box, Button, TextField, Typography } from "@mui/material"; +import { Alert, Box, Button, TextField, Typography } from "@mui/material"; import { Controller, useForm } from "react-hook-form"; -import React from "react"; +import React, { useEffect } from "react"; import { useNavigate } from "react-router-dom"; - -import { withAdminPrefix, ADMIN_HOME } from "../../../routing/routes"; +import { useCreateHomeMutation } from "../../../api/apiSlice"; +import { ADMIN_HOME, withAdminPrefix } from "../../../routing/routes"; const CreateNewHome = () => { const navigate = useNavigate(); - const { handleSubmit, control } = useForm({ + const { handleSubmit, control, reset } = useForm({ defaultValues: { - streetNumber: "", - address: "", - zipCode: "", + street_number: "", + street_name: "", + unit_number: "", city: "", + state: "", + zip_code: "", }, }); - const onSubmit = (data) => console.log(data); + const [createHome, { isLoading, isSuccess, isError }] = + useCreateHomeMutation(); + const onSubmit = async (data) => { + createHome({ home: data }); + }; const handleCancel = () => { navigate(withAdminPrefix(ADMIN_HOME)); }; + useEffect(() => { + if (isSuccess) { + reset(); + } + }, [isSuccess, reset]); + return ( {
( )} /> ( )} /> ( )} /> - ( )} /> - + ( + + )} + /> + ( + + )} + /> + {isError && ( + + Error Saving home + + )} + {/* + + --Feature will not implemented on backend + */}