import {Button, message, Space, Typography} from "antd"; import {GetStaticPaths, GetStaticProps} from "next"; import {useState} from "react"; import {fetchAllBills, fetchOneBill, sendBillAsPDF} from "../../api"; import {withLayout} from "../../layouts/main"; import {Bill} from "../../types/bill"; type BillProps = { bill: Bill }; type QueryParams = { id: string }; export const getStaticPaths: GetStaticPaths = async () => { const bills = await fetchAllBills(); const paths = bills.map(({ id }) => ({ params: { id: id.toString() }, })); return { paths, fallback: false }; }; export const getStaticProps: GetStaticProps = async ({ params }) => { const billID = parseInt(params!.id); const bill = await fetchOneBill(billID); return { props: { bill } }; }; const BillPage = ({ bill }: BillProps) => { const [sent, setSent] = useState(false); const handleSendPDF = (id: number) => { sendBillAsPDF(id); message.success("The bill will be sent to the customer"); setSent(() => true); }; return (
Facture #VFNI{`${bill.id}`.padStart(4,"0")} {bill?.name} {bill?.price} € from {bill?.start} to {bill?.end}
); }; export default withLayout(BillPage);