Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

1.6 KB
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

import type { JSONContent } from "@carbon/react";
import { useParams } from "react-router";
import { useRouteData } from "~/hooks";
import type {
  getPickingList,
  getPickingListLines,
  PickingListRecommendation
} from "~/modules/inventory/inventory.service";
import {
  PickingListLines,
  PickingListNotes
} from "~/modules/inventory/ui/PickingLists";
import { path } from "~/utils/path";

type PickingListData = NonNullable<
  Awaited<ReturnType<typeof getPickingList>>["data"]
>;

type PickingListLineData = NonNullable<
  Awaited<ReturnType<typeof getPickingListLines>>["data"]
>;

export default function PickingListDetailsRoute() {
  const { pickingListId } = useParams();
  if (!pickingListId) throw new Error("Could not find pickingListId");

  const routeData = useRouteData<{
    pickingList: PickingListData;
    pickingListLines: PickingListLineData;
    recommendations: Promise<Record<string, PickingListRecommendation[]>>;
  }>(path.to.pickingList(pickingListId));

  if (!routeData?.pickingList)
    throw new Error("Could not find picking list in routeData");

  return (
    <>
      <PickingListLines
        pickingListLines={routeData.pickingListLines}
        pickingListId={pickingListId}
        pickingList={routeData.pickingList}
        recommendations={routeData.recommendations}
      />
      <PickingListNotes
        id={pickingListId}
        notes={(routeData.pickingList.notes ?? {}) as JSONContent}
      />
    </>
  );
}