Skip to content

armgit / pdfcn

Public Imported from GitHub
0

Beautiful pdf components, built on Takumi and Forme. 100% Free, Zero config, one command setup.

16.5 KB
Raw Blame
{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "forme/work-order",
  "title": "Work Order",
  "description": "Work Order PDF block (forme)",
  "dependencies": [
    "@formepdf/react",
    "@formepdf/core"
  ],
  "registryDependencies": [
    "@pdfcn/forme/utils",
    "@pdfcn/forme/badge",
    "@pdfcn/forme/key-value",
    "@pdfcn/forme/page-footer",
    "@pdfcn/forme/page-header",
    "@pdfcn/forme/pdf-image",
    "@pdfcn/forme/section",
    "@pdfcn/forme/signature",
    "@pdfcn/forme/table",
    "@pdfcn/forme/text"
  ],
  "files": [
    {
      "path": "registry/bases/forme/blocks/work-order/work-order.tsx",
      "content": "import { Document, Page, StyleSheet, View } from \"@formepdf/react\";\n\nimport { Badge } from \"@/components/pdf/badge/badge\";\nimport type { BadgeVariant } from \"@/components/pdf/badge/badge\";\nimport { KeyValue } from \"@/components/pdf/key-value/key-value\";\nimport { PageFooter } from \"@/components/pdf/page-footer/page-footer\";\nimport { PageHeader } from \"@/components/pdf/page-header/page-header\";\nimport { PdfImage } from \"@/components/pdf/pdf-image/pdf-image\";\nimport { Section } from \"@/components/pdf/section/section\";\nimport { PdfSignatureBlock } from \"@/components/pdf/signature/signature\";\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHeader,\n  TableRow,\n} from \"@/components/pdf/table/table\";\nimport { Text } from \"@/components/pdf/text/text\";\nimport {\n  PdfcnThemeProvider,\n  usePdfcnTheme,\n} from \"@/components/pdf/theme-provider\";\nimport type { PdfcnTheme } from \"@/types/pdf-themes\";\n\nimport type { WorkOrderData, WorkOrderPriority } from \"./work-order.types\";\n\n// Sample data — replace with your own props or data source\nconst sampleData: WorkOrderData = {\n  accentColor: \"#ea580c\",\n  companyName: \"FixIt Pro Services\",\n  customer: {\n    accountNumber: \"ACC-10234\",\n    address: \"789 Elm St, Austin, TX 78701\",\n    name: \"Riverside Apartments\",\n    phone: \"(512) 555-0199\",\n  },\n  customerNotes: \"Please service before end of month lease inspection.\",\n  date: \"September 10, 2026\",\n  equipment: {\n    description: \"Commercial Dishwasher\",\n    location: \"Kitchen — Unit 4B\",\n    makeModel: \"Bosch SHP878ZD5N\",\n    serialNumber: \"BSH-2024-88712\",\n  },\n  jobType: \"Repair\",\n  labor: [\n    {\n      description: \"Diagnosis and repair\",\n      hours: 2.5,\n      rate: 95,\n      technician: \"Mike Torres\",\n    },\n  ],\n  parts: [\n    {\n      description: \"Drain Pump Assembly\",\n      partNumber: \"PUMP-001\",\n      qty: 1,\n      unitPrice: 89.99,\n    },\n    {\n      description: \"Drain Hose Kit\",\n      partNumber: \"HOSE-012\",\n      qty: 1,\n      unitPrice: 24.5,\n    },\n  ],\n  priority: \"High\",\n  taxRate: 0.0825,\n  technician: \"Mike Torres\",\n  technicianNotes:\n    \"Found clogged drain pump. Replaced pump and hose. Unit tested OK.\",\n  warrantyInfo: \"90-day warranty on parts and labor.\",\n  workOrderNumber: \"WO-2026-0452\",\n};\n\nconst PRIORITY_BADGE_VARIANT: Record<WorkOrderPriority, BadgeVariant> = {\n  High: \"warning\",\n  Low: \"default\",\n  Medium: \"info\",\n  Urgent: \"destructive\",\n};\n\nconst WorkOrderContent = ({ data }: { data: WorkOrderData }) => {\n  const theme = usePdfcnTheme();\n\n  const styles = StyleSheet.create({\n    checkbox: {\n      borderColor: theme.colors.foreground,\n      borderStyle: \"solid\",\n      borderWidth: 1,\n      height: 10,\n      width: 10,\n    },\n    checkboxRow: {\n      alignItems: \"center\",\n      flexDirection: \"row\",\n      gap: 6,\n      marginTop: theme.spacing.componentGap,\n    },\n    col: {\n      flex: 1,\n      paddingRight: 15,\n    },\n    label: {\n      fontSize: 9,\n      fontWeight: \"bold\",\n      marginBottom: 2,\n    },\n    page: {\n      backgroundColor: theme.colors.background,\n    },\n    row: {\n      flexDirection: \"row\",\n    },\n    section: {\n      marginBottom: theme.spacing.componentGap,\n    },\n    sectionSpaced: {\n      marginBottom: theme.spacing.componentGap,\n      marginTop: theme.spacing.componentGap,\n    },\n    signature: {\n      marginBottom: 0,\n      marginTop: 0,\n    },\n  });\n\n  const partsTotal = data.parts.reduce(\n    (sum, part) => sum + part.qty * part.unitPrice,\n    0\n  );\n  const laborTotal = data.labor.reduce(\n    (sum, item) => sum + item.hours * item.rate,\n    0\n  );\n  const taxRate = data.taxRate ?? 0;\n  const tax = (partsTotal + laborTotal) * taxRate;\n  const grandTotal = partsTotal + laborTotal + tax;\n\n  return (\n    <Document title={`Work Order ${data.workOrderNumber}`}>\n      <Page\n        margin={{\n          bottom: theme.spacing.page.marginBottom,\n          left: theme.spacing.page.marginLeft,\n          right: theme.spacing.page.marginRight,\n          top: theme.spacing.page.marginTop,\n        }}\n        size=\"A4\"\n      >\n        <PageFooter\n          leftText={data.warrantyInfo}\n          rightText=\"Page 1 of 1\"\n          sticky\n          pagePadding={25}\n        />\n        <View style={styles.page as never}>\n          <PageHeader\n            variant=\"logo-left\"\n            logo={\n              data.companyLogo ? (\n                <PdfImage src={data.companyLogo} style={{ margin: 0 }} />\n              ) : undefined\n            }\n            title={data.companyName}\n            subtitle=\"Work Order\"\n            rightText={`WO #${data.workOrderNumber}`}\n            rightSubText={`Date: ${data.date}`}\n            style={styles.section}\n          />\n\n          <Section\n            noWrap\n            spacing=\"none\"\n            style={{\n              ...styles.row,\n              ...styles.section,\n              alignItems: \"center\",\n              justifyContent: \"space-between\",\n            }}\n          >\n            <View\n              style={{ alignItems: \"center\", flexDirection: \"row\", gap: 8 }}\n            >\n              <Text\n                style={{ fontSize: 9, fontWeight: \"bold\" }}\n                color=\"mutedForeground\"\n                transform=\"uppercase\"\n                noMargin\n              >\n                Priority\n              </Text>\n              <Badge\n                label={data.priority}\n                variant={PRIORITY_BADGE_VARIANT[data.priority]}\n                size=\"sm\"\n              />\n            </View>\n            <Badge label={data.jobType} variant=\"outline\" size=\"sm\" />\n          </Section>\n\n          <Section\n            noWrap\n            spacing=\"none\"\n            style={{ ...styles.row, ...styles.section }}\n          >\n            <View style={styles.col}>\n              <Text\n                style={styles.label}\n                color=\"mutedForeground\"\n                transform=\"uppercase\"\n                noMargin\n              >\n                Customer\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {data.customer.name}\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {data.customer.address}\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {data.customer.phone}\n              </Text>\n              {data.customer.email ? (\n                <Text noMargin variant=\"xs\">\n                  {data.customer.email}\n                </Text>\n              ) : null}\n              {data.customer.accountNumber ? (\n                <Text noMargin variant=\"xs\">\n                  {`Acct #: ${data.customer.accountNumber}`}\n                </Text>\n              ) : null}\n            </View>\n            <View style={styles.col}>\n              <Text\n                style={styles.label}\n                color=\"mutedForeground\"\n                transform=\"uppercase\"\n                noMargin\n              >\n                Job Info\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {`Technician: ${data.technician}`}\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {`Job Type: ${data.jobType}`}\n              </Text>\n            </View>\n            <View style={styles.col}>\n              <Text\n                style={styles.label}\n                color=\"mutedForeground\"\n                transform=\"uppercase\"\n                noMargin\n              >\n                Equipment\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {data.equipment.description}\n              </Text>\n              {data.equipment.makeModel ? (\n                <Text noMargin variant=\"xs\">\n                  {data.equipment.makeModel}\n                </Text>\n              ) : null}\n              {data.equipment.serialNumber ? (\n                <Text noMargin variant=\"xs\">\n                  {`S/N: ${data.equipment.serialNumber}`}\n                </Text>\n              ) : null}\n              {data.equipment.location ? (\n                <Text noMargin variant=\"xs\">\n                  {`Location: ${data.equipment.location}`}\n                </Text>\n              ) : null}\n            </View>\n          </Section>\n\n          <Section spacing=\"none\">\n            <Text\n              style={styles.label}\n              color=\"mutedForeground\"\n              transform=\"uppercase\"\n              noMargin\n            >\n              Parts Used\n            </Text>\n            <Table variant=\"grid\" zebraStripe>\n              <TableHeader>\n                <TableRow header>\n                  <TableCell>Part #</TableCell>\n                  <TableCell>Description</TableCell>\n                  <TableCell align=\"center\">Qty</TableCell>\n                  <TableCell align=\"right\">Unit Price</TableCell>\n                  <TableCell align=\"right\">Total</TableCell>\n                </TableRow>\n              </TableHeader>\n              <TableBody>\n                {data.parts.map((part, index) => (\n                  // biome-ignore lint/suspicious/noArrayIndexKey: parts have no stable id\n                  <TableRow key={index}>\n                    <TableCell>{part.partNumber}</TableCell>\n                    <TableCell>{part.description}</TableCell>\n                    <TableCell align=\"center\">{`${part.qty}`}</TableCell>\n                    <TableCell align=\"right\">{`$${part.unitPrice.toFixed(2)}`}</TableCell>\n                    <TableCell align=\"right\">{`$${(part.qty * part.unitPrice).toFixed(2)}`}</TableCell>\n                  </TableRow>\n                ))}\n              </TableBody>\n            </Table>\n          </Section>\n\n          <Section spacing=\"none\">\n            <Text\n              style={styles.label}\n              color=\"mutedForeground\"\n              transform=\"uppercase\"\n              noMargin\n            >\n              Labor\n            </Text>\n            <Table variant=\"grid\" zebraStripe>\n              <TableHeader>\n                <TableRow header>\n                  <TableCell>Description</TableCell>\n                  <TableCell>Technician</TableCell>\n                  <TableCell align=\"center\">Hours</TableCell>\n                  <TableCell align=\"right\">Rate</TableCell>\n                  <TableCell align=\"right\">Total</TableCell>\n                </TableRow>\n              </TableHeader>\n              <TableBody>\n                {data.labor.map((item, index) => (\n                  // biome-ignore lint/suspicious/noArrayIndexKey: labor entries have no stable id\n                  <TableRow key={index}>\n                    <TableCell>{item.description}</TableCell>\n                    <TableCell>{item.technician}</TableCell>\n                    <TableCell align=\"center\">{`${item.hours}`}</TableCell>\n                    <TableCell align=\"right\">{`$${item.rate.toFixed(2)}`}</TableCell>\n                    <TableCell align=\"right\">{`$${(item.hours * item.rate).toFixed(2)}`}</TableCell>\n                  </TableRow>\n                ))}\n              </TableBody>\n            </Table>\n          </Section>\n\n          <Section\n            noWrap\n            spacing=\"none\"\n            style={{ ...styles.row, ...styles.section }}\n          >\n            <View style={{ flex: 1, paddingRight: 15 }}>\n              {data.technicianNotes ? (\n                <View>\n                  <Text\n                    style={styles.label}\n                    color=\"mutedForeground\"\n                    transform=\"uppercase\"\n                    noMargin\n                  >\n                    Technician Notes\n                  </Text>\n                  <Text noMargin variant=\"xs\">\n                    {data.technicianNotes}\n                  </Text>\n                </View>\n              ) : null}\n            </View>\n            <View style={{ marginLeft: \"auto\", width: 200 }}>\n              <KeyValue\n                size=\"sm\"\n                dividerThickness={1}\n                items={[\n                  { key: \"Parts Total\", value: `$${partsTotal.toFixed(2)}` },\n                  { key: \"Labor Total\", value: `$${laborTotal.toFixed(2)}` },\n                  {\n                    key: `Tax (${(taxRate * 100).toFixed(2)}%)`,\n                    value: `$${tax.toFixed(2)}`,\n                  },\n                  {\n                    key: \"Grand Total\",\n                    keyStyle: { fontSize: 12, fontWeight: \"bold\" },\n                    value: `$${grandTotal.toFixed(2)}`,\n                    valueStyle: { fontSize: 12, fontWeight: \"bold\" },\n                  },\n                ]}\n                divided\n              />\n            </View>\n          </Section>\n\n          {data.customerNotes ? (\n            <Section spacing=\"none\" style={styles.sectionSpaced}>\n              <Text\n                style={styles.label}\n                color=\"mutedForeground\"\n                transform=\"uppercase\"\n                noMargin\n              >\n                Customer Notes\n              </Text>\n              <Text noMargin variant=\"xs\">\n                {data.customerNotes}\n              </Text>\n            </Section>\n          ) : null}\n\n          <Section spacing=\"none\">\n            <PdfSignatureBlock\n              variant=\"double\"\n              signers={[\n                { date: data.date, label: \"Customer Signature\" },\n                {\n                  date: data.date,\n                  label: \"Technician Signature\",\n                  name: data.technician,\n                },\n              ]}\n              style={styles.signature}\n            />\n            <View style={styles.checkboxRow}>\n              <View style={styles.checkbox} />\n              <Text noMargin variant=\"xs\">\n                Customer approves work performed and charges above\n              </Text>\n            </View>\n          </Section>\n        </View>\n      </Page>\n    </Document>\n  );\n};\n\nexport const WorkOrderDocument = ({\n  theme,\n  data = sampleData,\n}: {\n  theme?: PdfcnTheme;\n  data?: WorkOrderData;\n}) => (\n  <PdfcnThemeProvider theme={theme}>\n    <WorkOrderContent data={data} />\n  </PdfcnThemeProvider>\n);\n",
      "type": "registry:block",
      "target": "components/pdf/blocks/work-order/work-order.tsx"
    },
    {
      "path": "registry/bases/forme/blocks/work-order/work-order.types.ts",
      "content": "export type WorkOrderPriority = \"Low\" | \"Medium\" | \"High\" | \"Urgent\";\n\nexport interface WorkOrderCustomer {\n  name: string;\n  address: string;\n  phone: string;\n  email?: string;\n  accountNumber?: string;\n}\n\nexport type WorkOrderJobType =\n  | \"Repair\"\n  | \"Installation\"\n  | \"Maintenance\"\n  | \"Inspection\"\n  | string;\n\nexport interface WorkOrderEquipment {\n  description: string;\n  makeModel?: string;\n  serialNumber?: string;\n  location?: string;\n}\n\nexport interface WorkOrderPart {\n  partNumber: string;\n  description: string;\n  qty: number;\n  unitPrice: number;\n}\n\nexport interface WorkOrderLabor {\n  description: string;\n  technician: string;\n  hours: number;\n  rate: number;\n}\n\nexport interface WorkOrderData {\n  companyName: string;\n  companyLogo?: string;\n  workOrderNumber: string;\n  date: string;\n  priority: WorkOrderPriority;\n  customer: WorkOrderCustomer;\n  technician: string;\n  jobType: WorkOrderJobType;\n  equipment: WorkOrderEquipment;\n  parts: WorkOrderPart[];\n  labor: WorkOrderLabor[];\n  taxRate?: number;\n  technicianNotes?: string;\n  customerNotes?: string;\n  warrantyInfo?: string;\n  accentColor?: string;\n  renderingBase?: \"takumi\" | \"forme\";\n}\n",
      "type": "registry:block",
      "target": "components/pdf/blocks/work-order/work-order.types.ts"
    }
  ],
  "type": "registry:block"
}