mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-12 13:26:43 +00:00
feat: redirect after creation
This commit is contained in:
parent
e953246d06
commit
3343e3595e
2 changed files with 7 additions and 1 deletions
|
|
@ -12,6 +12,7 @@ const BillPage = () => {
|
||||||
// Hooks
|
// Hooks
|
||||||
const { id } = useParams<QueryParams>();
|
const { id } = useParams<QueryParams>();
|
||||||
const [sent, setSent] = useState(false);
|
const [sent, setSent] = useState(false);
|
||||||
|
|
||||||
// Local State
|
// Local State
|
||||||
const [bill, setBill] = useState<Bill>({} as Bill);
|
const [bill, setBill] = useState<Bill>({} as Bill);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { Button, Form, Input, Switch } from 'antd';
|
import { Button, Form, Input, Switch } from 'antd';
|
||||||
import { Controller, useForm } from 'react-hook-form';
|
import { Controller, useForm } from 'react-hook-form';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import { createBill } from '../api';
|
import { createBill } from '../api';
|
||||||
import { InputSelect } from '../components/inputSelect';
|
import { InputSelect } from '../components/inputSelect';
|
||||||
import { withLayout } from '../layouts/main';
|
import { withLayout } from '../layouts/main';
|
||||||
|
|
@ -8,9 +9,13 @@ import { BillForm } from '../types/bill';
|
||||||
const HomePage = () => {
|
const HomePage = () => {
|
||||||
// Hooks
|
// Hooks
|
||||||
const { register, handleSubmit, control } = useForm<BillForm>();
|
const { register, handleSubmit, control } = useForm<BillForm>();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
// Logic
|
// Logic
|
||||||
const onSubmit = handleSubmit((data) => createBill(data));
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
|
const newId = await createBill(data);
|
||||||
|
history.push(`/bills/${newId}`);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue