FPSMS-frontend
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

151 rader
4.2 KiB

  1. "use client";
  2. import { PoResult } from "@/app/api/po";
  3. import { useCallback, useMemo, useState } from "react";
  4. import { useTranslation } from "react-i18next";
  5. import { useRouter, useSearchParams } from "next/navigation";
  6. import SearchBox, { Criterion } from "../SearchBox";
  7. import SearchResults, { Column } from "../SearchResults";
  8. import { EditNote } from "@mui/icons-material";
  9. import { Button, Grid, Tab, Tabs, TabsProps, Typography } from "@mui/material";
  10. import QrModal from "../PoDetail/QrModal";
  11. import { WarehouseResult } from "@/app/api/warehouse";
  12. import NotificationIcon from '@mui/icons-material/NotificationImportant';
  13. import { useSession } from "next-auth/react";
  14. type Props = {
  15. po: PoResult[];
  16. warehouse: WarehouseResult[];
  17. };
  18. type SearchQuery = Partial<Omit<PoResult, "id">>;
  19. type SearchParamNames = keyof SearchQuery;
  20. const PoSearch: React.FC<Props> = ({ po, warehouse }) => {
  21. const [filteredPo, setFilteredPo] = useState<PoResult[]>(po);
  22. const { t } = useTranslation("purchaseOrder");
  23. const router = useRouter();
  24. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(() => {
  25. var searchCriteria: Criterion<SearchParamNames>[] = [
  26. { label: t("Code"), paramName: "code", type: "text" },
  27. { label: t("Status"), paramName: "status", type: "select", options: ["PENDING", "RECEIVING", "COMPLETED"] },
  28. { label: t("Escalated"), paramName: "escalated", type: "select", options: [t("Escalated"), t("NotEscalated")] },
  29. ];
  30. return searchCriteria;
  31. }, [t, po]);
  32. const onDetailClick = useCallback(
  33. (po: PoResult) => {
  34. router.push(`/po/edit?id=${po.id}`);
  35. },
  36. [router]
  37. );
  38. const onDeleteClick = useCallback((po: PoResult) => {}, [router]);
  39. const columns = useMemo<Column<PoResult>[]>(
  40. () => [
  41. {
  42. name: "id",
  43. label: t("Details"),
  44. onClick: onDetailClick,
  45. buttonIcon: <EditNote />,
  46. },
  47. {
  48. name: "code",
  49. label: t("Code"),
  50. },
  51. {
  52. name: "orderDate",
  53. label: t("OrderDate"),
  54. },
  55. {
  56. name: "supplier",
  57. label: t("Supplier"),
  58. },
  59. {
  60. name: "status",
  61. label: t("Status"),
  62. },
  63. {
  64. name: "escalated",
  65. label: t("Escalated"),
  66. renderCell: (params) => {
  67. return params.escalated ? <NotificationIcon color="warning"/> : undefined
  68. }
  69. },
  70. // {
  71. // name: "name",
  72. // label: t("Name"),
  73. // },
  74. // {
  75. // name: "action",
  76. // label: t(""),
  77. // buttonIcon: <GridDeleteIcon />,
  78. // onClick: onDeleteClick,
  79. // },
  80. ],
  81. [filteredPo]
  82. );
  83. const onReset = useCallback(() => {
  84. setFilteredPo(po);
  85. }, [po]);
  86. const [isOpenScanner, setOpenScanner] = useState(false);
  87. const onOpenScanner = useCallback(() => {
  88. setOpenScanner(true);
  89. }, []);
  90. const onCloseScanner = useCallback(() => {
  91. setOpenScanner(false);
  92. }, []);
  93. return (
  94. <>
  95. <Grid container>
  96. <Grid item xs={8}>
  97. <Typography variant="h4" marginInlineEnd={2}>
  98. {t("Purchase Order")}
  99. </Typography>
  100. </Grid>
  101. <Grid
  102. item
  103. xs={4}
  104. display="flex"
  105. justifyContent="end"
  106. alignItems="end"
  107. >
  108. <QrModal
  109. open={isOpenScanner}
  110. onClose={onCloseScanner}
  111. warehouse={warehouse}
  112. />
  113. <Button onClick={onOpenScanner}>bind</Button>
  114. </Grid>
  115. </Grid>
  116. <>
  117. <SearchBox
  118. criteria={searchCriteria}
  119. onSearch={(query) => {
  120. setFilteredPo(
  121. po.filter((p) => {
  122. return (
  123. p.code.toLowerCase().includes(query.code.toLowerCase()) &&
  124. (query.status === "All" || p.status === query.status) &&
  125. (query.escalated === "All" || p.escalated === (query.escalated === t("Escalated")))
  126. )
  127. })
  128. );
  129. }}
  130. onReset={onReset}
  131. />
  132. <SearchResults<PoResult> items={filteredPo} columns={columns} />
  133. </>
  134. </>
  135. );
  136. };
  137. export default PoSearch;