Skip to content

Commit ade2b97

Browse files
mutation events
1 parent 5bddd0f commit ade2b97

File tree

1 file changed

+53
-3
lines changed

1 file changed

+53
-3
lines changed

frontend/src/pages/Events.js

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default class Events extends Component {
2323
modalConfirmHandler = () => {
2424
this.setState({ creating: false });
2525
const title = this.titleElRef.current.value;
26-
const price = this.priceElRef.current.value;
26+
const price = +this.priceElRef.current.value;
2727
const date = this.dateElRef.current.value;
2828
const description = this.descriptionElRef.current.value;
2929

@@ -37,7 +37,57 @@ export default class Events extends Component {
3737
}
3838

3939
const event = { title, price, date, description };
40-
console.log(event);
40+
41+
const requestBody = {
42+
query: `
43+
mutation {
44+
createEvent(eventInput: {
45+
title: "${title}",
46+
description: "${description}",
47+
date: "${date}",
48+
price: ${price}
49+
})
50+
{
51+
_id
52+
title
53+
description
54+
date
55+
price
56+
creator {
57+
_id
58+
email
59+
}
60+
}
61+
}
62+
`
63+
};
64+
65+
fetch('http://localhost:5000/api', {
66+
method: 'POST',
67+
body: JSON.stringify(requestBody),
68+
headers: {
69+
'Content-Type': 'application/json'
70+
}
71+
})
72+
.then(response => {
73+
if (response.status !== 200 && response.status !== 201) {
74+
throw new Error('Failed');
75+
}
76+
return response.json();
77+
})
78+
.then(responseData => {
79+
console.log(responseData);
80+
if (responseData.data.login.token) {
81+
this.context.login(
82+
responseData.data.login.token,
83+
responseData.data.login.userId,
84+
responseData.data.login.tokenExpiration
85+
);
86+
}
87+
})
88+
.catch(err => {
89+
console.log(err);
90+
});
4191
};
4292

4393
modalCancelHandler = () => {
@@ -67,7 +117,7 @@ export default class Events extends Component {
67117
</div>
68118
<div>
69119
<label htmlFor='date'>Date</label>
70-
<input type='date' id='date' ref={this.dateElRef} />
120+
<input type='datetime-local' id='date' ref={this.dateElRef} />
71121
</div>
72122
<div>
73123
<label htmlFor='description'>Description</label>

0 commit comments

Comments
 (0)