Skip to content

Commit dbb1be2

Browse files
committed
Invoice items fixes
1 parent 75379b0 commit dbb1be2

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

src/components/FormContent/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import formContent from './form-content.jsx';
1+
import formContent from './form-content';
22

33
export default formContent;

src/components/InvoiceItem/invoice-item.js

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import PropTypes from 'prop-types';
88

99
class InvoiceItem extends Component {
1010
state = {
11+
id: this.props.id,
1112
amount: 1,
1213
name: '',
1314
price: 0.0,
@@ -63,6 +64,7 @@ class InvoiceItem extends Component {
6364
}
6465

6566
InvoiceItem.propTypes = {
67+
id: PropTypes.number.isRequired,
6668
onUpdate: PropTypes.func.isRequired,
6769
};
6870

src/components/Main/main.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { Component } from 'react';
22
import { List, ListItem, ListItemText } from '@material-ui/core';
3-
import AddIcon from '@material-ui/icons/Add';
43

54
import { InvoiceMaker, LVMH_TYPE } from '../../libs/invoicemaker';
65
import { TYPE_PVP, TYPE_RESELLER } from '../../constats/form-types';
@@ -34,16 +33,23 @@ class MainApp extends Component {
3433
onUpdateItem = (value) => {
3534
const { items } = this.state;
3635
const itemList = Object.assign([], [...items]);
36+
3737
itemList[value.id] = value;
3838
if (JSON.stringify(items) !== JSON.stringify(itemList)) this.setState({ items: itemList });
3939
};
4040

4141
writeItems = () => {
4242
const { items } = this.state;
4343
let list = [];
44+
4445
if (items.length > 0) {
4546
list = [
46-
...items.map(item => <InvoiceItem key={item.id} onUpdate={this.onUpdateItem} />),
47+
...items.map(item => (
48+
<InvoiceItem
49+
key={item.id}
50+
id={item.id}
51+
onUpdate={this.onUpdateItem}
52+
/>)),
4753
];
4854
}
4955
return list;
@@ -64,7 +70,7 @@ class MainApp extends Component {
6470
handleAddItem = () => {
6571
const { items } = this.state;
6672
const newItem = {
67-
id: items.length + 1, amount: 0, name: '', price: 0,
73+
id: items.length, amount: 0, name: '', price: 0,
6874
};
6975
this.setState({
7076
items: [...items, newItem],
@@ -110,7 +116,7 @@ class MainApp extends Component {
110116
</div>
111117
<div className="add">
112118
<button type="button" onClick={this.handleAddItem}>
113-
<AddIcon />
119+
+
114120
</button>
115121
</div>
116122
</div>

src/components/TopBar/top-bar.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@ import React, { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import blobStream from 'blob-stream';
44
import { saveAs } from 'file-saver';
5+
import PDFDocument from 'pdfkit';
56
import './styles.scss';
67

78

89
class TopBar extends Component {
910
handleCreatePdf = (e) => {
1011
e.preventDefault();
1112
const { getDocument } = this.props;
12-
import('pdfkit'/* webpackChunkName: pdfkit */).then((pdfkit) => {
13-
const PDFDocument = pdfkit.default;
14-
let doc = new PDFDocument({ margin: 10 });
15-
doc = getDocument(doc);
16-
const stream = doc.pipe(blobStream());
17-
stream.on('finish', () => {
18-
const blob = stream.toBlob('application/pdf');
19-
saveAs(blob, 'invoice');
20-
});
13+
let doc = new PDFDocument({ margin: 10 });
14+
doc = getDocument(doc);
15+
const stream = doc.pipe(blobStream());
16+
stream.on('finish', () => {
17+
const blob = stream.toBlob('application/pdf');
18+
saveAs(blob, 'invoice');
2119
});
2220
};
2321

@@ -31,9 +29,9 @@ class TopBar extends Component {
3129
<div className="header-bar-right">
3230
<ul>
3331
<li>
34-
<buton onClick={this.handleCreatePdf}>
32+
<button type="button" onClick={this.handleCreatePdf}>
3533
Generar
36-
</buton>
34+
</button>
3735
</li>
3836
</ul>
3937
</div>

src/libs/invoicemaker/src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TYPE_RESELLER, TYPE_PVP } from "../../../constats/form-types";
1+
import { TYPE_RESELLER, TYPE_PVP } from '../../../constats/form-types';
22

33
const LVMH_TYPE = 'lvmh';
44
const MGI_TYPE = 'mgi';
@@ -72,6 +72,7 @@ class InvoiceMaker {
7272
};
7373

7474
pdfSetItems = (items, shipping, formModel) => {
75+
console.log(items);
7576
this.calculatePositions(formModel);
7677
let footerContentX = this.footerContentX;
7778
let line = 0;

0 commit comments

Comments
 (0)