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: use optional chaining for window.queryClient

Brad Barbinae0630f8fb9d
diff --git a/apps/carbon/app/routes/api+/resources.work-centers.tsx b/apps/carbon/app/routes/api+/resources.work-centers.tsx
index 1ecb714452..0dd534db91 100644
--- a/apps/carbon/app/routes/api+/resources.work-centers.tsx
+++ b/apps/carbon/app/routes/api+/resources.work-centers.tsx
@@ -1,10 +1,33 @@
import { requirePermissions } from "@carbon/auth/auth.server";
-import type { LoaderFunctionArgs } from "@vercel/remix";
+import type { ClientLoaderFunctionArgs } from "@remix-run/react";
+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";
import { json } from "@vercel/remix";
import { getWorkCentersList } from "~/modules/resources";
+import { getCompanyId, workCentersQuery } from "~/utils/react-query";
export async function loader({ request }: LoaderFunctionArgs) {
const { client, companyId } = await requirePermissions(request, {});
return json(await getWorkCentersList(client, companyId));
}
+
+export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {
+ const companyId = getCompanyId();
+
+ if (!companyId) {
+ return await serverLoader<typeof loader>();
+ }
+
+ const queryKey = workCentersQuery(companyId).queryKey;
+ const data =
+ window?.queryClient?.getQueryData<SerializeFrom<typeof loader>>(queryKey);
+
+ if (!data) {
+ const serverData = await serverLoader<typeof loader>();
+ window?.queryClient?.setQueryData(queryKey, serverData);
+ return serverData;
+ }
+
+ return data;
+}
+clientLoader.hydrate = true;
diff --git a/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx b/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx
index 3081b9348b..8602930022 100644
--- a/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx
@@ -74,7 +74,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(currenciesQuery().queryKey, null);
+ window.queryClient?.setQueryData(currenciesQuery().queryKey, null);
return await serverAction();
}
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
index 0cbaaa46de..6832e4d96e 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx
@@ -73,7 +73,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
paymentTermsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
index c53d4a45c1..16c9744cf1 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.delete.$paymentTermId.tsx
@@ -65,7 +65,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
paymentTermsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx
index 0a4a05ebd6..4e49c3044f 100644
--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx
+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx
@@ -66,7 +66,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
paymentTermsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
index 86d5a24bc8..37d3b1e9ce 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
@@ -103,7 +103,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerContactsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.delete.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.delete.$customerContactId.tsx
index 42be4a4b28..ddaba96ebe 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.delete.$customerContactId.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.delete.$customerContactId.tsx
@@ -50,7 +50,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerContactsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
index 5f57e029d8..6fb62fd34c 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
@@ -83,7 +83,7 @@ export async function clientAction({
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerContactsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx
index ddf06a2556..5f18826e16 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx
@@ -99,7 +99,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerLocationsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.delete.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.delete.$customerLocationId.tsx
index 0d4e547e2f..0a98f42370 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.delete.$customerLocationId.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.delete.$customerLocationId.tsx
@@ -53,7 +53,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerLocationsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx
index 8dbed8e1e3..bd0f1ed5ae 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx
@@ -74,7 +74,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { customerId } = params;
if (customerId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
customerLocationsQuery(customerId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/inventory+/shipping-methods.$shippingMethodId.tsx b/apps/carbon/app/routes/x+/inventory+/shipping-methods.$shippingMethodId.tsx
index 8036dd8ea3..212e3ef4e2 100644
--- a/apps/carbon/app/routes/x+/inventory+/shipping-methods.$shippingMethodId.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/shipping-methods.$shippingMethodId.tsx
@@ -75,7 +75,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
shippingMethodsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/inventory+/shipping-methods.delete.$shippingMethodId.tsx b/apps/carbon/app/routes/x+/inventory+/shipping-methods.delete.$shippingMethodId.tsx
index ffdbb5e366..bc92c02fc5 100644
--- a/apps/carbon/app/routes/x+/inventory+/shipping-methods.delete.$shippingMethodId.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/shipping-methods.delete.$shippingMethodId.tsx
@@ -65,7 +65,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
shippingMethodsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/inventory+/shipping-methods.new.tsx b/apps/carbon/app/routes/x+/inventory+/shipping-methods.new.tsx
index d8d77042cb..ab7333af9f 100644
--- a/apps/carbon/app/routes/x+/inventory+/shipping-methods.new.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/shipping-methods.new.tsx
@@ -68,7 +68,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
shippingMethodsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx b/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx
index cb47c21436..735c9df3d5 100644
--- a/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx
+++ b/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx
@@ -72,7 +72,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(uomsQuery(getCompanyId()).queryKey, null);
+ window.queryClient?.setQueryData(uomsQuery(getCompanyId()).queryKey, null);
return await serverAction();
}
diff --git a/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx b/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx
index bc2858f889..1934e571ac 100644
--- a/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx
+++ b/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx
@@ -63,7 +63,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(uomsQuery(getCompanyId()).queryKey, null);
+ window.queryClient?.setQueryData(uomsQuery(getCompanyId()).queryKey, null);
return await serverAction();
}
diff --git a/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx b/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx
index 800b362463..80acde4cea 100644
--- a/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx
@@ -63,7 +63,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
abilitiesQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx b/apps/carbon/app/routes/x+/resources+/abilities.new.tsx
index 6ee0345036..8846bff6ec 100644
--- a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/abilities.new.tsx
@@ -111,7 +111,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
abilitiesQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
index 0c021401af..74472442fe 100644
--- a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
@@ -137,7 +137,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
abilitiesQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx b/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx
index 9374c72ba4..579babae6a 100644
--- a/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx
@@ -79,7 +79,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
locationsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx b/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx
index 1984ae4b98..7c46704d66 100644
--- a/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx
@@ -66,7 +66,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
locationsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/locations.new.tsx b/apps/carbon/app/routes/x+/resources+/locations.new.tsx
index 2f57e94fbc..730c69b3d4 100644
--- a/apps/carbon/app/routes/x+/resources+/locations.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/locations.new.tsx
@@ -62,7 +62,7 @@ export async function action({ request }: ActionFunctionArgs) {
}
export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
locationsQuery(getCompanyId()).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx b/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
index cf31f17429..b93ba6de26 100644
--- a/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-centers.$id.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error, notFound, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import type { ClientActionFunctionArgs } from "@remix-run/react";
import { useLoaderData, useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -13,6 +14,7 @@ import {
} from "~/modules/resources";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+import { getCompanyId, workCentersQuery } from "~/utils/react-query";
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -76,6 +78,14 @@ export async function action({ request }: ActionFunctionArgs) {
);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.queryClient?.setQueryData(
+ workCentersQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function WorkCenterRoute() {
const { workCenter } = useLoaderData<typeof loader>();
const navigate = useNavigate();
diff --git a/apps/carbon/app/routes/x+/resources+/work-centers.delete.$id.tsx b/apps/carbon/app/routes/x+/resources+/work-centers.delete.$id.tsx
index bb9ea83928..6e0859da4d 100644
--- a/apps/carbon/app/routes/x+/resources+/work-centers.delete.$id.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-centers.delete.$id.tsx
@@ -1,10 +1,12 @@
import { error, success } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
+import type { ClientActionFunctionArgs } from "@remix-run/react";
import type { LoaderFunctionArgs } from "@vercel/remix";
import { redirect } from "@vercel/remix";
import { deleteWorkCenter } from "~/modules/resources";
import { path } from "~/utils/path";
+import { getCompanyId, workCentersQuery } from "~/utils/react-query";
export async function action({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
@@ -35,3 +37,11 @@ export async function action({ request, params }: LoaderFunctionArgs) {
await flash(request, success("Successfully deactivated work center"))
);
}
+
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.queryClient?.setQueryData(
+ workCentersQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
diff --git a/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx b/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
index b102d559e6..cd9847359f 100644
--- a/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
+++ b/apps/carbon/app/routes/x+/resources+/work-centers.new.tsx
@@ -2,6 +2,7 @@ import { assertIsPost, error } from "@carbon/auth";
import { requirePermissions } from "@carbon/auth/auth.server";
import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
+import type { ClientActionFunctionArgs } from "@remix-run/react";
import { useNavigate } from "@remix-run/react";
import type { ActionFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
@@ -13,6 +14,7 @@ import {
} from "~/modules/resources";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+import { getCompanyId, workCentersQuery } from "~/utils/react-query";
export async function action({ request }: ActionFunctionArgs) {
assertIsPost(request);
@@ -52,6 +54,14 @@ export async function action({ request }: ActionFunctionArgs) {
return modal ? json(createWorkCenter) : redirect(path.to.workCenters);
}
+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {
+ window.queryClient?.setQueryData(
+ workCentersQuery(getCompanyId()).queryKey,
+ null
+ );
+ return await serverAction();
+}
+
export default function NewWorkCenterRoute() {
const navigate = useNavigate();
const onClose = () => navigate(path.to.workCenters);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx
index a72480e0c0..61aaa039e5 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx
@@ -103,7 +103,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierContactsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.delete.$supplierContactId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.delete.$supplierContactId.tsx
index c724c1e3bc..7f97178934 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.delete.$supplierContactId.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.delete.$supplierContactId.tsx
@@ -50,7 +50,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierContactsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx
index 1d0ccfae22..846882e62e 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx
@@ -82,7 +82,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierContactsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx
index 7e092c4255..fe24af734d 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx
@@ -99,7 +99,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierLocationsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.delete.$supplierLocationId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.delete.$supplierLocationId.tsx
index 7134123bc2..4f96f344fe 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.delete.$supplierLocationId.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.delete.$supplierLocationId.tsx
@@ -52,7 +52,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierLocationsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx
index db0fe0cc84..372bcf9204 100644
--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx
@@ -94,7 +94,7 @@ export async function clientAction({
}: ClientActionFunctionArgs) {
const { supplierId } = params;
if (supplierId) {
- window.queryClient.setQueryData(
+ window.queryClient?.setQueryData(
supplierLocationsQuery(supplierId).queryKey,
null
);
diff --git a/apps/carbon/app/utils/react-query.ts b/apps/carbon/app/utils/react-query.ts
index 936cffa296..93356ae93c 100644
--- a/apps/carbon/app/utils/react-query.ts
+++ b/apps/carbon/app/utils/react-query.ts
@@ -48,6 +48,11 @@ export const paymentTermsQuery = (companyId: string | null) => ({
staleTime: RefreshRate.Low,
});
+export const processesQuery = (companyId: string | null) => ({
+ queryKey: ["processes", companyId ?? "null"],
+ staleTime: RefreshRate.Low,
+});
+
export const shippingMethodsQuery = (companyId: string | null) => ({
queryKey: ["shippingMethods", companyId ?? "null"],
staleTime: RefreshRate.Low,
@@ -67,3 +72,8 @@ export const uomsQuery = (companyId: string | null) => ({
queryKey: ["uoms", companyId ?? "null"],
staleTime: RefreshRate.Medium,
});
+
+export const workCentersQuery = (companyId: string | null) => ({
+ queryKey: ["workCenters", companyId ?? "null"],
+ staleTime: RefreshRate.Low,
+});