Skip to content

Commit

Permalink
cant delete finished products now
Browse files Browse the repository at this point in the history
  • Loading branch information
imkarimkarim committed Jun 23, 2021
1 parent 28df94c commit 5ac445a
Showing 1 changed file with 74 additions and 8 deletions.
82 changes: 74 additions & 8 deletions src/App/Components/Factor/ProductsTable.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState, useRef, useEffect } from "react";
const { ipcRenderer } = require("electron");
import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
Expand All @@ -8,13 +9,58 @@ import DeleteIcon from "@material-ui/icons/Delete";
import TableRow from "@material-ui/core/TableRow";
import Divider from "@material-ui/core/Divider";
import Expense from "../Expense.jsx";
import Notif from "../Notif.jsx";
import { Link } from "react-router-dom";
import "./ProductsTable.css";

export default function ProductsTable({ products, formDispatch, shouldLink }) {
console.log(products);
const [allUnFinishedProducts, setAllUnFinishedProducts] = useState();
const [notif, setNotif] = useState(null);
const init = useRef(true);

const isProductInUnfinishedProducts = (productId) => {
const aufp = allUnFinishedProducts;
for (let i = 0; i < aufp.length; i++) {
console.log(aufp[i].customeId, productId);
if (aufp[i].customeId === productId) {
return true;
}
}
return false;
};

const getUnFinishedProducts = () => {
ipcRenderer.send("getUnFinishedProducts");
};

useEffect(() => {
if (init.current) {
getUnFinishedProducts();
init.current = false;
}
ipcRenderer.on("getUnFinishedProducts", (event, dbproducts) => {
setAllUnFinishedProducts(dbproducts);
});
// clean up
return () => {
ipcRenderer.removeAllListeners("getUnFinishedProducts");
};
});

let notifJsx;
if (notif === "success")
notifJsx = <Notif type="success" message="با موفقیت حذف شد" />;
if (notif === "error")
notifJsx = (
<Notif
type="error"
message="صافی این بار بسته شده است. امکان حذف وجود ندارد"
/>
);

return (
<div className="ProductsTable">
{notifJsx ? notifJsx : ""}
<table>
<thead>
<tr>
Expand Down Expand Up @@ -51,13 +97,33 @@ export default function ProductsTable({ products, formDispatch, shouldLink }) {
}
</td>
{formDispatch ? (
<td
onDoubleClick={() =>
formDispatch({ type: "removeProduct", payload: index })
}
>
{<DeleteIcon />}
</td>
isProductInUnfinishedProducts(p.productId) ? (
<td
onDoubleClick={() => {
formDispatch({
type: "removeProduct",
payload: index,
});
setNotif(null);
setTimeout(function () {
setNotif("success");
}, 10);
}}
>
<DeleteIcon />
</td>
) : (
<td
onDoubleClick={() => {
setNotif(null);
setTimeout(function () {
setNotif("error");
}, 10);
}}
>
<DeleteIcon />
</td>
)
) : (
<td></td>
)}
Expand Down

0 comments on commit 5ac445a

Please sign in to comment.