Ability to delete non-exported payment IO-559

This commit is contained in:
Patrick Fic
2021-01-21 15:57:42 -08:00
parent 2117896410
commit 3836750fb3
13 changed files with 195 additions and 10 deletions

View File

@@ -1541,6 +1541,27 @@
</translation> </translation>
</translations> </translations>
</concept_node> </concept_node>
<concept_node>
<name>deleting</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
<concept_node> <concept_node>
<name>exporting</name> <name>exporting</name>
<definition_loaded>false</definition_loaded> <definition_loaded>false</definition_loaded>
@@ -2312,6 +2333,27 @@
</translation> </translation>
</translations> </translations>
</concept_node> </concept_node>
<concept_node>
<name>deleted</name>
<definition_loaded>false</definition_loaded>
<description></description>
<comment></comment>
<default_text></default_text>
<translations>
<translation>
<language>en-US</language>
<approved>false</approved>
</translation>
<translation>
<language>es-MX</language>
<approved>false</approved>
</translation>
<translation>
<language>fr-CA</language>
<approved>false</approved>
</translation>
</translations>
</concept_node>
</children> </children>
</folder_node> </folder_node>
<folder_node> <folder_node>

View File

@@ -0,0 +1,52 @@
import { useMutation } from "@apollo/react-hooks";
import { Button, notification } from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { DELETE_BILL } from "../../graphql/bills.queries";
export default function BillDeleteButton({ bill }) {
const [loading, setLoading] = useState(false);
const { t } = useTranslation();
const [deleteBill] = useMutation(DELETE_BILL);
const handleDelete = async () => {
setLoading(true);
const result = await deleteBill({
variables: { billId: bill.id },
update(cache) {
cache.modify({
fields: {
bills(existingBills, { readField }) {
return existingBills.filter(
(billref) => bill.id !== readField("id", billref)
);
},
search_bills(existingBills, { readField }) {
return existingBills.filter(
(billref) => bill.id !== readField("id", billref)
);
},
},
});
},
});
if (!!!result.errors) {
notification["success"]({ message: t("bills.successes.deleted") });
} else {
notification["error"]({
message: t("bills.errors.deleting", {
error: JSON.stringify(result.errors),
}),
});
}
setLoading(false);
};
return (
<Button disabled={bill.exported} onClick={handleDelete} loading={loading}>
{t("general.actions.delete")}
</Button>
);
}

View File

