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.

refactor: fix inline modals closing before data refetched (#111)

Brad Barbine553713ae8fe
diff --git a/apps/carbon/app/components/Breadcrumb.tsx b/apps/carbon/app/components/Breadcrumb.tsx
index 039b34bb61..c5714fd42e 100644
--- a/apps/carbon/app/components/Breadcrumb.tsx
+++ b/apps/carbon/app/components/Breadcrumb.tsx
@@ -46,7 +46,7 @@ const BreadcrumbItem = forwardRef<
{...props}
>
{!isFirstChild && (
- <LuChevronRight className="text-muted-foreground h-3 w-3" />
+ <LuChevronRight className="text-muted-foreground h-4 w-4" />
)}
{children}
</li>
diff --git a/apps/carbon/app/components/Layout/Topbar/Breadcrumbs.tsx b/apps/carbon/app/components/Layout/Topbar/Breadcrumbs.tsx
index e7ebbfc4b8..c8f80087e0 100644
--- a/apps/carbon/app/components/Layout/Topbar/Breadcrumbs.tsx
+++ b/apps/carbon/app/components/Layout/Topbar/Breadcrumbs.tsx
@@ -33,7 +33,7 @@ const Breadcrumbs = () => {
.filter(Boolean);
return (
- <HStack className="items-center h-full" spacing={0}>
+ <HStack className="items-center h-full -ml-2" spacing={0}>
<BreadcrumbsBase className="line-clamp-1">
{breadcrumbs.map((breadcrumb, i) => (
<BreadcrumbItem key={i}>
diff --git a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
index 874c1b4d0e..67e8328a5a 100644
--- a/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/Part/PartForm.tsx
@@ -8,10 +8,12 @@ import {
ModalCardProvider,
ModalCardTitle,
cn,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
-import { useState } from "react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect, useState } from "react";
import type { z } from "zod";
import {
Boolean,
@@ -86,7 +88,19 @@ const useNextPartIdShortcut = () => {
};
const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created part`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create part: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
+
const { partId, onPartIdChange, loading } = useNextPartIdShortcut();
const permissions = usePermissions();
const isEditing = !!initialValues.id;
@@ -112,7 +126,6 @@ const PartForm = ({ initialValues, type = "card", onClose }: PartFormProps) => {
method="post"
validator={partValidator}
defaultValues={initialValues}
- onSubmit={onClose}
fetcher={fetcher}
>
<ModalCardHeader>
diff --git a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx
index b4e79fe0aa..7640577466 100644
--- a/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/PartGroups/PartGroupForm.tsx
@@ -65,11 +65,6 @@ const PartGroupForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasureForm.tsx b/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasureForm.tsx
index c6e18c9632..2e2cd59fe2 100644
--- a/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasureForm.tsx
+++ b/apps/carbon/app/modules/parts/ui/UnitOfMeasure/UnitOfMeasureForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -32,7 +35,20 @@ const UnitOfMeasureForm = ({
onClose,
}: UnitOfMeasureFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created unit of measure`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create unit of measure: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -55,11 +71,6 @@ const UnitOfMeasureForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/purchasing/purchasing.service.ts b/apps/carbon/app/modules/purchasing/purchasing.service.ts
index 2769dd68a6..33c39f056f 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.service.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.service.ts
@@ -935,7 +935,11 @@ export async function upsertSupplierStatus(
})
) {
if ("createdBy" in supplierStatus) {
- return client.from("supplierStatus").insert([supplierStatus]);
+ return client
+ .from("supplierStatus")
+ .insert([supplierStatus])
+ .select("id")
+ .single();
} else {
return client
.from("supplierStatus")
@@ -958,7 +962,11 @@ export async function upsertSupplierType(
})
) {
if ("createdBy" in supplierType) {
- return client.from("supplierType").insert([supplierType]);
+ return client
+ .from("supplierType")
+ .insert([supplierType])
+ .select("id")
+ .single();
} else {
return client
.from("supplierType")
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContactForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContactForm.tsx
index 0132660766..735238720b 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContactForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierContactForm.tsx
@@ -8,9 +8,12 @@ import {
DrawerTitle,
HStack,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
CustomFormFields,
@@ -40,7 +43,20 @@ const SupplierContactForm = ({
type = "drawer",
onClose,
}: SupplierContactFormProps) => {
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created supplier contact`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create supplier contact: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const permissions = usePermissions();
const isEditing = !!initialValues?.id;
@@ -67,11 +83,6 @@ const SupplierContactForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose?.();
- }
- }}
>
<DrawerHeader>
<DrawerTitle>{isEditing ? "Edit" : "New"} Contact</DrawerTitle>
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 65d63bf722..b7d884e496 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -9,9 +9,12 @@ import {
ModalCardProvider,
ModalCardTitle,
cn,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
CustomFormFields,
@@ -23,6 +26,7 @@ import {
SupplierType,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
+import type { Supplier } from "~/modules/purchasing";
import { supplierValidator } from "~/modules/purchasing";
import { path } from "~/utils/path";
@@ -38,7 +42,19 @@ const SupplierForm = ({
onClose,
}: SupplierFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<Supplier>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ // @ts-ignore
+ toast.success(`Created supplier: ${fetcher.data.data.name}`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create supplier: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -54,7 +70,6 @@ const SupplierForm = ({
action={isEditing ? undefined : path.to.newSupplier}
validator={supplierValidator}
defaultValues={initialValues}
- onSubmit={onClose}
fetcher={fetcher}
>
<ModalCardHeader>
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx
index 7997d70c0f..bd4f132d98 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocationForm.tsx
@@ -8,10 +8,13 @@ import {
DrawerTitle,
HStack,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -33,7 +36,20 @@ const SupplierLocationForm = ({
type = "drawer",
onClose,
}: SupplierLocationFormProps) => {
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created supplier location`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create supplier location: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const permissions = usePermissions();
const isEditing = !!initialValues?.id;
@@ -59,11 +75,6 @@ const SupplierLocationForm = ({
}
defaultValues={initialValues}
fetcher={fetcher}
- onSubmit={() => {
- if (type === "modal") {
- onClose?.();
- }
- }}
className="flex flex-col h-full"
>
<DrawerHeader>
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierStatuses/SupplierStatusForm.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierStatuses/SupplierStatusForm.tsx
index b574b88377..3ba2cbb33c 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierStatuses/SupplierStatusForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierStatuses/SupplierStatusForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -32,7 +35,20 @@ const SupplierStatusForm = ({
onClose,
}: SupplierStatusFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created supplier status`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create supplier status: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -59,11 +75,6 @@ const SupplierStatusForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
index 01ee723e09..a6a93206ac 100644
--- a/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/SupplierTypes/SupplierTypeForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -32,7 +35,20 @@ const SupplierTypeForm = ({
onClose,
}: SupplierTypeFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created supplier type`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create supplier type: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -59,11 +75,6 @@ const SupplierTypeForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
index 669048fbd3..c46ea0c2d0 100644
--- a/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Departments/DepartmentForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
CustomFormFields,
@@ -38,7 +41,18 @@ const DepartmentForm = ({
onClose,
}: DepartmentFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created location`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create location: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -65,11 +79,6 @@ const DepartmentForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx
index 18ec1d90d8..c722d04c3f 100644
--- a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentTypeForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
Ability,
@@ -40,7 +43,18 @@ const EquipmentTypeForm = ({
onClose,
}: EquipmentTypeFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created location`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create location: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -67,11 +81,6 @@ const EquipmentTypeForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/resources/ui/Locations/LocationForm.tsx b/apps/carbon/app/modules/resources/ui/Locations/LocationForm.tsx
index 33485d55c6..49384fff6a 100644
--- a/apps/carbon/app/modules/resources/ui/Locations/LocationForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Locations/LocationForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
CustomFormFields,
@@ -38,7 +41,18 @@ const LocationForm = ({
onClose,
}: LocationFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created location`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create location: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -65,11 +79,6 @@ const LocationForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
index 5842535f28..d738a4eee0 100644
--- a/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/WorkCells/WorkCellTypeForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
Ability,
@@ -41,7 +44,20 @@ const WorkCellTypeForm = ({
onClose,
}: WorkCellTypeFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created work cell type`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create work cell type: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -68,11 +84,6 @@ const WorkCellTypeForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index f676525504..7e0fb6ecc9 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -698,7 +698,7 @@ export async function upsertCustomerStatus(
})
) {
if ("createdBy" in customerStatus) {
- return client.from("customerStatus").insert([customerStatus]);
+ return client.from("customerStatus").insert([customerStatus]).select("id");
} else {
return client
.from("customerStatus")
@@ -721,7 +721,7 @@ export async function upsertCustomerType(
})
) {
if ("createdBy" in customerType) {
- return client.from("customerType").insert([customerType]);
+ return client.from("customerType").insert([customerType]).select("id");
} else {
return client
.from("customerType")
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
index 9b65833c96..7da783292f 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerForm.tsx
@@ -9,9 +9,12 @@ import {
ModalCardProvider,
ModalCardTitle,
cn,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import {
CustomFormFields,
@@ -23,6 +26,7 @@ import {
Submit,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
+import type { Customer } from "~/modules/sales";
import { customerValidator } from "~/modules/sales";
import { path } from "~/utils/path";
@@ -38,7 +42,19 @@ const CustomerForm = ({
onClose,
}: CustomerFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<Customer>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ // @ts-ignore
+ toast.success(`Created customer: ${fetcher.data.data.name}`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(`Failed to create customer: ${fetcher.data.error.message}`);
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -54,7 +70,6 @@ const CustomerForm = ({
action={isEditing ? undefined : path.to.newCustomer}
validator={customerValidator}
defaultValues={initialValues}
- onSubmit={onClose}
fetcher={fetcher}
>
<ModalCardHeader>
diff --git a/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusForm.tsx b/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusForm.tsx
index 603cc2e711..662117c938 100644
--- a/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/CustomerStatuses/CustomerStatusForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -32,7 +35,20 @@ const CustomerStatusForm = ({
onClose,
}: CustomerStatusFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created customer status`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create customer status: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -59,11 +75,6 @@ const CustomerStatusForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypeForm.tsx b/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypeForm.tsx
index cd0e8b941e..0242a307d3 100644
--- a/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypeForm.tsx
+++ b/apps/carbon/app/modules/sales/ui/CustomerTypes/CustomerTypeForm.tsx
@@ -9,9 +9,12 @@ import {
ModalDrawerProvider,
ModalDrawerTitle,
VStack,
+ toast,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
import { useFetcher } from "@remix-run/react";
+import type { PostgrestResponse } from "@supabase/supabase-js";
+import { useEffect } from "react";
import type { z } from "zod";
import { CustomFormFields, Hidden, Input, Submit } from "~/components/Form";
import { usePermissions } from "~/hooks";
@@ -32,7 +35,20 @@ const CustomerTypeForm = ({
onClose,
}: CustomerTypeFormProps) => {
const permissions = usePermissions();
- const fetcher = useFetcher();
+ const fetcher = useFetcher<PostgrestResponse<{ id: string }>>();
+
+ useEffect(() => {
+ if (type !== "modal") return;
+
+ if (fetcher.state === "loading" && fetcher.data?.data) {
+ onClose?.();
+ toast.success(`Created customer type`);
+ } else if (fetcher.state === "idle" && fetcher.data?.error) {
+ toast.error(
+ `Failed to create customer type: ${fetcher.data.error.message}`
+ );
+ }
+ }, [fetcher.data, fetcher.state, onClose, type]);
const isEditing = initialValues.id !== undefined;
const isDisabled = isEditing
@@ -59,11 +75,6 @@ const CustomerTypeForm = ({
defaultValues={initialValues}
fetcher={fetcher}
className="flex flex-col h-full"
- onSubmit={() => {
- if (type === "modal") {
- onClose();
- }
- }}
>
<ModalDrawerHeader>
<ModalDrawerTitle>
diff --git a/apps/carbon/app/modules/sales/ui/Quotation/QuotationExplorer.tsx b/apps/carbon/app/modules/sales/ui/Quotation/QuotationExplorer.tsx
index 910950eeef..cc18f37201 100644
--- a/apps/carbon/app/modules/sales/ui/Quotation/QuotationExplorer.tsx
+++ b/apps/carbon/app/modules/sales/ui/Quotation/QuotationExplorer.tsx
@@ -511,6 +511,14 @@ const QuotationExplorer = () => {
};
const newButtonRef = useRef<HTMLButtonElement>(null);
+ useKeyboardShortcuts({
+ l: () => {
+ if (newButtonRef.current) {
+ newButtonRef.current.click();
+ }
+ },
+ });
+
const navigate = useNavigate();
const { id } = useParams();
if (!id) throw new Error("id not found");
diff --git a/apps/carbon/app/routes/api+/assign.ts b/apps/carbon/app/routes/api+/assign.ts
index d34bd98fbe..4e54df01c1 100644
--- a/apps/carbon/app/routes/api+/assign.ts
+++ b/apps/carbon/app/routes/api+/assign.ts
@@ -12,8 +12,11 @@ export async function action({ request }: ActionFunctionArgs) {
const assignee = formData.get("assignee") as string;
const table = formData.get("table") as string;
+ console.log({ id, assignee, table });
+
if (table && id) {
const result = await assign(client, { table, id, assignee });
+ console.log({ result });
if (result.error) {
return json(
{ success: false },
diff --git a/apps/carbon/app/routes/x+/_index.tsx b/apps/carbon/app/routes/x+/_index.tsx
index b07344decb..f350d54116 100644
--- a/apps/carbon/app/routes/x+/_index.tsx
+++ b/apps/carbon/app/routes/x+/_index.tsx
@@ -1,7 +1,8 @@
-import { Heading } from "@carbon/react";
+import { Heading, cn } from "@carbon/react";
import { formatDate } from "@carbon/utils";
import { getLocalTimeZone, today } from "@internationalized/date";
import { Link } from "@remix-run/react";
+import type { ComponentProps } from "react";
import { useModules } from "~/components/Layout/Navigation/useModules";
import { useUser } from "~/hooks";
import type { Authenticated, NavItem } from "~/types";
@@ -12,13 +13,13 @@ export default function AppIndexRoute() {
return (
<div className="p-8 w-full">
<Heading size="h3">Hello, {user.firstName}</Heading>
- <p className="text-muted-foreground text-base font-light">
+ <Subheading>
{formatDate(today(getLocalTimeZone()).toString(), {
dateStyle: "full",
})}
- </p>
+ </Subheading>
<Hr />
- <p className="text-muted-foreground text-base font-light mb-8">Modules</p>
+ <Subheading className="mb-8">Modules</Subheading>
<div className="grid grid-cols-1 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-6">
{modules.map((module) => (
<ModuleCard key={module.name} module={module} />
@@ -32,6 +33,12 @@ const Hr = () => (
<hr className="h-px my-8 bg-black/10 border-0 dark:bg-white/10" />
);
+const Subheading = ({ children, className }: ComponentProps<"p">) => (
+ <p className={cn("text-muted-foreground text-base font-light", className)}>
+ {children}
+ </p>
+);
+
const ModuleCard = ({ module }: { module: Authenticated<NavItem> }) => (
<Link
to={module.to}
diff --git a/apps/carbon/app/routes/x+/account+/theme.tsx b/apps/carbon/app/routes/x+/account+/theme.tsx
index 3feef96a21..54c33fb6b0 100644
--- a/apps/carbon/app/routes/x+/account+/theme.tsx
+++ b/apps/carbon/app/routes/x+/account+/theme.tsx
@@ -1,4 +1,3 @@
-import { VStack } from "@carbon/react";
import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
@@ -47,10 +46,5 @@ export default function Theme() {
theme,
};
- return (
- <VStack spacing={0} className="p-4 h-full">
- {/* @ts-ignore */}
- <ThemeForm theme={initialValues} />
- </VStack>
- );
+ return <ThemeForm theme={initialValues} />;
}
diff --git a/apps/carbon/app/routes/x+/quote+/$id.tsx b/apps/carbon/app/routes/x+/quote+/$id.tsx
index f02bea605f..223cbbe3ee 100644
--- a/apps/carbon/app/routes/x+/quote+/$id.tsx
+++ b/apps/carbon/app/routes/x+/quote+/$id.tsx
@@ -48,6 +48,7 @@ export const handle: Handle = {
to: path.to.quotes,
};
+// TODO: remove this
export const shouldRevalidate: ShouldRevalidateFunction = ({
currentUrl,
currentParams,
@@ -177,25 +178,22 @@ export default function QuotationRoute() {
return (
<div className="grid grid-cols-[auto_1fr] w-full">
- <CollapsibleSidebar width={260}>
- <VStack className="border-b border-border p-2" spacing={1}>
- <Heading size="h3" noOfLines={1}>
- {quote.quote?.quoteId}
- </Heading>
- </VStack>
- <VStack className="border-b border-border p-2 text-sm">
+ <CollapsibleSidebar width={280}>
+ <VStack className="border-b border-border px-4 py-2" spacing={1}>
<HStack className="justify-between w-full">
- <span className="text-xs text-muted-foreground">Status</span>
+ <Heading size="h4" noOfLines={1}>
+ {quote.quote?.quoteId}
+ </Heading>
{quote.quote && <QuotationStatus status={quote.quote?.status} />}
</HStack>
</VStack>
- <VStack className="border-b border-border p-2 text-sm">
+ <VStack className="border-b border-border px-4 py-2 text-sm">
<HStack className="justify-between w-full">
<span className="text-xs text-muted-foreground">Customer</span>
<CustomerAvatar customerId={customer.id} />
</HStack>
</VStack>
- <VStack className="border-b border-border p-2 text-sm">
+ <VStack className="border-b border-border px-4 py-2 text-sm">
<HStack className="justify-between w-full">
<span className="text-xs text-muted-foreground">Assignee</span>
{assignee && <EmployeeAvatar employeeId={assignee} />}
@@ -204,7 +202,7 @@ export default function QuotationRoute() {
<QuotationExplorer />
</CollapsibleSidebar>
- <VStack className="p-2">
+ <VStack className="px-4 py-2">
<Menubar>
<Assign id={id} table="quote" value={assignee ?? undefined} />
<MenubarItem asChild>
diff --git a/apps/carbon/app/routes/x+/resources+/locations.new.tsx b/apps/carbon/app/routes/x+/resources+/locations.new.tsx
index bcad6fafc6..2124222877 100644
--- a/apps/carbon/app/routes/x+/resources+/locations.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/locations.new.tsx
@@ -51,7 +51,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return modal
- ? json(createLocation, { status: 201 })
+ ? json(createLocation)
: redirect(
path.to.locations,
await flash(request, success("Location created"))
diff --git a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
index 68e3d5c768..25508a3c16 100644
--- a/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-cells.new.tsx
@@ -48,9 +48,7 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
- return modal
- ? json(createWorkCellType, { status: 201 })
- : redirect(path.to.workCells);
+ return modal ? json(createWorkCellType) : redirect(path.to.workCells);
}
export default function NewWorkCellTypeRoute() {
diff --git a/apps/carbon/app/routes/x+/sales+/customer-statuses.new.tsx b/apps/carbon/app/routes/x+/sales+/customer-statuses.new.tsx
index 4195526391..46db01b3f8 100644
--- a/apps/carbon/app/routes/x+/sales+/customer-statuses.new.tsx
+++ b/apps/carbon/app/routes/x+/sales+/customer-statuses.new.tsx
@@ -63,7 +63,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return modal
- ? json(insertCustomerStatus, { status: 201 })
+ ? json(insertCustomerStatus)
: redirect(
`${path.to.customerStatuses}?${getParams(request)}`,
await flash(request, success("Customer status created"))
diff --git a/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx b/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx
index a1046b9a92..bcde42c9ad 100644
--- a/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx
+++ b/apps/carbon/app/routes/x+/sales+/customer-types.new.tsx
@@ -57,7 +57,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
return modal
- ? json(insertCustomerType, { status: 201 })
+ ? json(insertCustomerType)
: redirect(
`${path.to.customerTypes}?${getParams(request)}`,
await flash(request, success("Customer type created"))
diff --git a/apps/carbon/app/routes/x+/supplier+/new.tsx b/apps/carbon/app/routes/x+/supplier+/new.tsx
index 9e07917211..fd85bc8290 100644
--- a/apps/carbon/app/routes/x+/supplier+/new.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/new.tsx
@@ -55,9 +55,7 @@ export async function action({ request }: ActionFunctionArgs) {
const supplierId = createSupplier.data?.id;
- return modal
- ? json(createSupplier, { status: 201 })
- : redirect(path.to.supplier(supplierId));
+ return modal ? json(createSupplier) : redirect(path.to.supplier(supplierId));
}
export default function SuppliersNewRoute() {
diff --git a/apps/carbon/app/services/theme.server.ts b/apps/carbon/app/services/theme.server.ts
index 7b2a112576..6e24b6f0dc 100644
--- a/apps/carbon/app/services/theme.server.ts
+++ b/apps/carbon/app/services/theme.server.ts
@@ -10,7 +10,7 @@ const themes = [
"blue",
"yellow",
"orange",
- "purple",
+ "violet",
] as const;
type Theme = (typeof themes)[number];
diff --git a/packages/react/src/Drawer.tsx b/packages/react/src/Drawer.tsx
index dcbd6e77a8..6e93cb3ee1 100644
--- a/packages/react/src/Drawer.tsx
+++ b/packages/react/src/Drawer.tsx
@@ -72,7 +72,7 @@ const DrawerBody = ({
DrawerBody.displayName = "DrawerBody";
const sheetVariants = cva(
- "fixed flex flex-col z-50 scale-100 bg-card opacity-100 shadow-lg border border-border overflow-y-auto transition-all duration-100",
+ "fixed flex flex-col z-50 scale-100 bg-card opacity-100 shadow-lg border border-border overflow-y-auto transition-all duration-100 focus-visible:outline-none focus-visible:ring-0",
{
variants: {
position: {
diff --git a/packages/react/src/Modal.tsx b/packages/react/src/Modal.tsx
index e7142e8822..fa5340628f 100644
--- a/packages/react/src/Modal.tsx
+++ b/packages/react/src/Modal.tsx
@@ -48,7 +48,7 @@ const ModalContentVariants = cva(
"data-[state=closed]:slide-out-to-left-[0%] data-[state=closed]:slide-out-to-top-[0%",
"data-[state=open]:slide-in-from-left-[0%] data-[state=open]:slide-in-from-top-[0%]",
"sm:rounded-lg md:w-full",
- "bg-background"
+ "bg-background focus-visible:outline-none focus-visible:ring-0"
),
{
variants: {