From 984a4a4cf619ae4999acd4b80a68af5d0964707f Mon Sep 17 00:00:00 2001 From: Allan Carr Date: Thu, 16 Mar 2023 16:44:12 -0700 Subject: [PATCH] IO-2193 Delete Owner & Vehicle --- .../owner-detail-form.container.jsx | 47 +++++++++++++++++-- .../vehicle-detail-form.container.jsx | 47 +++++++++++++++++-- client/src/graphql/owners.queries.js | 8 ++++ client/src/graphql/vehicles.queries.js | 8 ++++ client/src/translations/en_us/common.json | 6 +++ client/src/translations/es/common.json | 6 +++ client/src/translations/fr/common.json | 6 +++ 7 files changed, 118 insertions(+), 10 deletions(-) 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..381436d34 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,38 @@ -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"), + }); + setLoading(false); + } else { + notification["success"]({ + message: t("owners.successes.delete"), + }); + setLoading(false); + history.push(`/manage/owners`); + } + }; const handleFinish = async (values) => { setLoading(true); @@ -41,15 +64,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"), + }); + setLoading(false); + } else { + notification["success"]({ + message: t("vehicles.successes.delete"), + }); + setLoading(false); + history.push(`/manage/vehicles`); + } + }; const handleFinish = async (values) => { setLoading(true); @@ -40,15 +63,29 @@ function VehicleDetailFormContainer({ vehicle, refetch }) { <> + + , - } + , + ]} />