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(erp): save a slide caption when its step is submitted from the caption

Raul1c5fd3694c06
diff --git a/apps/erp/app/components/SlidesEditor.tsx b/apps/erp/app/components/SlidesEditor.tsx
index b01d0cb979..76208c21cb 100644
--- a/apps/erp/app/components/SlidesEditor.tsx
+++ b/apps/erp/app/components/SlidesEditor.tsx
@@ -20,7 +20,7 @@ import {
import { useLingui } from "@lingui/react/macro";
import type { SupabaseClient } from "@supabase/supabase-js";
import { nanoid } from "nanoid";
-import { useEffect, useMemo, useState } from "react";
+import { useEffect, useMemo, useRef, useState } from "react";
import { LuBox, LuCirclePlus, LuMapPin, LuX } from "react-icons/lu";
import type {
SlideAnnotation,
@@ -197,13 +197,38 @@ export function SlidesEditor({
const [annotatingIndex, setAnnotatingIndex] = useState<number | null>(null);
const annotating = annotatingIndex == null ? null : slides[annotatingIndex];
const models = useSlideModels(slides);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const isHidden = isDisabled && slides.length === 0;
- if (isDisabled && slides.length === 0) return null;
+ // A caption saves on blur. Submitting the surrounding form from inside a
+ // caption (⌘/Ctrl+Enter, or Enter) never blurs it, and the step form closes
+ // with the edit unsaved. So a submit first blurs a focused caption of this
+ // editor, which runs its own save.
+ useEffect(() => {
+ if (isHidden) return;
+ const form = containerRef.current?.closest("form");
+ if (!form) return;
+ const saveFocusedCaption = () => {
+ const active = document.activeElement;
+ if (
+ active instanceof HTMLInputElement &&
+ active.dataset.slideCaption !== undefined &&
+ containerRef.current?.contains(active)
+ ) {
+ active.blur();
+ }
+ };
+ form.addEventListener("submit", saveFocusedCaption);
+ return () => form.removeEventListener("submit", saveFocusedCaption);
+ }, [isHidden]);
+
+ if (isHidden) return null;
const withModels = !!modelInputRef && !!onModelFileChange;
return (
<VStack
+ ref={containerRef}
spacing={2}
className="w-full col-span-2 max-md:col-span-full border-t pt-4"
>
@@ -364,6 +389,7 @@ export function SlidesEditor({
)}
<input
type="text"
+ data-slide-caption=""
aria-label={t`Caption`}
placeholder={t`Caption`}
defaultValue={slide.caption ?? ""}