Delete Appointment works

This commit is contained in:
Riccardo
2021-01-06 12:15:53 +01:00
parent f25a3055e5
commit 9794f5c796
6 changed files with 36 additions and 48 deletions

View File

@@ -1,12 +1,29 @@
import React from 'react';
import { useMutation, gql } from '@apollo/client';
const DELETE_APPOINTMENT_MUTATION = gql`
mutation DeleteAppointmentMutation($_id: ID!) {
deleteAppointment(_id: $_id){
_id
}
}
`;
const Appointment = (props) => {
const { appointment } = props;
const [deleteAppointment] = useMutation(DELETE_APPOINTMENT_MUTATION, {
variables: { _id: appointment._id }
})
console.log(appointment._id);
return (
<div>
<div>
<b>{appointment.title}</b> starts at {appointment.start}, ends at {appointment.end}. It is described as "{appointment.description}"
</div>
<b><div className="ml1 gray f11" style={{ cursor: 'pointer' }} onClick={deleteAppointment}>[X]</div>{appointment.title}</b> starts at {appointment.start}, ends at {appointment.end}. It is described as "{appointment.description}"
</div>
</div>
);
};

View File

@@ -5,6 +5,7 @@ import { useQuery, gql } from '@apollo/client';
export const APPOINTMENTS_QUERY = gql`
{
allAppointments{
_id
title
description
start
@@ -18,12 +19,11 @@ const AppointmentList = () => {
const { data } = useQuery(APPOINTMENTS_QUERY);
if (data !== undefined) {
console.log(data.allAppointments);
return (
<div>
{
data.allAppointments.map((appointment) => (
<Appointment key={appointment.id} appointment={appointment} />
<Appointment key={appointment._id} appointment={appointment} />
))
}
</div>