@@ -1,5 +1,13 @@
import { SyncOutlined } from "@ant-design/icons"; import { SyncOutlined } from "@ant-design/icons";
import { Button, Checkbox, Descriptions, Input, Table, Typography } from "antd"; import {
Button,
Checkbox,
Descriptions,
Input,
Space,
Table,
Typography,
} from "antd";
import queryString from "query-string"; import queryString from "query-string";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -10,6 +18,7 @@ import { setModalContext } from "../../redux/modals/modals.actions";
import CurrencyFormatter from "../../utils/CurrencyFormatter"; import CurrencyFormatter from "../../utils/CurrencyFormatter";
import { DateFormatter } from "../../utils/DateFormatter"; import { DateFormatter } from "../../utils/DateFormatter";
import { alphaSort } from "../../utils/sorters"; import { alphaSort } from "../../utils/sorters";
import BillDeleteButton from "../bill-delete-button/bill-delete-button.component";
const mapStateToProps = createStructuredSelector({ const mapStateToProps = createStructuredSelector({
//jobRO: selectJobReadOnly, //jobRO: selectJobReadOnly,
@@ -106,7 +115,7 @@ export function BillsListTableComponent({
dataIndex: "actions", dataIndex: "actions",
key: "actions", key: "actions",
render: (text, record) => ( render: (text, record) => (
<div> <Space>
{record.exported ? ( {record.exported ? (
<Button disabled>{t("bills.actions.edit")}</Button> <Button disabled>{t("bills.actions.edit")}</Button>
) : ( ) : (
@@ -116,7 +125,8 @@ export function BillsListTableComponent({
<Button>{t("bills.actions.edit")}</Button> <Button>{t("bills.actions.edit")}</Button>
</Link> </Link>
)} )}
</div> <BillDeleteButton bill={record} />
</Space>
), ),
}, },
]; ];

View File

@@ -10,6 +10,14 @@ export const INSERT_NEW_BILL = gql`
} }
`; `;
export const DELETE_BILL = gql`
mutation DELETE_BILL($billId: uuid!) {
delete_bills_by_pk(id: $billId) {
id
}
}
`;
export const QUERY_ALL_BILLS_PAGINATED = gql` export const QUERY_ALL_BILLS_PAGINATED = gql`
query QUERY_ALL_BILLS_PAGINATED( query QUERY_ALL_BILLS_PAGINATED(
$search: String $search: String

View File

@@ -1,10 +1,11 @@
import { SyncOutlined } from "@ant-design/icons"; import { SyncOutlined } from "@ant-design/icons";
import { Button, Checkbox, Input, Table, Typography } from "antd"; import { Button, Checkbox, Input, Space, Table, Typography } from "antd";
import queryString from "query-string"; import queryString from "query-string";
import React, { useState } from "react"; import React, { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { Link, useHistory, useLocation } from "react-router-dom"; import { Link, useHistory, useLocation } from "react-router-dom";
import BillDeleteButton from "../../components/bill-delete-button/bill-delete-button.component";
import { setModalContext } from "../../redux/modals/modals.actions"; import { setModalContext } from "../../redux/modals/modals.actions";
import CurrencyFormatter from "../../utils/CurrencyFormatter"; import CurrencyFormatter from "../../utils/CurrencyFormatter";
import { DateFormatter } from "../../utils/DateFormatter"; import { DateFormatter } from "../../utils/DateFormatter";
@@ -98,7 +99,7 @@ export function BillsListPage({
dataIndex: "actions", dataIndex: "actions",
key: "actions", key: "actions",
render: (text, record) => ( render: (text, record) => (
<div> <Space>
<Link to={`/manage/bills?billid=${record.id}`}> <Link to={`/manage/bills?billid=${record.id}`}>
<Button>{t("bills.actions.edit")}</Button> <Button>{t("bills.actions.edit")}</Button>
</Link> </Link>
@@ -128,7 +129,8 @@ export function BillsListPage({
> >
{t("bills.actions.return")} {t("bills.actions.return")}
</Button> </Button>
</div> <BillDeleteButton bill={record} />
</Space>
), ),
}, },
]; ];

View File

@@ -112,7 +112,8 @@
"return": "Return Items" "return": "Return Items"
}, },
"errors": { "errors": {
"creating": "Error adding bill.", "creating": "Error adding bill. {{error}}",
"deleting": "Error deleting bill. {{error}}",
"exporting": "Error exporting payable(s). {{error}}", "exporting": "Error exporting payable(s). {{error}}",
"exporting-partner": "Unable to connect to ImEX Partner. Please ensure it is running and logged in.", "exporting-partner": "Unable to connect to ImEX Partner. Please ensure it is running and logged in.",
"invalidro": "Not a valid RO.", "invalidro": "Not a valid RO.",
@@ -154,7 +155,8 @@
"subtotal": "Subtotal" "subtotal": "Subtotal"
}, },
"successes": { "successes": {
"created": "Invoice added successfully." "created": "Invoice added successfully.",
"deleted": "Bill deleted successfully."
}, },
"validation": { "validation": {
"unique_invoice_number": "This invoice number has already been entered for this vendor." "unique_invoice_number": "This invoice number has already been entered for this vendor."

View File

@@ -113,6 +113,7 @@
}, },
"errors": { "errors": {
"creating": "", "creating": "",
"deleting": "",
"exporting": "", "exporting": "",
"exporting-partner": "", "exporting-partner": "",
"invalidro": "", "invalidro": "",
@@ -154,7 +155,8 @@
"subtotal": "" "subtotal": ""
}, },
"successes": { "successes": {
"created": "" "created": "",
"deleted": ""
}, },
"validation": { "validation": {
"unique_invoice_number": "" "unique_invoice_number": ""

View File

@@ -113,6 +113,7 @@
}, },
"errors": { "errors": {
"creating": "", "creating": "",
"deleting": "",
"exporting": "", "exporting": "",
"exporting-partner": "", "exporting-partner": "",
"invalidro": "", "invalidro": "",
@@ -154,7 +155,8 @@
"subtotal": "" "subtotal": ""
}, },
"successes": { "successes": {
"created": "" "created": "",
"deleted": ""
}, },
"validation": { "validation": {
"unique_invoice_number": "" "unique_invoice_number": ""

View File

@@ -0,0 +1,6 @@
- args:
role: user
table:
name: bills
schema: public
type: drop_delete_permission

View File

@@ -0,0 +1,21 @@
- args:
permission:
backend_only: false
filter:
_and:
- job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
- exported:
_eq: false
role: user
table:
name: bills
schema: public
type: create_delete_permission

View File

@@ -0,0 +1,12 @@
- args:
cascade: false
read_only: false
sql: |-
alter table "public"."documents" drop constraint "documents_billid_fkey",
add constraint "documents_invoiceid_fkey"
foreign key ("billid")
references "public"."bills"
("id")
on update restrict
on delete restrict;
type: run_sql

View File

@@ -0,0 +1,10 @@
- args:
cascade: false
read_only: false
sql: |-
alter table "public"."documents" drop constraint "documents_invoiceid_fkey",
add constraint "documents_billid_fkey"
foreign key ("billid")
references "public"."bills"
("id") on update restrict on delete set null;
type: run_sql

View File

@@ -587,6 +587,22 @@ tables:
- active: - active:
_eq: true _eq: true
check: null check: null
delete_permissions:
- role: user
permission:
filter:
_and:
- job:
bodyshop:
associations:
_and:
- user:
authid:
_eq: X-Hasura-User-Id
- active:
_eq: true
- exported:
_eq: false
- table: - table:
schema: public schema: public
name: bodyshops name: bodyshops