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 due date to actions

Brad Barbind74a95c84b81
diff --git a/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx b/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
index d308902098..39288606d2 100644
--- a/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
+++ b/apps/erp/app/modules/quality/ui/Issue/IssueTask.tsx
@@ -11,16 +11,21 @@ import {
DropdownMenuTrigger,
HStack,
IconButton,
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
Progress,
toast,
useDebounce,
useDisclosure,
} from "@carbon/react";
+import { formatDate } from "@carbon/utils";
import { Editor, generateHTML } from "@carbon/react/Editor";
import { useFetchers, useParams, useSubmit } from "@remix-run/react";
import { nanoid } from "nanoid";
import { useCallback, useRef, useState } from "react";
import {
+ LuCalendar,
LuChevronRight,
LuCircleCheck,
LuCirclePlay,
@@ -189,6 +194,12 @@ export function TaskItem({
value={task.assignee ?? undefined}
disabled={isDisabled}
/>
+ {type === "action" && (
+ <TaskDueDate
+ task={task as IssueActionTask}
+ isDisabled={isDisabled}
+ />
+ )}
</HStack>
<HStack>
<Button
@@ -404,3 +415,78 @@ function getTable(type: "investigation" | "action" | "approval" | "review") {
return "nonConformanceReviewer";
}
}
+
+function TaskDueDate({
+ task,
+ isDisabled,
+}: {
+ task: IssueActionTask;
+ isDisabled: boolean;
+}) {
+ const submit = useSubmit();
+ const [isOpen, setIsOpen] = useState(false);
+ const permissions = usePermissions();
+
+ const canEdit = permissions.can("update", "quality") && !isDisabled;
+
+ const handleDateChange = (date: string | null) => {
+ submit(
+ {
+ id: task.id!,
+ dueDate: date || "",
+ },
+ {
+ method: "post",
+ action: path.to.issueActionDueDate(task.id!),
+ navigate: false,
+ }
+ );
+ setIsOpen(false);
+ };
+
+ if (!canEdit) {
+ return (
+ <HStack className="text-sm text-muted-foreground">
+ <LuCalendar className="w-4 h-4" />
+ <span>{task.dueDate ? formatDate(task.dueDate) : "No due date"}</span>
+ </HStack>
+ );
+ }
+
+ return (
+ <Popover open={isOpen} onOpenChange={setIsOpen}>
+ <PopoverTrigger asChild>
+ <Button
+ variant="ghost"
+ size="sm"
+ className="h-auto px-2 py-1 text-sm text-muted-foreground hover:text-foreground"
+ >
+ <LuCalendar className="w-4 h-4 mr-1" />
+ <span>
+ {task.dueDate ? formatDate(task.dueDate) : "Set due date"}
+ </span>
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent className="w-auto p-3" align="start">
+ <div className="space-y-2">
+ <input
+ type="date"
+ value={task.dueDate || ""}
+ onChange={(e) => handleDateChange(e.target.value || null)}
+ className="w-full px-3 py-2 border rounded-md text-sm"
+ />
+ {task.dueDate && (
+ <Button
+ variant="ghost"
+ size="sm"
+ onClick={() => handleDateChange(null)}
+ className="w-full"
+ >
+ Clear due date
+ </Button>
+ )}
+ </div>
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/apps/erp/app/routes/x+/issue+/action.$id.due-date.tsx b/apps/erp/app/routes/x+/issue+/action.$id.due-date.tsx
new file mode 100644
index 0000000000..18b248e726
--- /dev/null
+++ b/apps/erp/app/routes/x+/issue+/action.$id.due-date.tsx
@@ -0,0 +1,35 @@
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@remix-run/node";
+import { z } from "zod";
+import { zfd } from "zod-form-data";
+
+const updateDueDateSchema = zfd.formData({
+ id: z.string(),
+ dueDate: z.string().optional(),
+});
+
+export async function action({ request }: ActionFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ update: "quality",
+ });
+
+ const formData = await request.formData();
+ const validated = await validator(updateDueDateSchema).validate(formData);
+ if (validated.error) {
+ return json({ error: "Invalid form data" }, { status: 400 });
+ }
+
+ const { error } = await client
+ .from("nonConformanceActionTask")
+ .update({
+ dueDate: validated.data.dueDate || null,
+ })
+ .eq("id", validated.data.id);
+
+ if (error) {
+ return json({ error: error.message }, { status: 400 });
+ }
+
+ return json({ success: true });
+}
diff --git a/apps/erp/app/utils/path.ts b/apps/erp/app/utils/path.ts
index 3cba623416..6ffaedd44e 100644
--- a/apps/erp/app/utils/path.ts
+++ b/apps/erp/app/utils/path.ts
@@ -688,6 +688,8 @@ export const path = {
issueActions: (id: string) => generatePath(`${x}/issue/${id}/actions`),
issueTaskStatus: (id: string) =>
generatePath(`${x}/issue/task/${id}/status`),
+ issueActionDueDate: (id: string) =>
+ generatePath(`${x}/issue/action/${id}/due-date`),
issueReview: (id: string) => generatePath(`${x}/issue/${id}/review`),
issueWorkflow: (id: string) => generatePath(`${x}/issue-workflow/${id}`),
issueWorkflows: `${x}/quality/issue-workflows`,