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.4 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 { Text, View } from "@react-pdf/renderer";
import type {
  ResolvedSection,
  SharedBlock as SharedBlockType
} from "../../template";
import { interpolateContent } from "../../template";
import { Note } from "../components";
import { hasContent } from "./resolveTerms";
import { useTw } from "./tw";

/** Extension block — doc-agnostic. Takes resolved sections + merge `vars`. */
export function SharedBlock({
  block,
  sections,
  vars
}: {
  block: SharedBlockType;
  sections: Record<string, ResolvedSection>;
  vars: Record<string, string>;
}) {
  const tw = useTw();
  const section = sections[block.sectionId];
  if (!section) return null;

  if (!hasContent(section.content)) return null;
  const content = interpolateContent(section.content, vars);
  if (!hasContent(content)) return null;

  return (
    <View style={tw("border border-gray-200 mb-4")}>
      <View style={tw("p-3")}>
        <Text style={tw("text-[9px] font-bold text-gray-600 mb-1 uppercase")}>
          {section.name}
        </Text>
        <View style={tw("text-[9px] text-gray-800")}>
          <Note content={content} />
        </View>
      </View>
    </View>
  );
}