mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-10 20:36:42 +00:00
* chore: update deps to fix CVEs * cleanup * use variable for app routes * refactor * ⬆️ react router * ⬆️ react * delete pem files
28 lines
734 B
TypeScript
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);
|