Skip to content

Commit

Permalink
Merge pull request #2 from sc-ashik/master
Browse files Browse the repository at this point in the history
Time drop down added and headers add fixed
  • Loading branch information
mdforhadsarker authored May 8, 2020
2 parents 21706f1 + 20e3dfa commit c60232e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ export default class Form extends Component {

async onSubmit (e){
try {
let stream=JSON.stringify({
date: this.state.selectedDate,
time: this.state.selectedTime
})
// let headers=new Headers()
// headers.append("Content-Type", "application/json")
// headers.append("Content-Length",Buffer.byteLength(stream, 'utf-8'))

// console.log(stream.length.toString()+" "+Buffer.byteLength(stream, 'utf-8'))
// console.log("XXXX "+this.state.selectedDate+" , "+this.state.selectedTime)


let result = await fetch('http://localhost:3000/inspection',{
method: 'POST',
header: {
'Content-type': 'application/json'
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
date: 'selectedDate',
time: 'selectedTime'
})
body: stream
});
console.log(result)
} catch(e){
Expand All @@ -38,9 +46,9 @@ export default class Form extends Component {

onTimeSelected =(selectedTime) =>{
this.setState({
selectedTime: selectedTime
selectedTime: selectedTime.label
})
console.log("FF "+ selectedTime)
console.log("FF "+ selectedTime.label)
}

render() {
Expand Down
8 changes: 6 additions & 2 deletions src/components/TimeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ export default class TimeField extends Component {
.then(json => {
console.log(json)
this.setState({
times: json,
times: json.map((time,index)=>{
return {label:time,value:index}
}),
})
console.log(this.state.times)
})
}

Expand All @@ -37,6 +40,7 @@ export default class TimeField extends Component {

handleChange = selectedTime => {
this.setState({ selectedTime });
this.props.onTimeSelected(selectedTime)
console.log(`Option selected:`, selectedTime)
};

Expand All @@ -49,7 +53,7 @@ export default class TimeField extends Component {
isSearchable={false}
value={selectedTime}
onChange={this.handleChange}
options={options}
options={this.state.times}
placeholder="Time"
>

Expand Down

0 comments on commit c60232e

Please sign in to comment.