import React from "react";
import { useMutation } from "react-apollo";
import { CANCEL_APPOINTMENT_BY_ID } from "../../graphql/appointments.queries";
import ScheduleEventComponent from "./schedule-event.component";
import { notification } from "antd";
import { useTranslation } from "react-i18next";
export default function ScheduleEventContainer({ event, refetch }) {
  const { t } = useTranslation();
  const [cancelAppointment] = useMutation(CANCEL_APPOINTMENT_BY_ID);
  const handleCancel = id => {
    cancelAppointment({ variables: { appid: event.id } })
      .then(r => {
        notification["success"]({
          message: t("appointments.successes.canceled")
        });
        if (refetch) refetch();
      })
      .catch(error => {
        notification["error"]({ message: t("appointments.errors.canceling") });
      });
  };

  return <ScheduleEventComponent event={event} handleCancel={handleCancel} />;
}
