Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: bug in top-level notes not being refetched after navigation to line and back to top-level

Brad Barbinc24dfed885d1
diff --git a/apps/erp/app/routes/x+/job+/$jobId.details.tsx b/apps/erp/app/routes/x+/job+/$jobId.details.tsx
index 2c6537ebdb..4505e0863e 100644
--- a/apps/erp/app/routes/x+/job+/$jobId.details.tsx
+++ b/apps/erp/app/routes/x+/job+/$jobId.details.tsx
@@ -9,15 +9,16 @@ import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
import { Spinner, useMount, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { CadModel, Documents } from "~/components";
import { usePanels } from "~/components/Layout";
import { usePermissions, useRealtime, useRouteData } from "~/hooks";
import type { Job } from "~/modules/production";
import {
+ getJob,
jobValidator,
recalculateJobRequirements,
upsertJob,
@@ -27,6 +28,31 @@ import type { StorageItem } from "~/types";
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ notes: JSONContent;
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "production",
+ });
+
+ const { jobId } = params;
+ if (!jobId) throw new Error("Could not find jobId");
+
+ const job = await getJob(client, jobId);
+ if (job.error) {
+ throw redirect(
+ path.to.jobs,
+ await flash(request, error(job.error, "Failed to load job"))
+ );
+ }
+
+ return json<LoaderData>({
+ notes: (job.data?.notes ?? {}) as JSONContent,
+ });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, companyId, userId } = await requirePermissions(request, {
@@ -79,6 +105,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function JobDetailsRoute() {
+ const { notes } = useLoaderData<typeof loader>();
const { jobId } = useParams();
if (!jobId) throw new Error("Could not find jobId");
const permissions = usePermissions();
@@ -104,7 +131,7 @@ export default function JobDetailsRoute() {
id={jobId}
title={jobData?.job.jobId ?? ""}
subTitle={jobData?.job.itemReadableId ?? ""}
- notes={jobData?.job.notes as JSONContent}
+ notes={notes}
/>
<Suspense
diff --git a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.details.tsx b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.details.tsx
index 2a827b1ece..4d6b349dba 100644
--- a/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.details.tsx
+++ b/apps/erp/app/routes/x+/purchase-invoice+/$invoiceId.details.tsx
@@ -4,15 +4,16 @@ import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
import { Spinner } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { Fragment } from "react/jsx-runtime";
import { useRouteData } from "~/hooks";
import type { PurchaseInvoice, PurchaseInvoiceLine } from "~/modules/invoicing";
import {
+ getPurchaseInvoice,
PurchaseInvoiceSummary,
purchaseInvoiceValidator,
upsertPurchaseInvoice,
@@ -25,6 +26,34 @@ import {
import { getCustomFields, setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ internalNotes: JSONContent;
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "invoicing",
+ });
+
+ const { invoiceId } = params;
+ if (!invoiceId) throw new Error("Could not find invoiceId");
+
+ const invoice = await getPurchaseInvoice(client, invoiceId);
+ if (invoice.error) {
+ throw redirect(
+ path.to.purchaseInvoices,
+ await flash(
+ request,
+ error(invoice.error, "Failed to load purchase invoice")
+ )
+ );
+ }
+
+ return json<LoaderData>({
+ internalNotes: (invoice.data?.internalNotes ?? {}) as JSONContent,
+ });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -70,6 +99,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function PurchaseInvoiceBasicRoute() {
+ const { internalNotes } = useLoaderData<typeof loader>();
const { invoiceId } = useParams();
if (!invoiceId) throw new Error("invoiceId not found");
@@ -108,7 +138,7 @@ export default function PurchaseInvoiceBasicRoute() {
id={invoiceId}
title="Notes"
table="purchaseInvoice"
- internalNotes={purchaseInvoice.internalNotes as JSONContent}
+ internalNotes={internalNotes}
/>
<Suspense
key={`documents-${invoiceId}`}
diff --git a/apps/erp/app/routes/x+/purchase-order+/$orderId.details.tsx b/apps/erp/app/routes/x+/purchase-order+/$orderId.details.tsx
index a255350570..389c62b2f2 100644
--- a/apps/erp/app/routes/x+/purchase-order+/$orderId.details.tsx
+++ b/apps/erp/app/routes/x+/purchase-order+/$orderId.details.tsx
@@ -12,6 +12,7 @@ import { Suspense } from "react";
import { useRouteData } from "~/hooks";
import type { PurchaseOrder, PurchaseOrderLine } from "~/modules/purchasing";
import {
+ getPurchaseOrder,
getPurchaseOrderDelivery,
getPurchaseOrderPayment,
purchaseOrderValidator,
@@ -37,10 +38,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const { orderId } = params;
if (!orderId) throw new Error("Could not find orderId");
- const [purchaseOrderDelivery, purchaseOrderPayment] = await Promise.all([
- getPurchaseOrderDelivery(client, orderId),
- getPurchaseOrderPayment(client, orderId),
- ]);
+ const [purchaseOrder, purchaseOrderDelivery, purchaseOrderPayment] =
+ await Promise.all([
+ getPurchaseOrder(client, orderId),
+ getPurchaseOrderDelivery(client, orderId),
+ getPurchaseOrderPayment(client, orderId),
+ ]);
if (purchaseOrderDelivery.error) {
throw redirect(
@@ -71,6 +74,8 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return json({
purchaseOrderDelivery: purchaseOrderDelivery.data,
purchaseOrderPayment: purchaseOrderPayment.data,
+ internalNotes: (purchaseOrder.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (purchaseOrder.data?.externalNotes ?? {}) as JSONContent,
});
}
@@ -117,8 +122,12 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function PurchaseOrderBasicRoute() {
- const { purchaseOrderDelivery, purchaseOrderPayment } =
- useLoaderData<typeof loader>();
+ const {
+ purchaseOrderDelivery,
+ purchaseOrderPayment,
+ internalNotes,
+ externalNotes,
+ } = useLoaderData<typeof loader>();
const { orderId } = useParams();
if (!orderId) throw new Error("Could not find orderId");
@@ -180,8 +189,8 @@ export default function PurchaseOrderBasicRoute() {
id={orderData.purchaseOrder.id}
title="Notes"
table="purchaseOrder"
- internalNotes={orderData.purchaseOrder.internalNotes as JSONContent}
- externalNotes={orderData.purchaseOrder.externalNotes as JSONContent}
+ internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
<Suspense
key={`documents-${orderId}`}
diff --git a/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx b/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx
index 66e6bddc7c..e439920bb6 100644
--- a/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx
+++ b/apps/erp/app/routes/x+/quote+/$quoteId.details.tsx
@@ -2,11 +2,12 @@ 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 { Spinner, type JSONContent } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
+import type { JSONContent } from "@carbon/react";
+import { Spinner } from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { useRouteData } from "~/hooks";
import type {
@@ -15,7 +16,7 @@ import type {
QuotationPayment,
QuotationShipment,
} from "~/modules/sales";
-import { quoteValidator, upsertQuote } from "~/modules/sales";
+import { getQuote, quoteValidator, upsertQuote } from "~/modules/sales";
import {
OpportunityDocuments,
OpportunityNotes,
@@ -29,6 +30,33 @@ import {
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ internalNotes: JSONContent;
+ externalNotes: JSONContent;
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "sales",
+ });
+
+ const { quoteId } = params;
+ if (!quoteId) throw new Error("Could not find quoteId");
+
+ const quote = await getQuote(client, quoteId);
+ if (quote.error) {
+ throw redirect(
+ path.to.quotes,
+ await flash(request, error(quote.error, "Failed to load quote"))
+ );
+ }
+
+ return json<LoaderData>({
+ internalNotes: (quote.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (quote.data?.externalNotes ?? {}) as JSONContent,
+ });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -69,12 +97,13 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function QuoteDetailsRoute() {
+ const { internalNotes, externalNotes } = useLoaderData<typeof loader>();
const { quoteId } = useParams();
if (!quoteId) throw new Error("Could not find quoteId");
const quoteData = useRouteData<{
quote: Quotation;
- files: Promise<(FileObject & { quoteLineId: string | null })[]>;
+ files: Promise<FileObject[]>;
shipment: QuotationShipment;
payment: QuotationPayment;
opportunity: Opportunity;
@@ -129,8 +158,8 @@ export default function QuoteDetailsRoute() {
id={quoteData.quote.id}
title="Notes"
table="quote"
- internalNotes={quoteData.quote.internalNotes as JSONContent}
- externalNotes={quoteData.quote.externalNotes as JSONContent}
+ internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
<Suspense
key={`documents-${quoteId}`}
diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.details.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.details.tsx
index 1bbf54e155..7d34b7fe29 100644
--- a/apps/erp/app/routes/x+/sales-order+/$orderId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.details.tsx
@@ -1,15 +1,19 @@
+import { assertIsPost, error, success } from "@carbon/auth";
+import { requirePermissions } from "@carbon/auth/auth.server";
+import { flash } from "@carbon/auth/session.server";
+import type { Database } from "@carbon/database";
import { validationError, validator } from "@carbon/form";
+import { Spinner } from "@carbon/react";
import { Await, useLoaderData, useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
+import type { JSONContent } from "@tiptap/react";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
import { json, redirect } from "@vercel/remix";
+import { Suspense } from "react";
import { useRouteData } from "~/hooks";
-import { getPaymentTermsList } from "~/modules/accounting";
-import { getShippingMethodsList } from "~/modules/inventory";
import type { Opportunity, SalesOrder, SalesOrderLine } from "~/modules/sales";
import {
- getOpportunityBySalesOrder,
- getQuote,
+ getSalesOrder,
getSalesOrderPayment,
getSalesOrderShipment,
salesOrderValidator,
@@ -25,70 +29,59 @@ import {
SalesOrderShipmentForm,
SalesOrderSummary,
} from "~/modules/sales/ui/SalesOrder";
-
-import { assertIsPost, error, success } from "@carbon/auth";
-import { requirePermissions } from "@carbon/auth/auth.server";
-import { flash } from "@carbon/auth/session.server";
-import { Spinner, type JSONContent } from "@carbon/react";
-import { Suspense } from "react";
import { getCustomFields, setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ internalNotes: JSONContent;
+ externalNotes: JSONContent;
+ payment: Database["public"]["Tables"]["salesOrderPayment"]["Row"];
+ shipment: Database["public"]["Tables"]["salesOrderShipment"]["Row"];
+};
+
export async function loader({ request, params }: LoaderFunctionArgs) {
- const { client, companyId } = await requirePermissions(request, {
+ const { client } = await requirePermissions(request, {
view: "sales",
});
const { orderId } = params;
if (!orderId) throw new Error("Could not find orderId");
- const [
- salesOrderShipment,
- salesOrderPayment,
-
- // shippingTerms,
- ] = await Promise.all([
- getSalesOrderShipment(client, orderId),
+ const [order, payment, shipment] = await Promise.all([
+ getSalesOrder(client, orderId),
getSalesOrderPayment(client, orderId),
- getPaymentTermsList(client, companyId),
- getShippingMethodsList(client, companyId),
- // getShippingTermsList(client, companyId),
+ getSalesOrderShipment(client, orderId),
]);
- if (salesOrderShipment.error) {
- // TODO: insert a salesOrderShipment record
+ if (order.error) {
throw redirect(
path.to.salesOrders,
- await flash(
- request,
- error(salesOrderShipment.error, "Failed to load sales order shipment")
- )
+ await flash(request, error(order.error, "Failed to load order"))
);
}
- if (salesOrderPayment.error) {
- // TODO: insert a salesOrderPayment record
+ if (payment.error) {
+ throw redirect(
+ path.to.salesOrders,
+ await flash(request, error(payment.error, "Failed to load order payment"))
+ );
+ }
+
+ if (shipment.error) {
throw redirect(
path.to.salesOrders,
await flash(
request,
- error(salesOrderPayment.error, "Failed to load sales order payment")
+ error(shipment.error, "Failed to load order shipment")
)
);
}
- const opportunity = await getOpportunityBySalesOrder(client, orderId);
- const originatedFromQuote = opportunity.data?.quoteId !== null;
- const quote = opportunity.data?.quoteId
- ? await getQuote(client, opportunity.data.quoteId)
- : null;
-
- return json({
- salesOrderShipment: salesOrderShipment.data,
- salesOrderPayment: salesOrderPayment.data,
- originatedFromQuote,
- quote,
- // shippingTerms: shippingTerms.data ?? [],
+ return json<LoaderData>({
+ internalNotes: (order.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (order.data?.externalNotes ?? {}) as JSONContent,
+ payment: payment.data || null,
+ shipment: shipment.data || null,
});
}
@@ -98,8 +91,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
update: "sales",
});
- const { orderId } = params;
- if (!orderId) throw new Error("Could not find orderId");
+ const { orderId: id } = params;
+ if (!id) throw new Error("Could not find id");
const formData = await request.formData();
const validation = await validator(salesOrderValidator).validate(formData);
@@ -111,33 +104,29 @@ export async function action({ request, params }: ActionFunctionArgs) {
const { salesOrderId, ...data } = validation.data;
if (!salesOrderId) throw new Error("Could not find salesOrderId");
- const updateSalesOrder = await upsertSalesOrder(client, {
- id: orderId,
+ const update = await upsertSalesOrder(client, {
+ id,
salesOrderId,
...data,
- updatedBy: userId,
customFields: setCustomFields(formData),
+ updatedBy: userId,
});
- if (updateSalesOrder.error) {
+ if (update.error) {
throw redirect(
- path.to.salesOrder(orderId),
- await flash(
- request,
- error(updateSalesOrder.error, "Failed to update sales order")
- )
+ path.to.salesOrder(id),
+ await flash(request, error(update.error, "Failed to update order"))
);
}
throw redirect(
- path.to.salesOrder(orderId),
- await flash(request, success("Updated sales order"))
+ path.to.salesOrder(id),
+ await flash(request, success("Updated order"))
);
}
-export default function SalesOrderRoute() {
- const { salesOrderShipment, salesOrderPayment } =
+export default function SalesOrderDetailsRoute() {
+ const { internalNotes, externalNotes, payment, shipment } =
useLoaderData<typeof loader>();
-
const { orderId } = useParams();
if (!orderId) throw new Error("Could not find orderId");
@@ -147,52 +136,55 @@ export default function SalesOrderRoute() {
opportunity: Opportunity;
files: Promise<FileObject[]>;
}>(path.to.salesOrder(orderId));
+
if (!orderData) throw new Error("Could not find order data");
const shipmentInitialValues = {
- id: salesOrderShipment.id,
- locationId: salesOrderShipment.locationId ?? "",
- shippingMethodId: salesOrderShipment.shippingMethodId ?? "",
- shippingTermId: salesOrderShipment.shippingTermId ?? "",
- trackingNumber: salesOrderShipment.trackingNumber ?? "",
- receiptRequestedDate: salesOrderShipment.receiptRequestedDate ?? "",
- receiptPromisedDate: salesOrderShipment.receiptPromisedDate ?? "",
- deliveryDate: salesOrderShipment.deliveryDate ?? "",
- notes: salesOrderShipment.notes ?? "",
- dropShipment: salesOrderShipment.dropShipment ?? false,
- customerId: salesOrderShipment.customerId ?? "",
- customerLocationId: salesOrderShipment.customerLocationId ?? "",
- shippingCost: salesOrderShipment.shippingCost ?? 0,
- ...getCustomFields(salesOrderShipment.customFields),
+ id: shipment.id,
+ locationId: shipment?.locationId ?? "",
+ shippingMethodId: shipment?.shippingMethodId ?? "",
+ shippingTermId: shipment?.shippingTermId ?? "",
+ trackingNumber: shipment?.trackingNumber ?? "",
+ receiptRequestedDate: shipment?.receiptRequestedDate ?? "",
+ receiptPromisedDate: shipment?.receiptPromisedDate ?? "",
+ deliveryDate: shipment?.deliveryDate ?? "",
+ notes: shipment?.notes ?? "",
+ dropShipment: shipment?.dropShipment ?? false,
+ customerId: shipment?.customerId ?? "",
+ customerLocationId: shipment?.customerLocationId ?? "",
+ shippingCost: shipment?.shippingCost ?? 0,
+ ...getCustomFields(shipment?.customFields),
};
const paymentInitialValues = {
- ...salesOrderPayment,
- invoiceCustomerId: salesOrderPayment.invoiceCustomerId ?? "",
- invoiceCustomerLocationId:
- salesOrderPayment.invoiceCustomerLocationId ?? "",
- invoiceCustomerContactId: salesOrderPayment.invoiceCustomerContactId ?? "",
- paymentTermId: salesOrderPayment.paymentTermId ?? "",
- ...getCustomFields(salesOrderPayment.customFields),
+ id: payment.id,
+ invoiceCustomerId: payment?.invoiceCustomerId ?? "",
+ invoiceCustomerLocationId: payment?.invoiceCustomerLocationId ?? "",
+ invoiceCustomerContactId: payment?.invoiceCustomerContactId ?? "",
+ paymentTermId: payment?.paymentTermId ?? "",
+ paymentComplete: payment?.paymentComplete ?? undefined,
+ ...getCustomFields(payment?.customFields),
};
return (
<>
- <OpportunityState opportunity={orderData.opportunity} />
+ <OpportunityState
+ key={`state-${orderId}`}
+ opportunity={orderData?.opportunity!}
+ />
<SalesOrderSummary />
<OpportunityNotes
key={`notes-${orderId}`}
id={orderData.salesOrder.id}
table="salesOrder"
title="Notes"
- internalNotes={orderData.salesOrder.internalNotes as JSONContent}
- externalNotes={orderData.salesOrder.externalNotes as JSONContent}
+ internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
-
<Suspense
key={`documents-${orderId}`}
fallback={
- <div className="flex w-full min-h-[480px] h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
+ <div className="flex w-full min-h-[480px] h-full rounded bg-gradient-to-tr from-background to-card items-center justify-center">
<Spinner className="h-10 w-10" />
</div>
}
diff --git a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.details.tsx b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.details.tsx
index d90bbb12fe..cf1ae0216d 100644
--- a/apps/erp/app/routes/x+/sales-rfq+/$rfqId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-rfq+/$rfqId.details.tsx
@@ -4,14 +4,18 @@ import { flash } from "@carbon/auth/session.server";
import { validationError, validator } from "@carbon/form";
import type { JSONContent } from "@carbon/react";
import { Spinner, VStack } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { useRouteData } from "~/hooks";
import type { Opportunity, SalesRFQ, SalesRFQLine } from "~/modules/sales";
-import { salesRfqValidator, upsertSalesRFQ } from "~/modules/sales";
+import {
+ getSalesRFQ,
+ salesRfqValidator,
+ upsertSalesRFQ,
+} from "~/modules/sales";
import {
OpportunityDocuments,
OpportunityNotes,
@@ -20,6 +24,33 @@ import {
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ internalNotes: JSONContent;
+ externalNotes: JSONContent;
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "sales",
+ });
+
+ const { rfqId } = params;
+ if (!rfqId) throw new Error("Could not find rfqId");
+
+ const rfq = await getSalesRFQ(client, rfqId);
+ if (rfq.error) {
+ throw redirect(
+ path.to.salesRfqs,
+ await flash(request, error(rfq.error, "Failed to load RFQ"))
+ );
+ }
+
+ return json<LoaderData>({
+ internalNotes: (rfq.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (rfq.data?.externalNotes ?? {}) as JSONContent,
+ });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -60,6 +91,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function SalesRFQDetailsRoute() {
+ const { internalNotes, externalNotes } = useLoaderData<typeof loader>();
const { rfqId } = useParams();
if (!rfqId) throw new Error("Could not find rfqId");
@@ -83,8 +115,8 @@ export default function SalesRFQDetailsRoute() {
id={rfqData.rfqSummary.id}
table="salesRfq"
title="Notes"
- internalNotes={rfqData.rfqSummary.internalNotes as JSONContent}
- externalNotes={rfqData.rfqSummary.externalNotes as JSONContent}
+ internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
<Suspense
key={`documents-${rfqId}`}
diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.details.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.details.tsx
index d21523ad43..31b1c54428 100644
--- a/apps/erp/app/routes/x+/supplier-quote+/$id.details.tsx
+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.details.tsx
@@ -2,14 +2,16 @@ 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 { Spinner, type JSONContent } from "@carbon/react";
-import { Await, useParams } from "@remix-run/react";
+import type { JSONContent } from "@carbon/react";
+import { Spinner } from "@carbon/react";
+import { Await, useLoaderData, useParams } from "@remix-run/react";
import type { FileObject } from "@supabase/storage-js";
-import type { ActionFunctionArgs } from "@vercel/remix";
-import { redirect } from "@vercel/remix";
+import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";
+import { json, redirect } from "@vercel/remix";
import { Suspense } from "react";
import { useRouteData } from "~/hooks";
import {
+ getSupplierQuote,
supplierQuoteValidator,
upsertSupplierQuote,
} from "~/modules/purchasing";
@@ -25,6 +27,33 @@ import SupplierQuoteSummary from "~/modules/purchasing/ui/SupplierQuote/Supplier
import { setCustomFields } from "~/utils/form";
import { path } from "~/utils/path";
+type LoaderData = {
+ internalNotes: JSONContent;
+ externalNotes: JSONContent;
+};
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "purchasing",
+ });
+
+ const { id } = params;
+ if (!id) throw new Error("Could not find id");
+
+ const quote = await getSupplierQuote(client, id);
+ if (quote.error) {
+ throw redirect(
+ path.to.supplierQuotes,
+ await flash(request, error(quote.error, "Failed to load supplier quote"))
+ );
+ }
+
+ return json<LoaderData>({
+ internalNotes: (quote.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (quote.data?.externalNotes ?? {}) as JSONContent,
+ });
+}
+
export async function action({ request, params }: ActionFunctionArgs) {
assertIsPost(request);
const { client, userId } = await requirePermissions(request, {
@@ -65,6 +94,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
}
export default function SupplierQuoteDetailsRoute() {
+ const { internalNotes, externalNotes } = useLoaderData<typeof loader>();
const { id } = useParams();
if (!id) throw new Error("Could not find id");
@@ -98,8 +128,8 @@ export default function SupplierQuoteDetailsRoute() {
id={routeData.quote.id}
title="Notes"
table="supplierQuote"
- internalNotes={routeData.quote.internalNotes as JSONContent}
- externalNotes={routeData.quote.externalNotes as JSONContent}
+ internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
<Suspense
key={`documents-${id}`}