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.

fix: correct lead time pluralization to show "1 day" instead of "1 days"

Claudefb23ce70b5c7
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
index 6c8947b716..55b6d40195 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
@@ -28,6 +28,7 @@ import {
Tr,
VStack
} from "@carbon/react";
+import { pluralize } from "@carbon/utils";
import { useEffect, useMemo, useState } from "react";
import { LuArrowLeft, LuImage, LuStar } from "react-icons/lu";
import { Form, useFetcher, useNavigation } from "react-router";
@@ -385,7 +386,7 @@ const ComparisonView = ({
minLeadTime === Infinity
? null
: minLeadTime === maxLeadTime
- ? `${minLeadTime} days`
+ ? `${minLeadTime} ${pluralize(minLeadTime, "day")}`
: `${minLeadTime}-${maxLeadTime} days`
};
});
@@ -620,7 +621,7 @@ const ComparisonView = ({
</span>
</HStack>
<span className="text-xs text-muted-foreground">
- {linePrice.leadTime ?? 0} days
+ {linePrice.leadTime ?? 0} {pluralize(linePrice.leadTime ?? 0, "day")}
</span>
</VStack>
</Td>
@@ -791,7 +792,7 @@ const LinePricingOptions = ({
<Td>{option.quantity}</Td>
<Td>{formatter.format(option.supplierUnitPrice ?? 0)}</Td>
<Td>{formatter.format(option.supplierShippingCost ?? 0)}</Td>
- <Td>{option.leadTime ?? 0} days</Td>
+ <Td>{option.leadTime ?? 0} {pluralize(option.leadTime ?? 0, "day")}</Td>
<Td>{formatter.format(option.supplierTaxAmount ?? 0)}</Td>
<Td>
{formatter.format(
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
index 34884083ac..6dc5f8c6e7 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
@@ -21,6 +21,7 @@ import {
Tr,
VStack
} from "@carbon/react";
+import { pluralize } from "@carbon/utils";
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useMemo, useState } from "react";
import { LuImage } from "react-icons/lu";
@@ -342,7 +343,7 @@ const LinePricingOptions = ({
option.supplierShippingCost ?? 0
)}
</Td>
- <Td>{option.leadTime} days</Td>
+ <Td>{option.leadTime} {pluralize(option.leadTime, "day")}</Td>
<Td>
{presentationCurrencyFormatter.format(
option.supplierTaxAmount ?? 0
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
index 4f7a717a21..c689b6643d 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteToOrderDrawer.tsx
@@ -27,7 +27,7 @@ import {
toast,
VStack
} from "@carbon/react";
-import { formatDate } from "@carbon/utils";
+import { formatDate, pluralize } from "@carbon/utils";
import type { Dispatch, SetStateAction } from "react";
import { useEffect, useMemo, useState } from "react";
import { flushSync } from "react-dom";
@@ -595,7 +595,7 @@ const LinePricingOptions = ({
convertedAdditionalChargesByQuantity[option.quantity]
)}
</Td>
- <Td>{option.leadTime} days</Td>
+ <Td>{option.leadTime} {pluralize(option.leadTime, "day")}</Td>
<Td>
{formatter.format(
(option.convertedNetExtendedPrice ?? 0) +
diff --git a/packages/documents/src/pdf/QuotePDF.tsx b/packages/documents/src/pdf/QuotePDF.tsx
index 5d69157add..8426f54761 100644
--- a/packages/documents/src/pdf/QuotePDF.tsx
+++ b/packages/documents/src/pdf/QuotePDF.tsx
@@ -1,6 +1,6 @@
import type { Database } from "@carbon/database";
import type { JSONContent } from "@carbon/react";
-import { formatCityStatePostalCode } from "@carbon/utils";
+import { formatCityStatePostalCode, pluralize } from "@carbon/utils";
import { getLocalTimeZone, today } from "@internationalized/date";
import { Image, Text, View } from "@react-pdf/renderer";
import { createTw } from "react-pdf-tailwind";
@@ -388,7 +388,7 @@ const QuotePDF = ({
`${colWidth} text-right text-gray-600 pr-3`
)}
>
- {leadTime > 0 ? `${leadTime} days` : "-"}
+ {leadTime > 0 ? `${leadTime} ${pluralize(leadTime, "day")}` : "-"}
</Text>
)}
<Text
@@ -506,7 +506,7 @@ const QuotePDF = ({
<View style={tw("flex flex-row")}>
<Text style={tw("font-bold text-gray-800")}>Max Lead Time: </Text>
<Text style={tw("text-gray-600")}>
- {maxLeadTime} {maxLeadTime === 1 ? "day" : "days"}
+ {maxLeadTime} {pluralize(maxLeadTime, "day")}
</Text>
</View>
)}
diff --git a/packages/utils/src/string.ts b/packages/utils/src/string.ts
index 07eac52dee..0b4121ca00 100644
--- a/packages/utils/src/string.ts
+++ b/packages/utils/src/string.ts
@@ -10,3 +10,18 @@ export function parseBoolean<T>(
if (normalized === "false" || normalized === "0") return false;
return defaultValue; // or throw an error if invalid
}
+
+/**
+ * Returns the singular or plural form of a word based on count.
+ * @param count - The number to check
+ * @param singular - The singular form of the word
+ * @param plural - The plural form (defaults to singular + "s")
+ * @returns The appropriate form of the word
+ */
+export function pluralize(
+ count: number,
+ singular: string,
+ plural?: string
+): string {
+ return count === 1 ? singular : (plural ?? `${singular}s`);
+}