feat: redirect after creation

This commit is contained in:
Ruidy 2021-07-15 15:06:40 +02:00
parent e953246d06
commit 3343e3595e
2 changed files with 7 additions and 1 deletions

View file

@ -12,6 +12,7 @@ const BillPage = () => {
// Hooks
const { id } = useParams<QueryParams>();
const [sent, setSent] = useState(false);
// Local State
const [bill, setBill] = useState<Bill>({} as Bill);

View file

@ -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<BillForm>();
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 (
<main>