diff --git a/src/app/(main)/pickOrder/page.tsx b/src/app/(main)/pickOrder/page.tsx new file mode 100644 index 0000000..740f99a --- /dev/null +++ b/src/app/(main)/pickOrder/page.tsx @@ -0,0 +1,36 @@ +import { PreloadPickOrder } from "@/app/api/pickOrder"; +import PickOrderSearch from "@/components/PickOrderSearch"; +import { getServerI18n } from "@/i18n"; +import { Stack, Typography } from "@mui/material"; +import { Metadata } from "next"; +import { Suspense } from "react"; + +export const metadata: Metadata = { + title: "Pick Order" +} + +const PickOrder: React.FC = async () => { + const { t } = await getServerI18n("pickOrder") + + PreloadPickOrder() + + return ( + <> + + + {t("Pick Order")} + + + }> + + + + ) +} + +export default PickOrder; \ No newline at end of file diff --git a/src/app/api/pickOrder/actions.ts b/src/app/api/pickOrder/actions.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/api/pickOrder/index.ts b/src/app/api/pickOrder/index.ts new file mode 100644 index 0000000..45ad8d6 --- /dev/null +++ b/src/app/api/pickOrder/index.ts @@ -0,0 +1,33 @@ +import "server-only"; +import { serverFetchJson } from "@/app/utils/fetchUtil"; +import { BASE_API_URL } from "@/config/api"; +import { cache } from "react"; + +interface PickOrderItemInfo { + name: string, + type: string, +} + +export interface PickOrderResult{ + id: number, + code: string, + consoCode?: string, + targetDate: string, + completeDate?: string, + type: string, + status: string, + releasedBy: string, + items?: PickOrderItemInfo[] | null, +} + +export const PreloadPickOrder = () => { + fetchPickOrders() +} + +export const fetchPickOrders = cache(async () => { + return serverFetchJson(`${BASE_API_URL}/pickOrder/list`, { + next: { + tags: ["pickOrders"] + } + }) +}) \ No newline at end of file diff --git a/src/components/InventorySearch/InventorySearch.tsx b/src/components/InventorySearch/InventorySearch.tsx index e0f3fec..b50cf20 100644 --- a/src/components/InventorySearch/InventorySearch.tsx +++ b/src/components/InventorySearch/InventorySearch.tsx @@ -113,8 +113,8 @@ const InventorySearch: React.FC = ({ { - console.log(query) - console.log(inventories) + // console.log(query) + // console.log(inventories) setFilteredInventories( inventories.filter( (i) => diff --git a/src/components/NavigationContent/NavigationContent.tsx b/src/components/NavigationContent/NavigationContent.tsx index 87c6ebd..5de05b0 100644 --- a/src/components/NavigationContent/NavigationContent.tsx +++ b/src/components/NavigationContent/NavigationContent.tsx @@ -52,7 +52,7 @@ const NavigationContent: React.FC = () => { { icon: , label: "Pick Order", - path: "", + path: "/pickOrder", }, { icon: , diff --git a/src/components/PickOrderSearch/PickOrderSearch.tsx b/src/components/PickOrderSearch/PickOrderSearch.tsx new file mode 100644 index 0000000..b825bfd --- /dev/null +++ b/src/components/PickOrderSearch/PickOrderSearch.tsx @@ -0,0 +1,108 @@ +"use client" +import { PickOrderResult } from "@/app/api/pickOrder"; +import { SearchParams } from "@/app/utils/fetchUtil"; +import { useCallback, useMemo, useState } from "react"; +import { useTranslation } from "react-i18next"; +import SearchBox, { Criterion } from "../SearchBox"; +import SearchResults, { Column } from "../SearchResults"; +import { groupBy, map, sortBy, sortedUniq, uniqBy, upperCase, upperFirst } from "lodash"; + +interface Props { + pickOrders: PickOrderResult[]; +} + +type SearchQuery = Partial> + +type SearchParamNames = keyof SearchQuery; + +const PickOrderSearch: React.FC = ({ + pickOrders, +}) => { + const { t } = useTranslation("pickOrders"); + + const [filteredPickOrders, setFilteredPickOrders] = useState(pickOrders) + + const searchCriteria: Criterion[] = useMemo(() => [ + { label: t("Code"), paramName: "code", type: "text" }, + { label: t("Target Date From"), label2: t("Target Date To"), paramName: "targetDate", type: "dateRange" }, + { + label: t("Type"), paramName: "type", type: "autocomplete", + options: sortBy( + uniqBy(pickOrders.map((po) => ({ value: po.type, label: t(upperCase(po.type)) })), "value"), + "label").map((po) => (po)) + }, + { + label: t("Status"), paramName: "status", type: "autocomplete", + options: sortBy( + uniqBy(pickOrders.map((po) => ({ value: po.status, label: t(upperFirst(po.status)) })), "value"), + "label").map((po) => (po)) + }, + // { + // label: t("Items"), paramName: "items", type: "autocomplete", multiple: true, + // options: sortBy( + // uniqBy(pickOrders.map((po) => po.items?.map((item) => ({ value: item.name, label: item.name, group: item.type }))), "value"), + // "label") + // }, + ], [t]) + + const onReset = useCallback(() => { + setFilteredPickOrders(pickOrders) + }, [pickOrders]) + + const columns = useMemo[]>(() => [ + { + name: "code", + label: t("Code"), + }, + { + name: "consoCode", + label: t("Consolidated Code"), + }, + { + name: "type", + label: t("type"), + }, + { + name: "items", + label: t("Items"), + renderCell: (params) => { + return params.items?.map((i) => i.name).join(", ") + } + }, + { + name: "releasedBy", + label: t("Released By"), + }, + { + name: "status", + label: t("Status"), + }, + ], [t]) + + return ( + <> + { + setFilteredPickOrders( + pickOrders.filter( + (po) => + po.code.toLowerCase().includes(query.code.toLowerCase()) + ) + ) + }} + onReset={onReset} + /> + items={filteredPickOrders} columns={columns} pagingController={{ + pageNum: 0, + pageSize: 0, + totalCount: 0, + }} /> + + ) +} + +export default PickOrderSearch; \ No newline at end of file diff --git a/src/components/PickOrderSearch/PickOrderSearchWrapper.tsx b/src/components/PickOrderSearch/PickOrderSearchWrapper.tsx new file mode 100644 index 0000000..0d19df7 --- /dev/null +++ b/src/components/PickOrderSearch/PickOrderSearchWrapper.tsx @@ -0,0 +1,21 @@ +import { fetchPickOrders } from "@/app/api/pickOrder"; +import GeneralLoading from "../General/GeneralLoading"; +import PickOrderSearch from "./PickOrderSearch"; + +interface SubComponents { + Loading: typeof GeneralLoading; +} + +const PickOrderSearchWrapper: React.FC & SubComponents = async () => { + const [ + pickOrders + ] = await Promise.all([ + fetchPickOrders() + ]) + + return +} + +PickOrderSearchWrapper.Loading = GeneralLoading; + +export default PickOrderSearchWrapper; \ No newline at end of file diff --git a/src/components/PickOrderSearch/index.ts b/src/components/PickOrderSearch/index.ts new file mode 100644 index 0000000..3eb7e16 --- /dev/null +++ b/src/components/PickOrderSearch/index.ts @@ -0,0 +1 @@ +export { default } from './PickOrderSearchWrapper' \ No newline at end of file