|
|
|
@@ -7,14 +7,11 @@ import { useTranslation } from "react-i18next"; |
|
|
|
import SearchResults, { Column } from "../SearchResults"; |
|
|
|
import { EditNote } from "@mui/icons-material"; |
|
|
|
import { useRouter, useSearchParams } from "next/navigation"; |
|
|
|
import { GridDeleteIcon } from "@mui/x-data-grid"; |
|
|
|
import { Chip } from "@mui/material"; |
|
|
|
import { TypeEnum } from "@/app/utils/typeEnum"; |
|
|
|
import axios from "axios"; |
|
|
|
import { BASE_API_URL, NEXT_PUBLIC_API_URL } from "@/config/api"; |
|
|
|
import axiosInstance from "@/app/(main)/axios/axiosInstance"; |
|
|
|
import { deleteItem } from "@/app/api/settings/item/actions"; |
|
|
|
import { deleteDialog, successDialog } from "../Swal/CustomAlerts"; |
|
|
|
|
|
|
|
type Props = { |
|
|
|
items: ItemsResult[]; |
|
|
|
@@ -135,22 +132,6 @@ const ItemsSearch: React.FC<Props> = ({ items }) => { |
|
|
|
refetchData, |
|
|
|
]); |
|
|
|
|
|
|
|
const onDeleteClick = useCallback( |
|
|
|
(item: ItemsResult) => { |
|
|
|
deleteDialog(async () => { |
|
|
|
if (item.id) { |
|
|
|
const itemId = typeof item.id === "string" ? parseInt(item.id, 10) : item.id; |
|
|
|
if (!isNaN(itemId)) { |
|
|
|
await deleteItem(itemId); |
|
|
|
await refetchData(filterObj); |
|
|
|
await successDialog(t("Delete Success"), t); |
|
|
|
} |
|
|
|
} |
|
|
|
}, t); |
|
|
|
}, |
|
|
|
[refetchData, filterObj, t], |
|
|
|
); |
|
|
|
|
|
|
|
const columns = useMemo<Column<ItemsResultWithStatus>[]>( |
|
|
|
() => [ |
|
|
|
{ |
|
|
|
@@ -158,22 +139,34 @@ const ItemsSearch: React.FC<Props> = ({ items }) => { |
|
|
|
label: t("Details"), |
|
|
|
onClick: onDetailClick, |
|
|
|
buttonIcon: <EditNote />, |
|
|
|
sx: { width: 80 }, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "code", |
|
|
|
label: t("Code"), |
|
|
|
sx: { width: 150 }, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "name", |
|
|
|
label: t("Name"), |
|
|
|
sx: { width: 250 }, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "LocationCode", |
|
|
|
label: t("LocationCode"), |
|
|
|
sx: { width: 150 }, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "type", |
|
|
|
label: t("Type"), |
|
|
|
sx: { width: 120 }, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "status", |
|
|
|
label: t("Status"), |
|
|
|
align: "center", |
|
|
|
headerAlign: "center", |
|
|
|
sx: { width: 120 }, |
|
|
|
renderCell: (item) => { |
|
|
|
const status = item.status || checkItemStatus(item); |
|
|
|
if (status === "complete") { |
|
|
|
@@ -183,14 +176,8 @@ const ItemsSearch: React.FC<Props> = ({ items }) => { |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
{ |
|
|
|
name: "action", |
|
|
|
label: t(""), |
|
|
|
buttonIcon: <GridDeleteIcon />, |
|
|
|
onClick: onDeleteClick, |
|
|
|
}, |
|
|
|
], |
|
|
|
[onDeleteClick, onDetailClick, t, checkItemStatus], |
|
|
|
[onDetailClick, t, checkItemStatus], |
|
|
|
); |
|
|
|
|
|
|
|
const onReset = useCallback(() => { |
|
|
|
|