Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd86079

Browse files
RICKRICK
RICK
authored and
RICK
committed
lastweek-1
1 parent 7cefe1e commit bd86079

File tree

11 files changed

+492
-118
lines changed

11 files changed

+492
-118
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
1+
*.iml
2+
.idea
3+
.tscache
4+
.DS_Store
25
node_modules/
6+
typings/
7+
coverage/
8+
test/typescript/axios.js*
9+
sauce_connect.log

.idea/workspace.xml

Lines changed: 116 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ContactComponent from './components/contact.comp.jsx';
88
import ServiceComponent from './components/service.comp.jsx';
99
import GetPrice from './components/product.comp';
1010
import DLComponent from './components/driveLicence.comp';
11+
import DocUpload from './components/upload.comp';
1112

1213
ReactDOM.render(
1314
<Router history={hashHistory}>
@@ -19,6 +20,7 @@ ReactDOM.render(
1920
<Route path="/services/:doc" component={GetPrice} />
2021
<Route path="/client" component={ClientComponent}/>
2122
<Route path="/contact" component={ContactComponent}/>
23+
<Route path="/upload" component={DocUpload}/>
2224
</Route>
2325
</Router>,
2426
document.getElementById('app')

components/cart.comp.jsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import { Panel,Button,ListGroup,ListGroupItem,Badge ,Modal,Table,InputGroup} fro
66

77
class Cart extends React.Component{
88
constructor(props){
9-
super(props)
9+
super(props);
1010
this.state = {
1111
cart:{
1212
items: props.cartData.items,
1313
totalPrice: props.cartData.totalPrice
1414
},
1515
showCart: false
16-
}
16+
};
1717
this.show = this.show.bind(this);
1818
this.hideCart = this.hideCart.bind(this);
1919
this.addMoreDoc = this.addMoreDoc.bind(this);
20-
this.edit = this.edit.bind(this);
21-
this.test = this.test.bind(this);
20+
this.handleCheckout = this.handleCheckout.bind(this);
21+
2222
}
2323

2424
addMoreDoc(event){
@@ -37,12 +37,29 @@ class Cart extends React.Component{
3737
})
3838

3939
}
40-
test(e){
41-
e.stopPropagation();
42-
hashHistory.push('/');
43-
localStorage.clear();
40+
41+
handleCheckout(){
42+
// if(confirm('This button is currently in test and all data will be erased and back to Homepage, do you' +
43+
// 'want to continue?')){
44+
// let cart = JSON.parse(localStorage.cart);
45+
// this.printOrder(cart);
46+
// hashHistory.push('/');
47+
// localStorage.clear();
48+
// }
49+
hashHistory.push('/upload');
4450
}
45-
delete(item){
51+
printOrder(cart){
52+
let total = parseInt(cart.totalPrice);
53+
let itemNum = cart.items.length;
54+
let items = cart.items;
55+
items.map((item,index) => {
56+
console.log('your order:'+itemNum+' services this is '+(parseInt(index)+1)+' document' +
57+
', document name is:'+item.doc+' translate '+item.dir+' '+ item.lang+' the ' +
58+
'qty of hard copy is:'+item.extraCop);
59+
});
60+
console.log('total price is '+total);
61+
}
62+
remove(item){
4663
let newState = this.state.cart;
4764
const deletedItemPrice = item.subTotal;
4865
if (newState.items.indexOf(item) > -1) {
@@ -98,7 +115,7 @@ class Cart extends React.Component{
98115
}
99116
this.setState({
100117
cart: updatedCart
101-
})
118+
});
102119
localStorage.cart = JSON.stringify(this.state.cart);
103120

104121
}
@@ -129,7 +146,7 @@ class Cart extends React.Component{
129146
</InputGroup>
130147
</td>
131148
<td>${item.subTotal}</td>
132-
<td><Button bsStyle="danger" onClick={this.delete.bind(this,item)} id={'btn-'+item.id}>remove</Button></td>
149+
<td><Button bsStyle="danger" onClick={this.remove.bind(this,item)} id={'btn-'+item.id}>remove</Button></td>
133150
</tr>
134151
)
135152
});
@@ -139,7 +156,7 @@ class Cart extends React.Component{
139156
<Panel style={this.props.panelStyle.tab} header="Shopping Cart" bsStyle="info" >
140157
<ListGroup fill>
141158
<ListGroupItem><Button bsStyle="success" onClick={this.show} >ViewCart <Badge>{this.state.cart.items.length}</Badge></Button></ListGroupItem>
142-
<ListGroupItem><Button onClick={this.test} >CheckOut</Button></ListGroupItem>
159+
<ListGroupItem><Button onClick={this.handleCheckout} >CheckOut</Button></ListGroupItem>
143160
</ListGroup>
144161
</Panel>
145162

components/service.comp.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class ServiceComponent extends React.Component{
6262
null;
6363
break;
6464
}
65-
console.log(cached);
6665
this.setState({
6766
selectedVal: cached
6867
});
@@ -105,7 +104,7 @@ class ServiceComponent extends React.Component{
105104
lanOption(document){
106105
if(document === 'Family Register'){
107106
return(
108-
<option value='Japanese' key={0}>Japanese</option>
107+
<option value='Japanese' >Japanese</option>
109108
);
110109
}else{
111110
return (

components/upload.comp.jsx

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import React from 'react';
2+
import axios from 'axios';
3+
import ReactDOM from 'react-dom';
4+
5+
6+
7+
class DocUpload extends React.Component {
8+
9+
constructor(props){
10+
super(props);
11+
this.state = {
12+
cart: {
13+
items:[],
14+
totalPrice: 0
15+
},
16+
uploadFiles:[]
17+
}
18+
this.handleFileChange = this.handleFileChange.bind(this);
19+
this.handleSubmit = this.handleSubmit.bind(this);
20+
}
21+
componentDidMount(){
22+
if(localStorage.cart) {
23+
this.setState({
24+
cart:{
25+
items: JSON.parse(localStorage.cart).items,
26+
totalPrice: parseInt(JSON.parse(localStorage.cart).totalPrice)
27+
}
28+
});
29+
}
30+
}
31+
handleFileChange(item,event){
32+
let fileName = item.doc;
33+
let file = {};
34+
let files = [];
35+
36+
files.push(event.target.files);
37+
this.setState({
38+
uploadFiles: files
39+
});
40+
41+
//
42+
//
43+
console.log("doc name is %s",fileName);
44+
45+
}
46+
handleSubmit(event){
47+
let config = {
48+
headers:{
49+
"Content-Type":"multipart/form-data"
50+
}
51+
}
52+
let data = new FormData();
53+
54+
console.log(this.state.uploadFiles);
55+
axios.post('http://localhost/api/api/post/upload',data,config)
56+
.then((response) => {
57+
console.log(response.data);
58+
})
59+
.catch((err) => {
60+
console.log(err.message)
61+
});
62+
event.preventDefault();
63+
}
64+
65+
uploadInput(){
66+
return(
67+
this.state.cart.items.map((item,index) => {
68+
return(
69+
<div className="form-group" key={index}>
70+
<h4>{item.doc}</h4>
71+
<input className="file-input btn btn-info form-control" type="file" id={"item-"+index} name="docs[]"
72+
multiple onChange={(event) =>
73+
this.handleFileChange(item, event)}/>
74+
</div>
75+
)
76+
})
77+
);
78+
79+
80+
81+
}
82+
83+
render() {
84+
return (
85+
<div className="jumbotron text-center" >
86+
<h1>Upload your documents</h1>
87+
<form onSubmit={this.handleSubmit} encType="multipart/form-data">
88+
{this.uploadInput()}
89+
<div className="form-group">
90+
<h5>Please enter your full name</h5>
91+
<input type="text" ref="full-name" className="form-control"/>
92+
<h5>Please enter your post address</h5>
93+
<input type="text" ref="post-address" className="form-control"/>
94+
<h5>Other comment for the services</h5>
95+
<textarea className="form-control" ref="comment" rows="2" placeholder="Comments for these documents
96+
.e.g where are you going to use driver's licence" />
97+
</div>
98+
99+
<div className="form-group">
100+
<input type="submit" className="btn btn-success form-control" value="Upload"/>
101+
</div>
102+
103+
</form>
104+
</div>
105+
)
106+
}
107+
108+
}
109+
110+
111+
export default DocUpload;

0 commit comments

Comments
 (0)