From 3343e3595e1c79f8c09df15ca17ab69b19ec3764 Mon Sep 17 00:00:00 2001 From: Ruidy Date: Thu, 15 Jul 2021 15:06:40 +0200 Subject: [PATCH] feat: redirect after creation --- src/pages/bill.tsx | 1 + src/pages/home.tsx | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pages/bill.tsx b/src/pages/bill.tsx index eb6329c..df32221 100644 --- a/src/pages/bill.tsx +++ b/src/pages/bill.tsx @@ -12,6 +12,7 @@ const BillPage = () => { // Hooks const { id } = useParams(); const [sent, setSent] = useState(false); + // Local State const [bill, setBill] = useState({} as Bill); diff --git a/src/pages/home.tsx b/src/pages/home.tsx index e32d2b6..9377e5d 100644 --- a/src/pages/home.tsx +++ b/src/pages/home.tsx @@ -1,5 +1,6 @@ import { Button, Form, Input, Switch } from 'antd'; import { Controller, useForm } from 'react-hook-form'; +import { useHistory } from 'react-router-dom'; import { createBill } from '../api'; import { InputSelect } from '../components/inputSelect'; import { withLayout } from '../layouts/main'; @@ -8,9 +9,13 @@ import { BillForm } from '../types/bill'; const HomePage = () => { // Hooks const { register, handleSubmit, control } = useForm(); + const history = useHistory(); // Logic - const onSubmit = handleSubmit((data) => createBill(data)); + const onSubmit = handleSubmit(async (data) => { + const newId = await createBill(data); + history.push(`/bills/${newId}`); + }); return (