Some fixes

This commit is contained in:
Riccardo
2021-01-06 16:15:11 +01:00
parent 9c0e997f10
commit 12b19e889f
2 changed files with 30 additions and 9 deletions

View File

@@ -14,6 +14,7 @@ const ONE_APPOINTMENT_QUERY = gql`
_id
title
description
type
start
end
}
@@ -24,14 +25,16 @@ const UPDATE_APPOINTMENT_MUTATION = gql`
mutation UpdateAppointmentMutation(
$_id: ID!
$title: String!
$description: String!
$start: String!
$end: String!
$description: String
$type: String!
$start: DateTime!
$end: DateTime!
) {
updateAppointment(title: $title, description: $description, start: $start, end: $end) {
_id
title
description
type
start
end
}
@@ -48,11 +51,12 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
});
let [formState, setFormState] = useState({
_id: '',
title: '',
description: '',
start: '',
end: ''
// _id: '',
// title: '',
// description: '',
// type: '',
// start: '',
// end: ''
});
const [updateAppointment] = useMutation(UPDATE_APPOINTMENT_MUTATION, {
@@ -60,6 +64,7 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
_id: formState._id,
title: formState.title,
description: formState.description,
type: formState.type,
start: formState.start,
end: formState.end
},
@@ -69,6 +74,9 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
if (data === undefined) {
return <div>Loading...</div>
} else {
// setFormState({
// formState.title= data.oneAppointment.title
// })
return (
<div>
@@ -88,7 +96,7 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
/>
<input
className="mb2"
value={data.oneAppointment.title}
value={formState.title}
onChange={(e) =>
setFormState({
...formState,
@@ -110,6 +118,18 @@ const UpdateAppointment = ({ match: { params: { _id } } }) => {
type="text"
placeholder="Input description"
/>
<input
className="mb2"
value={data.oneAppointment.type}
onChange={(e) =>
setFormState({
...formState,
type: e.target.value
})
}
type="text"
placeholder="Input description"
/>
<Datetime
className="mb2"
value={data.oneAppointment.start}

View File

@@ -77,6 +77,7 @@ export const resolvers = {
return await Appointment.create(args);
},
async updateAppointment(parent, args, context, info) {
console.log(args);
return await Appointment.findOneAndUpdate({
args
}, args, {