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.

feat: add ExchangeRate component for the quote header

Rob Carrington0ad9b7ea618d
diff --git a/apps/carbon/app/components/Form/ExchangeRate.tsx b/apps/carbon/app/components/Form/ExchangeRate.tsx
new file mode 100644
index 0000000000..935473ca63
--- /dev/null
+++ b/apps/carbon/app/components/Form/ExchangeRate.tsx
@@ -0,0 +1,77 @@
+import {
+ cn,
+ HStack,
+ IconButton,
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@carbon/react";
+import { useLocale } from "@react-aria/i18n";
+import React, { useMemo } from "react";
+import { LuInfo, LuRefreshCw } from "react-icons/lu";
+import { Input } from "~/components/Form";
+
+interface ExchangeRateProps extends React.ComponentProps<typeof Input> {
+ onRefresh?: () => void;
+ exchangeRateDate: string | undefined;
+}
+
+const ExchangeRate: React.FC<ExchangeRateProps> = ({
+ onRefresh,
+ exchangeRateDate,
+ ...props
+}) => {
+ const { locale } = useLocale();
+
+ const formatter = useMemo(
+ () =>
+ new Intl.DateTimeFormat(locale, {
+ dateStyle: "medium",
+ timeZone: "UTC",
+ }),
+ [locale]
+ );
+
+ const formattedDate = exchangeRateDate
+ ? formatter.format(new Date(exchangeRateDate))
+ : "";
+
+ return (
+ <div className="relative">
+ <HStack spacing={0}>
+ <Input
+ label={
+ <HStack spacing={1}>
+ <span>Exchange Rate</span>
+ {exchangeRateDate && onRefresh && (
+ <Tooltip>
+ <TooltipTrigger tabIndex={-1}>
+ <LuInfo className="w-4 h-4" />
+ </TooltipTrigger>
+ <TooltipContent>
+ Last updated on: {formattedDate}
+ </TooltipContent>
+ </Tooltip>
+ )}
+ </HStack>
+ }
+ {...props}
+ isReadOnly
+ className={cn("z-10", onRefresh ? "rounded-r-none" : "")}
+ />
+ {onRefresh && (
+ <IconButton
+ aria-label="Refresh exchange rate"
+ className="bg-transparent flex-shrink-0 h-10 rounded-l-none border-l-0 shadow-sm self-end"
+ icon={<LuRefreshCw />}
+ variant="secondary"
+ size="lg"
+ onClick={onRefresh}
+ />
+ )}
+ </HStack>
+ </div>
+ );
+};
+
+export default ExchangeRate;
diff --git a/apps/carbon/app/modules/sales/sales.models.ts b/apps/carbon/app/modules/sales/sales.models.ts
index ab5228fd5f..f9b438b268 100644
--- a/apps/carbon/app/modules/sales/sales.models.ts
+++ b/apps/carbon/app/modules/sales/sales.models.ts
@@ -117,6 +117,8 @@ export const quoteValidator = z.object({
dueDate: zfd.text(z.string().optional()),
expirationDate: zfd.text(z.string().optional()),
currencyCode: zfd.text(z.string().optional()),
+ exchangeRate: zfd.numeric(z.number().optional()),
+ exchangeRateDate: zfd.text(z.string().optional()),
});
export const quoteLineAdditionalChargesValidator = z.record(
diff --git a/apps/carbon/app/modules/sales/ui/Quotes/QuoteForm.tsx b/apps/carbon/app/modules/sales/ui/Quotes/QuoteForm.tsx
index 67eb2b6922..ad6a99ce5d 100644
--- a/apps/carbon/app/modules/sales/ui/Quotes/QuoteForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotes/QuoteForm.tsx
@@ -27,6 +27,7 @@ import {
Location,
Submit,
} from "~/components/Form";
+import ExchangeRate from "~/components/Form/ExchangeRate";
import { usePermissions } from "~/hooks";
import { quoteValidator } from "~/modules/sales";
@@ -162,6 +163,16 @@ const QuoteForm = ({ initialValues }: QuoteFormProps) => {
}
}}
/>
+ {isEditing && (
+ <ExchangeRate
+ name="exchangeRate"
+ exchangeRateDate={initialValues.exchangeRateDate}
+ isReadOnly
+ onRefresh={() => {
+ console.log("refresh");
+ }}
+ />
+ )}
<CustomFormFields table="quote" />
</div>
diff --git a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
index 63b05ad450..63dd52dba3 100644
--- a/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$quoteId.details.tsx
@@ -102,7 +102,9 @@ export default function QuoteDetailsRoute() {
quoteId: quoteData?.quote?.quoteId ?? "",
salesPersonId: quoteData?.quote?.salesPersonId ?? "",
status: quoteData?.quote?.status ?? "Draft",
- currencyCode: quoteData?.quote?.currencyCode ?? "",
+ currencyCode: quoteData?.quote?.currencyCode ?? undefined,
+ exchangeRate: quoteData?.quote?.exchangeRate ?? undefined,
+ exchangeRateDate: quoteData?.quote?.exchangeRateDate ?? "",
};
const shipmentInitialValues = {
diff --git a/apps/carbon/app/routes/x+/quote+/new.tsx b/apps/carbon/app/routes/x+/quote+/new.tsx
index 40d5bb2de5..48c2aab9fb 100644
--- a/apps/carbon/app/routes/x+/quote+/new.tsx
+++ b/apps/carbon/app/routes/x+/quote+/new.tsx
@@ -78,6 +78,8 @@ export default function QuoteNewRoute() {
quoteId: undefined,
status: "Draft" as QuotationStatusType,
currencyCode: undefined,
+ exchangeRate: undefined,
+ exchangeRateDate: "",
};
return (
diff --git a/packages/form/src/components/Input.tsx b/packages/form/src/components/Input.tsx
index 37a3a1e1dc..c50ae1043e 100644
--- a/packages/form/src/components/Input.tsx
+++ b/packages/form/src/components/Input.tsx
@@ -9,12 +9,13 @@ import {
InputLeftAddon,
InputRightAddon,
} from "@carbon/react";
+import type { ReactNode } from "react";
import { forwardRef } from "react";
import { useField } from "../hooks";
type FormInputProps = InputProps & {
name: string;
- label?: string;
+ label?: ReactNode;
isOptional?: boolean;
helperText?: string;
prefix?: string;