diff --git a/client/src/components/owner-detail-form/owner-detail-form.container.jsx b/client/src/components/owner-detail-form/owner-detail-form.container.jsx index 95f14ec00..fc1ae6bd1 100644 --- a/client/src/components/owner-detail-form/owner-detail-form.container.jsx +++ b/client/src/components/owner-detail-form/owner-detail-form.container.jsx @@ -1,15 +1,40 @@ -import { Button, Form, notification, PageHeader } from "antd"; +import { Button, Form, notification, PageHeader, Popconfirm } from "antd"; import React, { useState } from "react"; +import { useHistory } from "react-router-dom"; import { useMutation } from "@apollo/client"; import { useTranslation } from "react-i18next"; -import { UPDATE_OWNER } from "../../graphql/owners.queries"; +import { DELETE_OWNER, UPDATE_OWNER } from "../../graphql/owners.queries"; import OwnerDetailFormComponent from "./owner-detail-form.component"; function OwnerDetailFormContainer({ owner, refetch }) { const { t } = useTranslation(); const [form] = Form.useForm(); + const history = useHistory(); const [loading, setLoading] = useState(false); const [updateOwner] = useMutation(UPDATE_OWNER); + const [deleteOwner] = useMutation(DELETE_OWNER); + + const handleDelete = async () => { + setLoading(true); + const result = await deleteOwner({ + variables: { id: owner.id }, + }); + console.log(result); + if (result.errors) { + notification["error"]({ + message: t("owners.errors.deleting", { + error: JSON.stringify(result.errors), + }), + }); + setLoading(false); + } else { + notification["success"]({ + message: t("owners.successes.delete"), + }); + setLoading(false); + history.push(`/manage/owners`); + } + }; const handleFinish = async (values) => { setLoading(true); @@ -41,15 +66,29 @@ function OwnerDetailFormContainer({ owner, refetch }) { <> + + , - } + , + ]} />
{ + setLoading(true); + const result = await deleteVehicle({ + variables: { id: vehicle.id }, + }); + console.log(result); + if (result.errors) { + notification["error"]({ + message: t("vehicles.errors.deleting", { + error: JSON.stringify(result.errors), + }), + }); + setLoading(false); + } else { + notification["success"]({ + message: t("vehicles.successes.delete"), + }); + setLoading(false); + history.push(`/manage/vehicles`); + } + }; const handleFinish = async (values) => { setLoading(true); @@ -40,15 +65,29 @@ function VehicleDetailFormContainer({ vehicle, refetch }) { <> + + , - } + , + ]} />