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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
refactor: use new pattern for client-side caching
Brad Barbin96e8e30344f4
diff --git a/apps/carbon/app/components/Form/Abilities.tsx b/apps/carbon/app/components/Form/Abilities.tsxindex 5fb999dc09..d66c87e698 100644--- a/apps/carbon/app/components/Form/Abilities.tsx+++ b/apps/carbon/app/components/Form/Abilities.tsx@@ -1,31 +1,11 @@import type { MultiSelectProps } from "@carbon/form";import { MultiSelect } from "@carbon/form";-import { useMount } from "@carbon/react";-import { useFetcher } from "@remix-run/react";-import { useMemo } from "react";-import type { getAbilitiesList } from "~/modules/resources";-import { path } from "~/utils/path";+import { useAbilities } from "./Ability";type AbilitiesSelectProps = Omit<MultiSelectProps, "options" | "value">;const Abilities = (props: AbilitiesSelectProps) => {- const abilityFetcher =- useFetcher<Awaited<ReturnType<typeof getAbilitiesList>>>();-- useMount(() => {- abilityFetcher.load(path.to.api.abilities);- });-- const options = useMemo(- () =>- abilityFetcher.data?.data- ? abilityFetcher.data?.data.map((c) => ({- value: c.id,- label: c.name,- }))- : [],- [abilityFetcher.data]- );+ const options = useAbilities();return (<MultiSelectdiff --git a/apps/carbon/app/components/Form/CustomerContact.tsx b/apps/carbon/app/components/Form/CustomerContact.tsxindex 90cf6fad95..7d37f8b3cd 100644--- a/apps/carbon/app/components/Form/CustomerContact.tsx+++ b/apps/carbon/app/components/Form/CustomerContact.tsx@@ -37,39 +37,17 @@ const CustomerContactPreview = (};const CustomerContact = (props: CustomerContactSelectProps) => {- const customerContactsFetcher =- useFetcher<Awaited<ReturnType<typeof getCustomerContacts>>>();-const newContactModal = useDisclosure();const [created, setCreated] = useState<string>("");const triggerRef = useRef<HTMLButtonElement>(null);const [firstName, ...lastName] = created.split(" ");- useEffect(() => {- if (props?.customer) {- customerContactsFetcher.load(- path.to.api.customerContacts(props.customer)- );- }- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [props.customer]);-- const options = useMemo(- () =>- customerContactsFetcher.data?.data?.map((c) => ({- value: c.id,- label: c.contact?.fullName ?? c.contact?.email ?? "Unknown",- })) ?? [],-- [customerContactsFetcher.data]- );+ const { options, data } = useCustomerContacts(props.customer);const onChange = (newValue: { label: string; value: string } | null) => {const contact =- customerContactsFetcher.data?.data?.find(- (contact) => contact.id === newValue?.value- ) ?? null;+ data?.data?.find((contact) => contact.id === newValue?.value) ?? null;props.onChange?.(contact ?? null);};@@ -109,3 +87,27 @@ const CustomerContact = (props: CustomerContactSelectProps) => {};export default CustomerContact;++function useCustomerContacts(customerId?: string) {+ const customerContactsFetcher =+ useFetcher<Awaited<ReturnType<typeof getCustomerContacts>>>();++ useEffect(() => {+ if (customerId) {+ customerContactsFetcher.load(path.to.api.customerContacts(customerId));+ }+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [customerId]);++ const options = useMemo(+ () =>+ customerContactsFetcher.data?.data?.map((c) => ({+ value: c.id,+ label: c.contact?.fullName ?? c.contact?.email ?? "Unknown",+ })) ?? [],++ [customerContactsFetcher.data]+ );++ return { options, data: customerContactsFetcher.data };+}diff --git a/apps/carbon/app/global.d.ts b/apps/carbon/app/global.d.tsnew file mode 100644index 0000000000..cf5439d2fd--- /dev/null+++ b/apps/carbon/app/global.d.ts@@ -0,0 +1,5 @@+declare global {+ interface Window {+ queryClient?: QueryClient;+ }+}diff --git a/apps/carbon/app/modules/resources/resources.service.ts b/apps/carbon/app/modules/resources/resources.service.tsindex ac4738c148..5fd05d8f87 100644--- a/apps/carbon/app/modules/resources/resources.service.ts+++ b/apps/carbon/app/modules/resources/resources.service.ts@@ -14,7 +14,7 @@ import type {export async function deleteAbility(client: SupabaseClient<Database>,abilityId: string,- hardDelete = false+ hardDelete = true) {return hardDelete? client.from("ability").delete().eq("id", abilityId)diff --git a/apps/carbon/app/root.tsx b/apps/carbon/app/root.tsxindex ef6ab3721b..ddcd9003c3 100644--- a/apps/carbon/app/root.tsx+++ b/apps/carbon/app/root.tsx@@ -1,7 +1,7 @@import { error, getBrowserEnv } from "@carbon/auth";import { getSessionFlash } from "@carbon/auth/session.server";import { validator } from "@carbon/form";-import { Button, Heading, toast, Toaster } from "@carbon/react";+import { Button, Heading, toast, Toaster, useMount } from "@carbon/react";import type { Theme } from "@carbon/utils";import { themes } from "@carbon/utils";import {@@ -14,6 +14,7 @@ import {useLoaderData,useRouteError,} from "@remix-run/react";+import { QueryClient } from "@tanstack/react-query";import { Analytics } from "@vercel/analytics/react";import type {ActionFunctionArgs,@@ -169,6 +170,20 @@ export default function App() {const theme = loaderData?.theme ?? "zinc";const mode = useMode();+ useMount(() => {+ if (!window.queryClient) {+ window.queryClient = new QueryClient({+ defaultOptions: {+ queries: {+ staleTime: Infinity,+ refetchOnWindowFocus: false,+ gcTime: Infinity,+ },+ },+ });+ }+ });+/* Toast Messages */useEffect(() => {if (result?.success === true) {@@ -181,6 +196,7 @@ export default function App() {return (<Document mode={mode} theme={theme}><Outlet />+<scriptdangerouslySetInnerHTML={{__html: `window.env = ${JSON.stringify(env)}`,diff --git a/apps/carbon/app/routes/api+/accounting.currencies.ts b/apps/carbon/app/routes/api+/accounting.currencies.tsindex c8b2857403..736794a32f 100644--- a/apps/carbon/app/routes/api+/accounting.currencies.ts+++ b/apps/carbon/app/routes/api+/accounting.currencies.ts@@ -1,10 +1,28 @@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 { getCurrenciesList } from "~/modules/accounting";+import { currenciesQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {});return json(await getCurrenciesList(client));}++export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {+ const query = currenciesQuery();+ const data = window?.queryClient?.getQueryData<SerializeFrom<typeof loader>>(+ query.queryKey+ );++ if (!data) {+ const serverData = await serverLoader<typeof loader>();+ window?.queryClient?.setQueryData(query.queryKey, serverData);+ return serverData;+ }++ return data;+}+clientLoader.hydrate = true;diff --git a/apps/carbon/app/routes/api+/accounting.payment-terms.ts b/apps/carbon/app/routes/api+/accounting.payment-terms.tsindex 58bf2ccc35..0265aa2117 100644--- a/apps/carbon/app/routes/api+/accounting.payment-terms.ts+++ b/apps/carbon/app/routes/api+/accounting.payment-terms.ts@@ -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 { getPaymentTermsList } from "~/modules/accounting";+import { getCompanyId, paymentTermsQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});return json(await getPaymentTermsList(client, companyId));}++export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {+ const companyId = getCompanyId();++ if (!companyId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = paymentTermsQuery(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/api+/countries.ts b/apps/carbon/app/routes/api+/countries.tsindex 9a6d3e0c5a..38515784ed 100644--- a/apps/carbon/app/routes/api+/countries.ts+++ b/apps/carbon/app/routes/api+/countries.ts@@ -3,7 +3,7 @@ import type { ClientLoaderFunctionArgs } from "@remix-run/react";import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";import { json } from "@vercel/remix";import { getCountries } from "~/modules/shared";-import { countriesQuery, queryClient } from "~/utils/react-query";+import { countriesQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {});@@ -12,13 +12,13 @@ export async function loader({ request }: LoaderFunctionArgs) {export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {const query = countriesQuery();- const data = queryClient.getQueryData<SerializeFrom<typeof loader>>(+ const data = window?.queryClient?.getQueryData<SerializeFrom<typeof loader>>(query.queryKey);if (!data) {const serverData = await serverLoader<typeof loader>();- queryClient.setQueryData(query.queryKey, serverData);+ window?.queryClient?.setQueryData(query.queryKey, serverData);return serverData;}diff --git a/apps/carbon/app/routes/api+/items.uoms.ts b/apps/carbon/app/routes/api+/items.uoms.tsindex d5d37a21b4..4f2a9e1faa 100644--- a/apps/carbon/app/routes/api+/items.uoms.ts+++ b/apps/carbon/app/routes/api+/items.uoms.ts@@ -3,7 +3,7 @@ import type { ClientLoaderFunctionArgs } from "@remix-run/react";import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";import { json } from "@vercel/remix";import { getUnitOfMeasuresList } from "~/modules/items";-import { getCompanyId, queryClient, uomsQuery } from "~/utils/react-query";+import { getCompanyId, uomsQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});@@ -18,14 +18,13 @@ export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {return await serverLoader<typeof loader>();}- const query = uomsQuery(companyId);- const data = queryClient.getQueryData<SerializeFrom<typeof loader>>(- query.queryKey- );+ const queryKey = uomsQuery(companyId).queryKey;+ const data =+ window?.queryClient?.getQueryData<SerializeFrom<typeof loader>>(queryKey);if (!data) {const serverData = await serverLoader<typeof loader>();- queryClient.setQueryData(query.queryKey, serverData);+ window?.queryClient?.setQueryData(queryKey, serverData);return serverData;}diff --git a/apps/carbon/app/routes/api+/purchasing.supplier-contacts.$supplierId.ts b/apps/carbon/app/routes/api+/purchasing.supplier-contacts.$supplierId.tsnew file mode 100644index 0000000000..96876c1635--- /dev/null+++ b/apps/carbon/app/routes/api+/purchasing.supplier-contacts.$supplierId.ts@@ -0,0 +1,58 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ClientLoaderFunctionArgs } from "@remix-run/react";+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";+import { json } from "@vercel/remix";+import { getSupplierContacts } from "~/modules/purchasing";+import { supplierContactsQuery } from "~/utils/react-query";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {+ view: "purchasing",+ });++ const { supplierId } = params;++ if (!supplierId)+ return json({+ data: [],+ });++ const contacts = await getSupplierContacts(authorized.client, supplierId);+ if (contacts.error) {+ return json(+ contacts,+ await flash(+ request,+ error(contacts.error, "Failed to get supplier contacts")+ )+ );+ }++ return json(contacts);+}++export async function clientLoader({+ serverLoader,+ params,+}: ClientLoaderFunctionArgs) {+ const { supplierId } = params;++ if (!supplierId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = supplierContactsQuery(supplierId).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/api+/purchasing.supplier-contacts.ts b/apps/carbon/app/routes/api+/purchasing.supplier-contacts.tsdeleted file mode 100644index 53fe1ecb0b..0000000000--- a/apps/carbon/app/routes/api+/purchasing.supplier-contacts.ts+++ /dev/null@@ -1,34 +0,0 @@-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";-import { getSupplierContacts } from "~/modules/purchasing";--export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {- view: "purchasing",- });-- const url = new URL(request.url);- const searchParams = new URLSearchParams(url.search);- const supplierId = searchParams.get("supplierId") as string;-- if (!supplierId || supplierId === "undefined")- return json({- data: [],- });-- const contacts = await getSupplierContacts(authorized.client, supplierId);- if (contacts.error) {- return json(- contacts,- await flash(- request,- error(contacts.error, "Failed to get supplier contacts")- )- );- }-- return json(contacts);-}diff --git a/apps/carbon/app/routes/api+/purchasing.supplier-locations.$supplierId.ts b/apps/carbon/app/routes/api+/purchasing.supplier-locations.$supplierId.tsnew file mode 100644index 0000000000..cf644fc011--- /dev/null+++ b/apps/carbon/app/routes/api+/purchasing.supplier-locations.$supplierId.ts@@ -0,0 +1,58 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ClientLoaderFunctionArgs } from "@remix-run/react";+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";+import { json } from "@vercel/remix";+import { getSupplierLocations } from "~/modules/purchasing";+import { supplierLocationsQuery } from "~/utils/react-query";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {+ view: "purchasing",+ });++ const { supplierId } = params;++ if (!supplierId)+ return json({+ data: [],+ });++ const locations = await getSupplierLocations(authorized.client, supplierId);+ if (locations.error) {+ return json(+ locations,+ await flash(+ request,+ error(locations.error, "Failed to get supplier locations")+ )+ );+ }++ return json(locations);+}++export async function clientLoader({+ serverLoader,+ params,+}: ClientLoaderFunctionArgs) {+ const { supplierId } = params;++ if (!supplierId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = supplierLocationsQuery(supplierId).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/api+/purchasing.supplier-locations.ts b/apps/carbon/app/routes/api+/purchasing.supplier-locations.tsdeleted file mode 100644index 7460d6d706..0000000000--- a/apps/carbon/app/routes/api+/purchasing.supplier-locations.ts+++ /dev/null@@ -1,34 +0,0 @@-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";-import { getSupplierLocations } from "~/modules/purchasing";--export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {- view: "purchasing",- });-- const url = new URL(request.url);- const searchParams = new URLSearchParams(url.search);- const supplierId = searchParams.get("supplierId") as string;-- if (!supplierId || supplierId === "undefined")- return json({- data: [],- });-- const locations = await getSupplierLocations(authorized.client, supplierId);- if (locations.error) {- return json(- locations,- await flash(- request,- error(locations.error, "Failed to get supplier locations")- )- );- }-- return json(locations);-}diff --git a/apps/carbon/app/routes/api+/resources.abilities.ts b/apps/carbon/app/routes/api+/resources.abilities.tsindex 557f8148cb..5c9ddbe132 100644--- a/apps/carbon/app/routes/api+/resources.abilities.ts+++ b/apps/carbon/app/routes/api+/resources.abilities.ts@@ -1,7 +1,9 @@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 { getAbilitiesList } from "~/modules/resources";+import { abilitiesQuery, getCompanyId } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {@@ -10,3 +12,24 @@ export async function loader({ request }: LoaderFunctionArgs) {return json(await getAbilitiesList(client, companyId));}++export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {+ const companyId = getCompanyId();++ if (!companyId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = abilitiesQuery(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/api+/resources.locations.ts b/apps/carbon/app/routes/api+/resources.locations.tsindex f933c27ed2..06839c0b33 100644--- a/apps/carbon/app/routes/api+/resources.locations.ts+++ b/apps/carbon/app/routes/api+/resources.locations.ts@@ -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 { getLocationsList } from "~/modules/resources";+import { getCompanyId, locationsQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {});return json(await getLocationsList(client, companyId));}++export async function clientLoader({ serverLoader }: ClientLoaderFunctionArgs) {+ const companyId = getCompanyId();++ if (!companyId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = locationsQuery(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/api+/sales.customer-contacts.$customerId.ts b/apps/carbon/app/routes/api+/sales.customer-contacts.$customerId.tsnew file mode 100644index 0000000000..00b18faecb--- /dev/null+++ b/apps/carbon/app/routes/api+/sales.customer-contacts.$customerId.ts@@ -0,0 +1,58 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ClientLoaderFunctionArgs } from "@remix-run/react";+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";+import { json } from "@vercel/remix";+import { getCustomerContacts } from "~/modules/sales";+import { customerContactsQuery } from "~/utils/react-query";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {+ view: "sales",+ });++ const { customerId } = params;++ if (!customerId)+ return json({+ data: [],+ });++ const contacts = await getCustomerContacts(authorized.client, customerId);+ if (contacts.error) {+ return json(+ contacts,+ await flash(+ request,+ error(contacts.error, "Failed to get customer contacts")+ )+ );+ }++ return json(contacts);+}++export async function clientLoader({+ serverLoader,+ params,+}: ClientLoaderFunctionArgs) {+ const { customerId } = params;++ if (!customerId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = customerContactsQuery(customerId).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/api+/sales.customer-contacts.ts b/apps/carbon/app/routes/api+/sales.customer-contacts.tsdeleted file mode 100644index b872c3ba9a..0000000000--- a/apps/carbon/app/routes/api+/sales.customer-contacts.ts+++ /dev/null@@ -1,34 +0,0 @@-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";-import { getCustomerContacts } from "~/modules/sales";--export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {- view: "sales",- });-- const url = new URL(request.url);- const searchParams = new URLSearchParams(url.search);- const customerId = searchParams.get("customerId") as string;-- if (!customerId || customerId === "undefined")- return json({- data: [],- });-- const contacts = await getCustomerContacts(authorized.client, customerId);- if (contacts.error) {- return json(- contacts,- await flash(- request,- error(contacts.error, "Failed to get customer contacts")- )- );- }-- return json(contacts);-}diff --git a/apps/carbon/app/routes/api+/sales.customer-locations.$customerId.ts b/apps/carbon/app/routes/api+/sales.customer-locations.$customerId.tsnew file mode 100644index 0000000000..305b91862e--- /dev/null+++ b/apps/carbon/app/routes/api+/sales.customer-locations.$customerId.ts@@ -0,0 +1,58 @@+import { error } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ClientLoaderFunctionArgs } from "@remix-run/react";+import type { LoaderFunctionArgs, SerializeFrom } from "@vercel/remix";+import { json } from "@vercel/remix";+import { getCustomerLocations } from "~/modules/sales";+import { customerLocationsQuery } from "~/utils/react-query";++export async function loader({ request, params }: LoaderFunctionArgs) {+ const authorized = await requirePermissions(request, {+ view: "sales",+ });++ const { customerId } = params;++ if (!customerId)+ return json({+ data: [],+ });++ const locations = await getCustomerLocations(authorized.client, customerId);+ if (locations.error) {+ return json(+ locations,+ await flash(+ request,+ error(locations.error, "Failed to get supplier locations")+ )+ );+ }++ return json(locations);+}++export async function clientLoader({+ serverLoader,+ params,+}: ClientLoaderFunctionArgs) {+ const { customerId } = params;++ if (!customerId) {+ return await serverLoader<typeof loader>();+ }++ const queryKey = customerLocationsQuery(customerId).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/api+/sales.customer-locations.ts b/apps/carbon/app/routes/api+/sales.customer-locations.tsdeleted file mode 100644index 6fb8feffae..0000000000--- a/apps/carbon/app/routes/api+/sales.customer-locations.ts+++ /dev/null@@ -1,34 +0,0 @@-import { error } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { LoaderFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";-import { getCustomerLocations } from "~/modules/sales";--export async function loader({ request }: LoaderFunctionArgs) {- const authorized = await requirePermissions(request, {- view: "sales",- });-- const url = new URL(request.url);- const searchParams = new URLSearchParams(url.search);- const customerId = searchParams.get("customerId") as string;-- if (!customerId || customerId === "undefined")- return json({- data: [],- });-- const locations = await getCustomerLocations(authorized.client, customerId);- if (locations.error) {- return json(- locations,- await flash(- request,- error(locations.error, "Failed to get supplier locations")- )- );- }-- return json(locations);-}diff --git a/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx b/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsxindex d76e665c90..3081b9348b 100644--- a/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx+++ b/apps/carbon/app/routes/x+/accounting+/currencies.$currencyId.tsx@@ -1,4 +1,5 @@import { validationError, validator } from "@carbon/form";+import type { ClientActionFunctionArgs } from "@remix-run/react";import { useLoaderData } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -14,6 +15,7 @@ import {} from "~/modules/accounting";import { getCustomFields, setCustomFields } from "~/utils/form";import { getParams, path } from "~/utils/path";+import { currenciesQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -71,6 +73,11 @@ export async function action({ request }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(currenciesQuery().queryKey, null);+ return await serverAction();+}+export default function EditCurrencysRoute() {const { currency } = useLoaderData<typeof loader>();diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsxindex 3f9d3307fd..0cbaaa46de 100644--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.tsx+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.$paymentTermId.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";@@ -14,6 +15,7 @@ import {} from "~/modules/accounting";import { getCustomFields, setCustomFields } from "~/utils/form";import { getParams, path } from "~/utils/path";+import { getCompanyId, paymentTermsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -70,6 +72,14 @@ export async function action({ request }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ paymentTermsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function EditPaymentTermsRoute() {const { paymentTerm } = useLoaderData<typeof loader>();const navigate = useNavigate();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.tsxindex d2aaef4301..c53d4a45c1 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@@ -1,12 +1,14 @@import { error, notFound, 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 { useLoaderData, useNavigate, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { ConfirmDelete } from "~/components/Modals";import { deletePaymentTerm, getPaymentTerm } from "~/modules/accounting";import { getParams, path } from "~/utils/path";+import { getCompanyId, paymentTermsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -62,6 +64,14 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ paymentTermsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function DeletePaymentTermRoute() {const { paymentTermId } = useParams();const { paymentTerm } = useLoaderData<typeof loader>();diff --git a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx b/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsxindex 7245dc4688..0a4a05ebd6 100644--- a/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx+++ b/apps/carbon/app/routes/x+/accounting+/payment-terms.new.tsx@@ -2,6 +2,7 @@ import { assertIsPost, error, 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 { 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/accounting";import { setCustomFields } from "~/utils/form";import { getParams, path } from "~/utils/path";+import { getCompanyId, paymentTermsQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {@@ -63,6 +65,14 @@ export async function action({ request }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ paymentTermsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function NewPaymentTermsRoute() {const navigate = useNavigate();const initialValues = {diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsxindex 381b28be8a..86d5a24bc8 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -19,6 +20,7 @@ import {} from "~/modules/sales";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { customerContactsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -95,6 +97,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;+ if (customerId) {+ window.queryClient.setQueryData(+ customerContactsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function EditCustomerContactRoute() {const { contact } = useLoaderData<typeof loader>();const navigate = useNavigate();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.tsxindex 33e595d544..42be4a4b28 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@@ -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 { ActionFunctionArgs } from "@vercel/remix";import { redirect } from "@vercel/remix";import { deleteCustomerContact } from "~/modules/sales";import { path } from "~/utils/path";+import { customerContactsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {const { client } = await requirePermissions(request, {@@ -41,3 +43,17 @@ export async function action({ request, params }: ActionFunctionArgs) {await flash(request, success("Successfully deleted customer contact")));}++export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;+ if (customerId) {+ window.queryClient.setQueryData(+ customerContactsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsxindex e9e77ed49e..5f57e029d8 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -18,6 +19,7 @@ import {} from "~/modules/sales";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { customerContactsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);@@ -74,6 +76,21 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;++ if (customerId) {+ window.queryClient.setQueryData(+ customerContactsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function CustomerContactsNewRoute() {const navigate = useNavigate();const { customerId } = useParams();diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsxindex cdf630c40a..ddf06a2556 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.$customerLocationId.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -19,6 +20,7 @@ import {} from "~/modules/sales";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { customerLocationsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -91,6 +93,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;+ if (customerId) {+ window.queryClient.setQueryData(+ customerLocationsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function EditCustomerLocationRoute() {const { location } = useLoaderData<typeof loader>();const navigate = useNavigate();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.tsxindex c77006a130..0d4e547e2f 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@@ -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 { ActionFunctionArgs } from "@vercel/remix";import { redirect } from "@vercel/remix";import { deleteCustomerLocation } from "~/modules/sales";import { path } from "~/utils/path";+import { customerLocationsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {const { client } = await requirePermissions(request, {@@ -44,3 +46,17 @@ export async function action({ request, params }: ActionFunctionArgs) {await flash(request, success("Successfully deleted customer location")));}++export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;+ if (customerId) {+ window.queryClient.setQueryData(+ customerLocationsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsxindex 7584a805d0..8dbed8e1e3 100644--- a/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.tsx+++ b/apps/carbon/app/routes/x+/customer+/$customerId.locations.new.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 { useNavigate, useParams } from "@remix-run/react";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -13,6 +14,7 @@ import {} from "~/modules/sales";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { customerLocationsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);@@ -66,6 +68,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { customerId } = params;+ if (customerId) {+ window.queryClient.setQueryData(+ customerLocationsQuery(customerId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function CustomerLocationsNewRoute() {const navigate = useNavigate();const { company } = useUser();diff --git a/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx b/apps/carbon/app/routes/x+/items+/uom.$uomId.tsxindex a2eb150d69..cb47c21436 100644--- a/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx+++ b/apps/carbon/app/routes/x+/items+/uom.$uomId.tsx@@ -14,7 +14,7 @@ import {} from "~/modules/items";import { getCustomFields, setCustomFields } from "~/utils/form";import { getParams, path } from "~/utils/path";-import { getCompanyId, queryClient, uomsQuery } from "~/utils/react-query";+import { getCompanyId, uomsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {@@ -72,12 +72,7 @@ export async function action({ request }: ActionFunctionArgs) {}export async function clientAction({ serverAction }: ClientActionFunctionArgs) {- const companyId = getCompanyId();- if (!companyId) {- return await serverAction();- }-- queryClient.invalidateQueries({ queryKey: uomsQuery(companyId).queryKey });+ 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.tsxindex 3d0434550c..bc2858f889 100644--- a/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx+++ b/apps/carbon/app/routes/x+/items+/uom.delete.$uomId.tsx@@ -8,7 +8,7 @@ import { json, redirect } from "@vercel/remix";import { ConfirmDelete } from "~/components/Modals";import { deleteUnitOfMeasure, getUnitOfMeasure } from "~/modules/items";import { getParams, path } from "~/utils/path";-import { getCompanyId, queryClient, uomsQuery } from "~/utils/react-query";+import { getCompanyId, uomsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client, companyId } = await requirePermissions(request, {@@ -63,12 +63,7 @@ export async function action({ request, params }: ActionFunctionArgs) {}export async function clientAction({ serverAction }: ClientActionFunctionArgs) {- const companyId = getCompanyId();- if (!companyId) {- return await serverAction();- }-- queryClient.invalidateQueries({ queryKey: uomsQuery(companyId).queryKey });+ window.queryClient.setQueryData(uomsQuery(getCompanyId()).queryKey, null);return await serverAction();}diff --git a/apps/carbon/app/routes/x+/items+/uom.new.tsx b/apps/carbon/app/routes/x+/items+/uom.new.tsxindex 674ae9ef8c..e196ea2bb9 100644--- a/apps/carbon/app/routes/x+/items+/uom.new.tsx+++ b/apps/carbon/app/routes/x+/items+/uom.new.tsx@@ -13,7 +13,7 @@ import {} from "~/modules/items";import { setCustomFields } from "~/utils/form";import { getParams, path } from "~/utils/path";-import { getCompanyId, queryClient, uomsQuery } from "~/utils/react-query";+import { getCompanyId, uomsQuery } from "~/utils/react-query";export async function loader({ request }: LoaderFunctionArgs) {await requirePermissions(request, {@@ -65,12 +65,8 @@ export async function action({ request }: ActionFunctionArgs) {}export async function clientAction({ serverAction }: ClientActionFunctionArgs) {- const companyId = getCompanyId();- if (!companyId) {- return await serverAction();- }+ window?.queryClient?.setQueryData(uomsQuery(getCompanyId()).queryKey, null);- queryClient.invalidateQueries({ queryKey: uomsQuery(companyId).queryKey });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.tsxindex af29181df1..800b362463 100644--- a/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx+++ b/apps/carbon/app/routes/x+/resources+/abilities.delete.$abilityId.tsx@@ -1,12 +1,14 @@import { error, notFound, 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 { useLoaderData, useNavigate, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { ConfirmDelete } from "~/components/Modals";import { deleteAbility, getAbility } from "~/modules/resources";import { path } from "~/utils/path";+import { abilitiesQuery, getCompanyId } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -60,6 +62,14 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ abilitiesQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function DeleteEmployeeTypeRoute() {const { abilityId } = useParams();const { ability } = useLoaderData<typeof loader>();diff --git a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx b/apps/carbon/app/routes/x+/resources+/abilities.new.tsxindex 3eb6ccc901..6ee0345036 100644--- a/apps/carbon/app/routes/x+/resources+/abilities.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/abilities.new.tsx@@ -2,6 +2,7 @@ import { assertIsPost, error, 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 type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import {@@ -12,6 +13,7 @@ import {insertEmployeeAbilities,} from "~/modules/resources";import { path } from "~/utils/path";+import { abilitiesQuery, getCompanyId } from "~/utils/react-query";function makeCurve(startingPoint: number, weeks: number) {return {@@ -87,6 +89,7 @@ export async function action({ request }: ActionFunctionArgs) {);if (createEmployeeAbilities.error) {+ console.error(createEmployeeAbilities.error);await deleteAbility(client, abilityId, true);return json({},@@ -107,6 +110,14 @@ export async function action({ request }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ abilitiesQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function NewAbilityRoute() {const initialValues = {name: "",diff --git a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsxindex a5122d93ab..0c021401af 100644--- a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx+++ b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx@@ -14,6 +14,7 @@ import {NumberInputStepper,useDisclosure,} from "@carbon/react";+import type { ClientActionFunctionArgs } from "@remix-run/react";import { Outlet, useLoaderData, useNavigate } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -34,6 +35,7 @@ import {} from "~/modules/resources";import type { Handle } from "~/utils/handle";import { path } from "~/utils/path";+import { abilitiesQuery, getCompanyId } from "~/utils/react-query";export const handle: Handle = {breadcrumb: "Abilities",@@ -134,6 +136,14 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ abilitiesQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function AbilitiesRoute() {const { ability, weeks } = useLoaderData<typeof loader>();const navigate = useNavigate();diff --git a/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx b/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsxindex 32bae8cfe5..9374c72ba4 100644--- a/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx+++ b/apps/carbon/app/routes/x+/resources+/locations.$locationId.tsx@@ -3,6 +3,7 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { getLocalTimeZone } from "@internationalized/date";+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";@@ -14,6 +15,7 @@ import {} from "~/modules/resources";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { getCompanyId, locationsQuery } 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(+ locationsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function LocationRoute() {const { location } = useLoaderData<typeof loader>();const navigate = useNavigate();diff --git a/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx b/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsxindex 41e79cf47c..1984ae4b98 100644--- a/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx+++ b/apps/carbon/app/routes/x+/resources+/locations.delete.$locationId.tsx@@ -1,12 +1,14 @@import { error, notFound, 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 { useLoaderData, useNavigate, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { ConfirmDelete } from "~/components/Modals";import { deleteLocation, getLocation } from "~/modules/resources";import { path } from "~/utils/path";+import { getCompanyId, locationsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -63,6 +65,14 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ locationsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function DeleteLocationRoute() {const { locationId } = useParams();const { location } = useLoaderData<typeof loader>();diff --git a/apps/carbon/app/routes/x+/resources+/locations.new.tsx b/apps/carbon/app/routes/x+/resources+/locations.new.tsxindex c8f8d7623b..2f57e94fbc 100644--- a/apps/carbon/app/routes/x+/resources+/locations.new.tsx+++ b/apps/carbon/app/routes/x+/resources+/locations.new.tsx@@ -3,6 +3,7 @@ import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import { validationError, validator } from "@carbon/form";import { getLocalTimeZone } from "@internationalized/date";+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";@@ -14,6 +15,7 @@ import {} from "~/modules/resources";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { getCompanyId, locationsQuery } from "~/utils/react-query";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);@@ -59,6 +61,14 @@ export async function action({ request }: ActionFunctionArgs) {);}+export async function clientAction({ serverAction }: ClientActionFunctionArgs) {+ window.queryClient.setQueryData(+ locationsQuery(getCompanyId()).queryKey,+ null+ );+ return await serverAction();+}+export default function NewLocationRoute() {const navigate = useNavigate();const { company } = useUser();diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsxindex ef3d288f40..a72480e0c0 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.$supplierContactId.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -19,6 +20,7 @@ import {} from "~/modules/purchasing";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { supplierContactsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -95,6 +97,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierContactsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function EditSupplierContactRoute() {const { contact } = useLoaderData<typeof loader>();const navigate = useNavigate();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.tsxindex 7454427ef6..c724c1e3bc 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@@ -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 { ActionFunctionArgs } from "@vercel/remix";import { redirect } from "@vercel/remix";import { deleteSupplierContact } from "~/modules/purchasing";import { path } from "~/utils/path";+import { supplierContactsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {const { client } = await requirePermissions(request, {@@ -41,3 +43,17 @@ export async function action({ request, params }: ActionFunctionArgs) {await flash(request, success("Successfully deleted supplier contact")));}++export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierContactsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsxindex e721eb1168..1d0ccfae22 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.contacts.new.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -18,6 +19,7 @@ import {} from "~/modules/purchasing";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { supplierContactsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);@@ -74,6 +76,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierContactsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function SupplierContactsNewRoute() {const navigate = useNavigate();const { supplierId } = useParams();diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsxindex 8af6b77cc9..7e092c4255 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.$supplierLocationId.tsx@@ -8,6 +8,7 @@ import {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, useParams } from "@remix-run/react";import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -19,6 +20,7 @@ import {} from "~/modules/purchasing";import { getCustomFields, setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { supplierLocationsQuery } from "~/utils/react-query";export async function loader({ request, params }: LoaderFunctionArgs) {const { client } = await requirePermissions(request, {@@ -91,6 +93,20 @@ export async function action({ request, params }: ActionFunctionArgs) {);}+export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierLocationsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}+export default function EditSupplierLocationRoute() {const { location } = useLoaderData<typeof loader>();const navigate = useNavigate();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.tsxindex 9929097fb2..7134123bc2 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@@ -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 { ActionFunctionArgs } from "@vercel/remix";import { redirect } from "@vercel/remix";import { deleteSupplierLocation } from "~/modules/purchasing";import { path } from "~/utils/path";+import { supplierLocationsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {const { client } = await requirePermissions(request, {@@ -43,3 +45,17 @@ export async function action({ request, params }: ActionFunctionArgs) {await flash(request, success("Successfully deleted supplier location")));}++export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierLocationsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsxindex 23f9ca39f4..db0fe0cc84 100644--- a/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.tsx+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.locations.new.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 { useNavigate, useParams } from "@remix-run/react";import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";@@ -13,6 +14,7 @@ import {} from "~/modules/purchasing";import { setCustomFields } from "~/utils/form";import { path } from "~/utils/path";+import { supplierLocationsQuery } from "~/utils/react-query";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);@@ -85,3 +87,17 @@ export default function SupplierLocationsNewRoute() {/>);}++export async function clientAction({+ serverAction,+ params,+}: ClientActionFunctionArgs) {+ const { supplierId } = params;+ if (supplierId) {+ window.queryClient.setQueryData(+ supplierLocationsQuery(supplierId).queryKey,+ null+ );+ }+ return await serverAction();+}diff --git a/apps/carbon/app/types/global.d.ts b/apps/carbon/app/types/global.d.tsnew file mode 100644index 0000000000..ecef2ee717--- /dev/null+++ b/apps/carbon/app/types/global.d.ts@@ -0,0 +1,9 @@+import type { QueryClient } from "@tanstack/react-query";++declare global {+ interface Window {+ queryClient: QueryClient;+ }+}++export {};diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.tsindex 1ef40b3243..8efad9c1d2 100644--- a/apps/carbon/app/utils/path.ts+++ b/apps/carbon/app/utils/path.ts@@ -20,9 +20,9 @@ export const path = {countries: `${api}/countries`,currencies: `${api}/accounting/currencies`,customerContacts: (id: string) =>- generatePath(`${api}/sales/customer-contacts?customerId=${id}`),+ generatePath(`${api}/sales/customer-contacts/${id}`),customerLocations: (id: string) =>- generatePath(`${api}/sales/customer-locations?customerId=${id}`),+ generatePath(`${api}/sales/customer-locations/${id}`),customerStatuses: `${api}/sales/customer-statuses`,customerTypes: `${api}/sales/customer-types`,departments: `${api}/people/departments`,@@ -56,9 +56,9 @@ export const path = {shelves: (id: string) =>generatePath(`${api}/inventory/shelves?locationId=${id}`),supplierContacts: (id: string) =>- generatePath(`${api}/purchasing/supplier-contacts?supplierId=${id}`),+ generatePath(`${api}/purchasing/supplier-contacts/${id}`),supplierLocations: (id: string) =>- generatePath(`${api}/purchasing/supplier-locations?supplierId=${id}`),+ generatePath(`${api}/purchasing/supplier-locations/${id}`),supplierProcesses: (id?: string) =>generatePath(`${api}/purchasing/supplier-processes?processId=${id}`),supplierStatuses: `${api}/purchasing/supplier-statuses`,diff --git a/apps/carbon/app/utils/react-query.ts b/apps/carbon/app/utils/react-query.tsindex cafb6c6129..bd916f34a3 100644--- a/apps/carbon/app/utils/react-query.ts+++ b/apps/carbon/app/utils/react-query.ts@@ -1,9 +1,5 @@-import { remember } from "@epic-web/remember";-import { QueryClient, queryOptions } from "@tanstack/react-query";import * as cookie from "cookie";-export const queryClient = remember("react-query", () => new QueryClient());-enum RefreshRate {Never = Infinity,High = 1000 * 60 * 2,@@ -17,14 +13,52 @@ export const getCompanyId = () => {return parsed;};-export const countriesQuery = () =>- queryOptions({- queryKey: ["countries"],- staleTime: RefreshRate.Never,- });--export const uomsQuery = (companyId: string) =>- queryOptions({- queryKey: ["uoms", companyId],- staleTime: RefreshRate.Medium,- });+export const abilitiesQuery = (companyId: string | null) => ({+ queryKey: ["abilities", companyId ?? "null"],+ staleTime: RefreshRate.Low,+});++export const countriesQuery = () => ({+ queryKey: ["countries"],+ staleTime: RefreshRate.Never,+});++export const currenciesQuery = () => ({+ queryKey: ["currencies"],+ staleTime: RefreshRate.Never,+});++export const customerContactsQuery = (customerId: string) => ({+ queryKey: ["customerContacts", customerId],+ staleTime: RefreshRate.Low,+});++export const customerLocationsQuery = (customerId: string) => ({+ queryKey: ["customerLocations", customerId],+ staleTime: RefreshRate.Low,+});++export const locationsQuery = (companyId: string | null) => ({+ queryKey: ["locations", companyId ?? "null"],+ staleTime: RefreshRate.Low,+});++export const paymentTermsQuery = (companyId: string | null) => ({+ queryKey: ["paymentTerms", companyId ?? "null"],+ staleTime: RefreshRate.Low,+});++export const supplierContactsQuery = (supplierId: string) => ({+ queryKey: ["supplierContacts", supplierId],+ staleTime: RefreshRate.Low,+});++export const supplierLocationsQuery = (supplierId: string) => ({+ queryKey: ["supplierLocations", supplierId],+ staleTime: RefreshRate.Low,+});++export const uomsQuery = (companyId: string | null) => ({+ queryKey: ["uoms", companyId ?? "null"],+ staleTime: RefreshRate.Medium,+});diff --git a/apps/carbon/tsconfig.json b/apps/carbon/tsconfig.jsonindex 5e901f61bc..6be6e78d8d 100644--- a/apps/carbon/tsconfig.json+++ b/apps/carbon/tsconfig.json@@ -4,6 +4,7 @@"**/*.ts","**/*.tsx","app/modules/documents/documents.service.ts",+ "app/types/global.d.ts","trigger.config.ts"],"compilerOptions": {