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: stop auto closing active quotes (#669)

Gaurav Bhatt467c692da9e4
diff --git a/apps/erp/app/routes/share+/quote.$id.tsx b/apps/erp/app/routes/share+/quote.$id.tsx
index 10d84b90a5..ba04aaa9ae 100644
--- a/apps/erp/app/routes/share+/quote.$id.tsx
+++ b/apps/erp/app/routes/share+/quote.$id.tsx
@@ -324,20 +324,15 @@ const LineItems = ({
const { company, quote, quoteLines, quoteLinePrices, thumbnails } =
useLoaderData<typeof loader>().data!;
- const [openItems, setOpenItems] = useState<string[]>(() =>
- Array.isArray(quoteLines) && quoteLines.length > 0
- ? quoteLines.map((line) => line.id!).filter(Boolean)
- : []
- );
- // biome-ignore lint/correctness/useExhaustiveDependencies: suppressed due to migration
- useEffect(() => {
- Object.entries(selectedLines).forEach(([lineId, line]) => {
- if (line.quantity === 0 && openItems.includes(lineId)) {
- setOpenItems((prev) => prev.filter((item) => item !== lineId));
- }
- });
- }, [selectedLines]);
-
+ const [openItems, setOpenItems] = useState<string[]>(() => {
+ if (!Array.isArray(quoteLines) || quoteLines.length === 0) {
+ return [];
+ }
+ if (["Ordered", "Partial", "Expired", "Cancelled"].includes(quote.status)) {
+ return [];
+ }
+ return quoteLines.filter((line) => !!line.id).map((line) => line.id!);
+ });
const pricingByLine = useMemo(
() =>
quoteLines?.reduce<Record<string, QuotationPrice[]>>((acc, line) => {
@@ -471,6 +466,9 @@ const LineItems = ({
locale={locale}
selectedLine={selectedLines[line.id!]}
setSelectedLines={setSelectedLines}
+ onDeselect={(lineId) =>
+ setOpenItems((prev) => prev.filter((item) => item !== lineId))
+ }
/>
</motion.div>
</motion.div>
@@ -490,6 +488,7 @@ type LinePricingOptionsProps = {
formatter: Intl.NumberFormat;
selectedLine: SelectedLine;
setSelectedLines: Dispatch<SetStateAction<Record<string, SelectedLine>>>;
+ onDeselect?: (lineId: string) => void;
};
const LinePricingOptions = ({
@@ -501,7 +500,8 @@ const LinePricingOptions = ({
locale,
formatter,
selectedLine,
- setSelectedLines
+ setSelectedLines,
+ onDeselect
}: LinePricingOptionsProps) => {
const percentFormatter = usePercentFormatter();
const { quote, salesOrderLines } = useLoaderData<typeof loader>().data!;
@@ -917,6 +917,9 @@ const LinePricingOptions = ({
...prev,
[line.id!]: deselectedLine
}));
+ if (line.id) {
+ onDeselect?.(line.id);
+ }
}}
>
<Trans>Remove</Trans>