mirror of
https://github.com/rjNemo/melon_frontend
synced 2026-06-06 02:16:45 +00:00
feat: new home page
This commit is contained in:
parent
ef167a6c37
commit
e8b30c868f
4 changed files with 42 additions and 17 deletions
|
|
@ -12,7 +12,7 @@ yarn dev
|
||||||
|
|
||||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
You can start editing the page by modifying `pages/home.tsx`. The page auto-updates as you edit the file.
|
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
|
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Route, Switch } from 'react-router-dom';
|
||||||
import BillPage from './pages/bill';
|
import BillPage from './pages/bill';
|
||||||
import BillsPage from './pages/bills';
|
import BillsPage from './pages/bills';
|
||||||
import HomePage from './pages/home';
|
import HomePage from './pages/home';
|
||||||
|
import NewBillPage from './pages/newBill';
|
||||||
import NotFoundPage from './pages/notFound';
|
import NotFoundPage from './pages/notFound';
|
||||||
|
|
||||||
type RouteConfig = {
|
type RouteConfig = {
|
||||||
|
|
@ -17,6 +18,11 @@ export default function Router() {
|
||||||
component: HomePage,
|
component: HomePage,
|
||||||
exact: true
|
exact: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/bills/new',
|
||||||
|
component: NewBillPage,
|
||||||
|
exact: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/bills',
|
path: '/bills',
|
||||||
component: BillsPage,
|
component: BillsPage,
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,19 @@
|
||||||
import { useForm } from 'react-hook-form';
|
import { Button } from 'antd';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { createBill } from '../api';
|
|
||||||
import { BillForm } from '../components/billForm';
|
|
||||||
import { withLayout } from '../layouts/main';
|
import { withLayout } from '../layouts/main';
|
||||||
import { BillFormType } from '../types/bill';
|
|
||||||
|
|
||||||
const HomePage = () => {
|
function HomePage() {
|
||||||
// Hooks
|
// Hooks
|
||||||
const { handleSubmit, control } = useForm<BillFormType>();
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
// Logic
|
|
||||||
const onSubmit = handleSubmit(async (data) => {
|
|
||||||
const newId = await createBill(data);
|
|
||||||
history.push(`/bills/${newId}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<h1>Create a new bill</h1>
|
<h1>Rent it Like a Pro</h1>
|
||||||
|
<Button type="primary" size="large" onClick={() => history.push('/bills/new')}>
|
||||||
<BillForm onFinish={onSubmit} control={control} />
|
Add Bill
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
|
||||||
export default withLayout(HomePage);
|
export default withLayout(HomePage);
|
||||||
|
|
|
||||||
28
src/pages/newBill/index.tsx
Normal file
28
src/pages/newBill/index.tsx
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { createBill } from '../../api';
|
||||||
|
import { BillForm } from '../../components/billForm';
|
||||||
|
import { withLayout } from '../../layouts/main';
|
||||||
|
import { BillFormType } from '../../types/bill';
|
||||||
|
|
||||||
|
const NewBillPage = () => {
|
||||||
|
// Hooks
|
||||||
|
const { handleSubmit, control } = useForm<BillFormType>();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
// Logic
|
||||||
|
const onSubmit = handleSubmit(async (data) => {
|
||||||
|
const newId = await createBill(data);
|
||||||
|
history.push(`/bills/${newId}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<h1>Create a new bill</h1>
|
||||||
|
|
||||||
|
<BillForm onFinish={onSubmit} control={control} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withLayout(NewBillPage);
|
||||||
Loading…
Reference in a new issue