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.2 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 { useParams } from "react-router";
import { DetailSidebar } from "~/components/Layout";
import { useRouteData } from "~/hooks";
import type {
  SupplierContact,
  SupplierDetail,
  SupplierLocation
} from "~/modules/purchasing/types";
import { path } from "~/utils/path";
import { useSupplierSidebar } from "./useSupplierSidebar";

const SupplierSidebar = () => {
  const { supplierId } = useParams();

  if (!supplierId)
    throw new Error(
      "SupplierSidebar requires an supplierId and could not find supplierId in params"
    );

  const routeData = useRouteData<{
    supplier: SupplierDetail;
    contacts: SupplierContact[];
    locations: SupplierLocation[];
  }>(path.to.supplier(supplierId));

  const links = useSupplierSidebar({
    contacts: routeData?.contacts.length ?? 0,
    locations: routeData?.locations.length ?? 0,
    parts: routeData?.supplier?.partCount ?? 0
  });

  return <DetailSidebar links={links} />;
};

export default SupplierSidebar;