forked from pennylane-hq/jean_test_front
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial code for invoice create / edit
- Loading branch information
1 parent
0ea5046
commit 0e79cf1
Showing
7 changed files
with
241 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import Stack from 'react-bootstrap/Stack' | ||
import Container from 'react-bootstrap/Container' | ||
|
||
export default function Header() { | ||
return ( | ||
<header> | ||
<Stack className="mt-5"> | ||
<Container className="mt-5 mb-5"> | ||
<h1>Fern Hill</h1> | ||
<p className="text-muted">Invoices</p> | ||
</Stack> | ||
</Container> | ||
</header> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useState } from 'react' | ||
import type { Product } from '../../../types' | ||
|
||
import Row from 'react-bootstrap/Row' | ||
import Col from 'react-bootstrap/Col' | ||
import Form from 'react-bootstrap/Form' | ||
import Card from 'react-bootstrap/Card' | ||
|
||
import ProductAutocomplete from '../ProductAutocomplete' | ||
|
||
export function InvoiceLineForm() { | ||
const [selectedProduct, setSelectedProduct] = useState<Product>() | ||
|
||
return ( | ||
<Card className="mt-3"> | ||
<Card.Header>Add product</Card.Header> | ||
<Card.Body> | ||
<Row className="mb-3"> | ||
<ProductAutocomplete onChange={setSelectedProduct} /> | ||
</Row> | ||
<Row className="mb-3"> | ||
<Form.Group as={Col} controlId="inputTax"> | ||
<Form.Label className="text-end">Quantity</Form.Label> | ||
<Form.Control type="text" /> | ||
</Form.Group> | ||
|
||
<Form.Group as={Col} controlId="inputTax"> | ||
<Form.Label>Unit</Form.Label> | ||
<Form.Control type="text" /> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} controlId="inputTax"> | ||
<Form.Label>Label</Form.Label> | ||
<Form.Control type="text" /> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTax"> | ||
<Form.Label column sm={2}> | ||
VAT Rate | ||
</Form.Label> | ||
<Form.Control type="text" /> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTax"> | ||
<Form.Label column sm={2}> | ||
Price | ||
</Form.Label> | ||
<Form.Control type="text" readOnly /> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTax"> | ||
<Form.Label column sm={2}> | ||
Tax | ||
</Form.Label> | ||
<Form.Control type="text" /> | ||
</Form.Group> | ||
</Row> | ||
</Card.Body> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { useState } from 'react' | ||
|
||
import Row from 'react-bootstrap/Row' | ||
import Col from 'react-bootstrap/Col' | ||
import Button from 'react-bootstrap/Button' | ||
import Form from 'react-bootstrap/Form' | ||
import InputGroup from 'react-bootstrap/esm/InputGroup' | ||
import Container from 'react-bootstrap/esm/Container' | ||
|
||
import CustomerAutocomplete from '../CustomerAutocomplete' | ||
import { Invoice } from 'types' | ||
import { formatCustomerAddress } from 'app/lib/formatting' | ||
import ProductAutocomplete from '../ProductAutocomplete' | ||
import { InvoiceLineForm } from './InvoiceLineForm' | ||
|
||
const InvoiceCreate = () => { | ||
// const api = useApi() | ||
// const [invoice, setInvoice] = useState<Invoice>() | ||
|
||
const [formState, setFormState] = useState<Invoice>({ | ||
id: 0, | ||
customer_id: null, | ||
finalized: false, | ||
paid: false, | ||
date: null, | ||
deadline: null, | ||
total: null, | ||
tax: null, | ||
customer: undefined, | ||
invoice_lines: [], | ||
}) | ||
|
||
const setCustomer = (customer: NonNullable<Invoice['customer']>) => { | ||
setFormState((s) => ({ | ||
...s, | ||
customer_id: customer.id, | ||
customer, | ||
})) | ||
} | ||
|
||
const addProduct = (product: NonNullable<Invoice['invoice_lines'][0]>) => { | ||
setFormState((s) => ({ | ||
...s, | ||
invoice_lines: [...s.invoice_lines, product], | ||
})) | ||
} | ||
|
||
const [addingInvoiceLine, setAddingInvoiceLine] = useState(false) | ||
|
||
return ( | ||
<Container> | ||
<header className="mb-5"> | ||
<h2>New invoice</h2> | ||
</header> | ||
|
||
<Form> | ||
<Form.Group as={Row} className="mb-3" controlId="inputCustomer"> | ||
<Form.Label column sm={2} className="text-end"> | ||
Customer | ||
</Form.Label> | ||
<Col sm={10}> | ||
<CustomerAutocomplete | ||
value={formState.customer} | ||
onChange={setCustomer} | ||
/> | ||
{formState.customer ? ( | ||
<div className="pt-2 pb-2"> | ||
<strong>Address: </strong> | ||
<pre> | ||
{formatCustomerAddress(formState.customer)} | ||
<br /> | ||
{formState.customer.country} | ||
</pre> | ||
</div> | ||
) : null} | ||
</Col> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTotal"> | ||
<Form.Label column sm={2} className="text-end"> | ||
Total Amount | ||
</Form.Label> | ||
|
||
<Col sm={10}> | ||
<InputGroup> | ||
<InputGroup.Text>€</InputGroup.Text> | ||
<Form.Control | ||
type="text" | ||
inputMode="numeric" | ||
placeholder="0,00" | ||
/> | ||
</InputGroup> | ||
</Col> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTax"> | ||
<Form.Label column sm={2} className="text-end"> | ||
Tax | ||
</Form.Label> | ||
|
||
<Col sm={10}> | ||
<InputGroup> | ||
<InputGroup.Text>€</InputGroup.Text> | ||
<Form.Control | ||
type="text" | ||
inputMode="numeric" | ||
placeholder="0,00" | ||
/> | ||
</InputGroup> | ||
</Col> | ||
</Form.Group> | ||
|
||
<Form.Group as={Row} className="mb-3" controlId="inputTax"> | ||
<Form.Label column sm={2} className="text-end"> | ||
Items | ||
</Form.Label> | ||
|
||
<Col sm={10}> | ||
{addingInvoiceLine && <InvoiceLineForm />} | ||
<Button | ||
variant="secondary" | ||
onClick={() => setAddingInvoiceLine(true)} | ||
> | ||
Add product | ||
</Button> | ||
</Col> | ||
</Form.Group> | ||
|
||
<Row className="mt-5"> | ||
<Col sm={{ span: 10, offset: 2 }}> | ||
<Button variant="primary" type="submit"> | ||
Create invoice | ||
</Button> | ||
</Col> | ||
</Row> | ||
</Form> | ||
</Container> | ||
) | ||
} | ||
|
||
export default InvoiceCreate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useState, useEffect } from 'react' | ||
import { useParams } from 'react-router' | ||
|
||
import { useApi } from 'api' | ||
import { Invoice } from 'types' | ||
|
||
const InvoiceShow = () => { | ||
const { id } = useParams<{ id: string }>() | ||
const api = useApi() | ||
const [invoice, setInvoice] = useState<Invoice>() | ||
|
||
useEffect(() => { | ||
api.getInvoice(id).then(({ data }) => { | ||
setInvoice(data) | ||
}) | ||
}, [api, id]) | ||
|
||
return ( | ||
<div> | ||
<pre>{JSON.stringify(invoice ?? '', null, 2)}</pre> | ||
</div> | ||
) | ||
} | ||
|
||
export default InvoiceShow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters