IO-2193 Delete Owner & Vehicle
This commit is contained in:
@@ -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 }) {
|
||||
<>
|
||||
<PageHeader
|
||||
title={t("menus.header.owners")}
|
||||
extra={
|
||||
extra={[
|
||||
<Popconfirm
|
||||
trigger="click"
|
||||
onConfirm={handleDelete}
|
||||
disabled={owner.jobs.length !== 0}
|
||||
title={t("owners.labels.deleteconfirm")}
|
||||
>
|
||||
<Button
|
||||
type="danger"
|
||||
loading={loading}
|
||||
disabled={owner.jobs.length !== 0}
|
||||
>
|
||||
{t("general.actions.delete")}
|
||||
</Button>
|
||||
</Popconfirm>,
|
||||
<Button
|
||||
type="primary"
|
||||
loading={loading}
|
||||
onClick={() => form.submit()}
|
||||
>
|
||||
{t("general.actions.save")}
|
||||
</Button>
|
||||
}
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<Form
|
||||
form={form}
|
||||
|
||||
@@ -1,16 +1,39 @@
|
||||
import React, { useState } from "react";
|
||||
import { Button, Form, notification, PageHeader } from "antd";
|
||||
import { Button, Form, notification, PageHeader, Popconfirm } from "antd";
|
||||
import { useMutation } from "@apollo/client";
|
||||
import VehicleDetailFormComponent from "./vehicle-detail-form.component";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import moment from "moment";
|
||||
import { UPDATE_VEHICLE } from "../../graphql/vehicles.queries";
|
||||
import { DELETE_VEHICLE, UPDATE_VEHICLE } from "../../graphql/vehicles.queries";
|
||||
import { useHistory } from "react-router-dom";
|
||||
|
||||
function VehicleDetailFormContainer({ vehicle, refetch }) {
|
||||
const { t } = useTranslation();
|
||||
const [updateVehicle] = useMutation(UPDATE_VEHICLE);
|
||||
const [deleteVehicle] = useMutation(DELETE_VEHICLE);
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const history = useHistory();
|
||||
|
||||
const handleDelete = async () => {
|
||||
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 }) {
|
||||
<>
|
||||
<PageHeader
|
||||
title={t("menus.header.vehicles")}
|
||||
extra={
|
||||
extra={[
|
||||
<Popconfirm
|
||||
trigger="click"
|
||||
onConfirm={handleDelete}
|
||||
disabled={vehicle.jobs.length !== 0}
|
||||
title={t("vehicles.labels.deleteconfirm")}
|
||||
>
|
||||
<Button
|
||||
type="danger"
|
||||
loading={loading}
|
||||
disabled={vehicle.jobs.length !== 0}
|
||||
>
|
||||
{t("general.actions.delete")}
|
||||
</Button>
|
||||
</Popconfirm>,
|
||||
<Button
|
||||
type="primary"
|
||||
loading={loading}
|
||||
onClick={() => form.submit()}
|
||||
>
|
||||
{t("general.actions.save")}
|
||||
</Button>
|
||||
}
|
||||
</Button>,
|
||||
]}
|
||||
/>
|
||||
<Form
|
||||
onFinish={handleFinish}
|
||||
|
||||
@@ -94,6 +94,14 @@ export const UPDATE_OWNER = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const DELETE_OWNER = gql`
|
||||
mutation DELETE_OWNER($id: uuid!) {
|
||||
delete_owners_by_pk(id: $id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const QUERY_ALL_OWNERS = gql`
|
||||
query QUERY_ALL_OWNERS {
|
||||
owners {
|
||||
|
||||
@@ -55,6 +55,14 @@ export const UPDATE_VEHICLE = gql`
|
||||
}
|
||||
`;
|
||||
|
||||
export const DELETE_VEHICLE = gql`
|
||||
mutation DELETE_VEHICLE($id: uuid!) {
|
||||
delete_vehicles_by_pk(id: $id) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const QUERY_ALL_VEHICLES = gql`
|
||||
query QUERY_ALL_VEHICLES {
|
||||
vehicles {
|
||||
|
||||
@@ -1993,6 +1993,7 @@
|
||||
"update": "Update Selected Records"
|
||||
},
|
||||
"errors": {
|
||||
"deleting": "Error deleting owner. {{error}}.",
|
||||
"noaccess": "The record does not exist or you do not have access to it. ",
|
||||
"saving": "Error saving owner. {{error}}.",
|
||||
"selectexistingornew": "Select an existing owner record or create a new one. "
|
||||
@@ -2025,6 +2026,7 @@
|
||||
},
|
||||
"labels": {
|
||||
"create_new": "Create a new owner record.",
|
||||
"deleteconfirm": "Are you sure you want to delete this owner? This cannot be undone.",
|
||||
"existing_owners": "Existing Owners",
|
||||
"fromclaim": "Current Claim",
|
||||
"fromowner": "Historical Owner Record",
|
||||
@@ -2032,6 +2034,7 @@
|
||||
"updateowner": "Update Owner"
|
||||
},
|
||||
"successes": {
|
||||
"delete": "Owner deleted successfully.",
|
||||
"save": "Owner saved successfully."
|
||||
}
|
||||
},
|
||||
@@ -2792,6 +2795,7 @@
|
||||
},
|
||||
"vehicles": {
|
||||
"errors": {
|
||||
"deleting": "Error deleting vehicle. {{error}}.",
|
||||
"noaccess": "The vehicle does not exist or you do not have access to it.",
|
||||
"selectexistingornew": "Select an existing vehicle record or create a new one. ",
|
||||
"validation": "Please ensure all fields are entered correctly.",
|
||||
@@ -2827,12 +2831,14 @@
|
||||
"registration": "Registration"
|
||||
},
|
||||
"labels": {
|
||||
"deleteconfirm": "Are you sure you want to delete this vehicle? This cannot be undone.",
|
||||
"fromvehicle": "Historical Vehicle Record",
|
||||
"novehinfo": "No Vehicle Information",
|
||||
"relatedjobs": "Related Jobs",
|
||||
"updatevehicle": "Update Vehicle Information"
|
||||
},
|
||||
"successes": {
|
||||
"delete": "Vehicle deleted successfully.",
|
||||
"save": "Vehicle saved successfully."
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1993,6 +1993,7 @@
|
||||
"update": ""
|
||||
},
|
||||
"errors": {
|
||||
"deleting": "",
|
||||
"noaccess": "El registro no existe o no tiene acceso a él.",
|
||||
"saving": "",
|
||||
"selectexistingornew": ""
|
||||
@@ -2025,6 +2026,7 @@
|
||||
},
|
||||
"labels": {
|
||||
"create_new": "Crea un nuevo registro de propietario.",
|
||||
"deleteconfirm": "",
|
||||
"existing_owners": "Propietarios existentes",
|
||||
"fromclaim": "",
|
||||
"fromowner": "",
|
||||
@@ -2032,6 +2034,7 @@
|
||||
"updateowner": ""
|
||||
},
|
||||
"successes": {
|
||||
"delete": "",
|
||||
"save": "Propietario guardado con éxito."
|
||||
}
|
||||
},
|
||||
@@ -2792,6 +2795,7 @@
|
||||
},
|
||||
"vehicles": {
|
||||
"errors": {
|
||||
"deleting": "",
|
||||
"noaccess": "El vehículo no existe o usted no tiene acceso a él.",
|
||||
"selectexistingornew": "",
|
||||
"validation": "Asegúrese de que todos los campos se ingresen correctamente.",
|
||||
@@ -2827,12 +2831,14 @@
|
||||
"registration": ""
|
||||
},
|
||||
"labels": {
|
||||
"deleteconfirm": "",
|
||||
"fromvehicle": "",
|
||||
"novehinfo": "",
|
||||
"relatedjobs": "",
|
||||
"updatevehicle": ""
|
||||
},
|
||||
"successes": {
|
||||
"delete": "",
|
||||
"save": "Vehículo guardado con éxito."
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1993,6 +1993,7 @@
|
||||
"update": ""
|
||||
},
|
||||
"errors": {
|
||||
"deleting": "",
|
||||
"noaccess": "L'enregistrement n'existe pas ou vous n'y avez pas accès.",
|
||||
"saving": "",
|
||||
"selectexistingornew": ""
|
||||
@@ -2025,6 +2026,7 @@
|
||||
},
|
||||
"labels": {
|
||||
"create_new": "Créez un nouvel enregistrement de propriétaire.",
|
||||
"deleteconfirm": "",
|
||||
"existing_owners": "Propriétaires existants",
|
||||
"fromclaim": "",
|
||||
"fromowner": "",
|
||||
@@ -2032,6 +2034,7 @@
|
||||
"updateowner": ""
|
||||
},
|
||||
"successes": {
|
||||
"delete": "",
|
||||
"save": "Le propriétaire a bien enregistré."
|
||||
}
|
||||
},
|
||||
@@ -2792,6 +2795,7 @@
|
||||
},
|
||||
"vehicles": {
|
||||
"errors": {
|
||||
"deleting": "",
|
||||
"noaccess": "Le véhicule n'existe pas ou vous n'y avez pas accès.",
|
||||
"selectexistingornew": "",
|
||||
"validation": "Veuillez vous assurer que tous les champs sont correctement entrés.",
|
||||
@@ -2827,12 +2831,14 @@
|
||||
"registration": ""
|
||||
},
|
||||
"labels": {
|
||||
"deleteconfirm": "",
|
||||
"fromvehicle": "",
|
||||
"novehinfo": "",
|
||||
"relatedjobs": "",
|
||||
"updatevehicle": ""
|
||||
},
|
||||
"successes": {
|
||||
"delete": "",
|
||||
"save": "Le véhicule a été enregistré avec succès."
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user