From 0f0e5f7408969fcc4473746919bb0e8aaa89947c Mon Sep 17 00:00:00 2001 From: MikunoNaka Date: Sun, 8 Aug 2021 13:00:16 +0530 Subject: half-cleaned the way saving invoices works --- src/components/Form/Transport/TransportForm.tsx | 12 +++++---- src/components/Menu/SubmitMenu.tsx | 16 ++++-------- src/components/Pages/BillingPage.tsx | 33 +++++++------------------ 3 files changed, 21 insertions(+), 40 deletions(-) (limited to 'src/components') diff --git a/src/components/Form/Transport/TransportForm.tsx b/src/components/Form/Transport/TransportForm.tsx index 60dfee3..af64d80 100644 --- a/src/components/Form/Transport/TransportForm.tsx +++ b/src/components/Form/Transport/TransportForm.tsx @@ -11,15 +11,17 @@ import { Transport } from "./../../../interfaces" interface Props { setVisibility: Dispatch> // this component's visibility + currentTransporter: Transport setTransporter: Dispatch> } const TransportForm: React.FC = (props) => { - const [transporterName, setTransporterName] = useState(""); - const [vehicleNum, setVehicleNum] = useState(""); - const [transportMethod, setTransportMethod] = useState(""); - const [transporterGSTIN, setTransporterGSTIN] = useState(""); - const [builtyNumber, setBuiltyNumber] = useState(""); + // read values from already existing transporter + const [transporterName, setTransporterName] = useState(props.currentTransporter.Name); + const [vehicleNum, setVehicleNum] = useState(props.currentTransporter.VehicleNum); + const [transportMethod, setTransportMethod] = useState(props.currentTransporter.Method); + const [transporterGSTIN, setTransporterGSTIN] = useState(props.currentTransporter.GSTIN); + const [builtyNumber, setBuiltyNumber] = useState(props.currentTransporter.Builty); const hideSelf = () => props.setVisibility(false); diff --git a/src/components/Menu/SubmitMenu.tsx b/src/components/Menu/SubmitMenu.tsx index 599b181..649b49d 100644 --- a/src/components/Menu/SubmitMenu.tsx +++ b/src/components/Menu/SubmitMenu.tsx @@ -6,16 +6,16 @@ * Copyright (c) 2021 Vidhu Kant Sharma */ -import React, { useState, Dispatch, SetStateAction } from "react"; -import { PDFViewer } from '@react-pdf/renderer'; -import PrintableDoc from "./../Print/PrintableDoc"; +import React, { Dispatch, SetStateAction } from "react"; +import { Transport, Item } from "./../../interfaces"; interface Props { setVisibility: Dispatch> // this component's visibility + transporter: Transport + items: Item[] } const TransportForm: React.FC = (props) => { - const [showPDF, setShowPDF] = useState(false); const hideSelf = () => props.setVisibility(false); @@ -24,13 +24,7 @@ const TransportForm: React.FC = (props) => { return (
- {showPDF && - - - - } -
- +
); diff --git a/src/components/Pages/BillingPage.tsx b/src/components/Pages/BillingPage.tsx index 8848406..58fdd40 100644 --- a/src/components/Pages/BillingPage.tsx +++ b/src/components/Pages/BillingPage.tsx @@ -7,7 +7,7 @@ */ import React, { useState, useEffect } from "react"; -import { Item, Person, Transport, Invoice } from "../../interfaces"; +import { Item, Person, Transport/*, Invoice*/ } from "../../interfaces"; import axios from "axios"; import DocumentInfoForm from "./../Form/Document/DocumentInfoForm"; @@ -29,10 +29,9 @@ const BillingPage: React.FC = () => { const [registerItemFormVisibility, setRegisterItemFormVisibility] = useState(false); const [registerPersonFormVisibility, setRegisterPersonFormVisibility] = useState(false); const [items, setItems] = useState([]); - const [invoiceNumber, setInvoiceNumber] = useState(1234); // get data from backend + const [invoiceNumber, setInvoiceNumber] = useState(1234); // TODO: get data from backend const [showTransportForm, setShowTransportForm] = useState(false); const [transporter, setTransporter] = useState({Name: "", VehicleNum: "", Method: "", GSTIN: "", Builty: ""}) - console.log(transporter); const [showSubmitMenu, setShowSubmitMenu] = useState(false); const getRegisteredItems = () => @@ -57,28 +56,11 @@ const BillingPage: React.FC = () => { // update the items from AddNewItemForm const getItems = (item: Item) => setItems([...items, item]); - /* - const postInvoice = () => { - const newInvoice: Invoice = { - Items: items, - Transport: transporter - } - window.print(); - - // just for testing it will not save to DB - axios.post("/api/invoice/preview", newInvoice) - .then((res) => { - alert("OH MY FUCKEN GOD") - console.log(res) - }) - .catch((res) => { - console.log(res) - }) - } - */ - const handleSubmit = () => { setShowSubmitMenu(true); + axios.post(`/api/invoices/preview`, {ID: 1010, Items: items, Transporter: transporter}) + .then(() => alert("yay")) + .catch(() => alert("nay")); } return ( @@ -101,6 +83,7 @@ const BillingPage: React.FC = () => { {showTransportForm && } @@ -108,6 +91,8 @@ const BillingPage: React.FC = () => { {showSubmitMenu && } @@ -135,8 +120,8 @@ const BillingPage: React.FC = () => { setShowTransportForm={setShowTransportForm} /> +
- ); } -- cgit v1.2.3