melon_frontend/src/pages/newBill/index.tsx
Ruidy a9bf6936b5
refactoring (#18)
* chore: update deps to fix CVEs

* cleanup

* use variable for app routes

* refactor

* ⬆️ react router

* ⬆️ react

* delete pem files
2022-09-10 14:33:51 +02:00

28 lines
734 B
TypeScript

import { useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { createBill } from '../../api/bills';
import { BillForm } from '../../components/billForm';
import { withLayout } from '../../layouts/main';
import { BillFormType } from '../../types/bill';
const NewBillPage = () => {
// Hooks
const { handleSubmit, control } = useForm<BillFormType>();
const navigate = useNavigate();
// Logic
const onSubmit = handleSubmit(async (data) => {
const newId = await createBill(data);
navigate(`/bills/${newId}`);
});
return (
<>
<h1>Create a new bill</h1>
<BillForm onFinish={onSubmit} control={control} />
</>
);
};
export default withLayout(NewBillPage);