Skip to content

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

feat: refactor receipt detail view to use the standard detail layout

Brad Barbin918726a4ca69
diff --git a/apps/carbon/app/modules/inventory/inventory.service.ts b/apps/carbon/app/modules/inventory/inventory.service.ts
index c3f70a846e..2ce33abb8a 100644
--- a/apps/carbon/app/modules/inventory/inventory.service.ts
+++ b/apps/carbon/app/modules/inventory/inventory.service.ts
@@ -56,7 +56,7 @@ export async function getReceipt(
client: SupabaseClient<Database>,
receiptId: string
) {
- return client.from("receipt").select("*").eq("id", receiptId).single();
+ return client.from("receipts").select("*").eq("id", receiptId).single();
}
export async function getReceiptLines(
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
index 7b79eddb2b..2fb86ac661 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/ReceiptForm.tsx
@@ -1,20 +1,14 @@
import {
- Button,
- Drawer,
- DrawerBody,
- DrawerContent,
- DrawerFooter,
- DrawerHeader,
- DrawerTitle,
- HStack,
- Menubar,
- MenubarItem,
+ Card,
+ CardContent,
+ CardDescription,
+ CardFooter,
+ CardHeader,
+ CardTitle,
VStack,
} from "@carbon/react";
import { ValidatedForm } from "@carbon/remix-validated-form";
-import { Outlet } from "@remix-run/react";
import type { z } from "zod";
-import { Assign, useOptimisticAssignment } from "~/components";
import {
ComboboxControlled,
CustomFormFields,
@@ -23,8 +17,7 @@ import {
Select,
Submit,
} from "~/components/Form";
-import DataGrid from "~/components/Grid";
-import { SectionTitle } from "~/components/Layout";
+import { usePermissions } from "~/hooks";
import type {
ReceiptLine,
ReceiptSourceDocument,
@@ -34,43 +27,30 @@ import {
receiptSourceDocumentType,
receiptValidator,
} from "~/modules/inventory";
-import type { Note } from "~/modules/shared";
-import { Notes } from "~/modules/shared";
import { path } from "~/utils/path";
import useReceiptForm from "./useReceiptForm";
type ReceiptFormProps = {
- assignee: string | null;
initialValues: z.infer<typeof receiptValidator>;
status: (typeof receiptStatusType)[number];
- notes: Note[];
receiptLines?: ReceiptLine[];
};
const formId = "receipt-form";
const ReceiptForm = ({
- assignee,
initialValues,
status,
- notes,
receiptLines,
}: ReceiptFormProps) => {
+ const permissions = usePermissions();
const {
- editableComponents,
locationId,
locations,
- internalReceiptLines,
- canPost,
- isDisabled,
- receiptLineColumns,
sourceDocumentId,
supplierId,
sourceDocuments,
- onClose,
- onPost,
setLocationId,
- setReceiptLines,
setSourceDocument,
setSourceDocumentId,
} = useReceiptForm({
@@ -79,146 +59,115 @@ const ReceiptForm = ({
});
const isPosted = status === "Posted";
-
- const optimisticAssignment = useOptimisticAssignment({
- id: initialValues.id,
- table: "receipt",
- });
- const optimisticAssignee =
- optimisticAssignment !== undefined ? optimisticAssignment : assignee;
+ const isEditing = initialValues.id !== undefined;
+ const locationOptions = locations.map((l) => ({
+ label: l.name,
+ value: l.id,
+ }));
return (
- <>
- <Drawer
- open
- onOpenChange={(open) => {
- if (!open) onClose();
- }}
- >
- <DrawerContent size="full">
- <DrawerHeader>
- <DrawerTitle>{initialValues.receiptId}</DrawerTitle>
- </DrawerHeader>
- <DrawerBody>
- <VStack spacing={4}>
- <Menubar className="mb-2 mt--2">
- <Assign
- id={initialValues.id}
- table="receipt"
- value={optimisticAssignee ?? undefined}
- />
- <MenubarItem isDisabled={!canPost || isPosted} onClick={onPost}>
- Post
- </MenubarItem>
- </Menubar>
-
- <div className="w-full">
- <ValidatedForm
- id={formId}
- validator={receiptValidator}
- method="post"
- action={path.to.receipt(initialValues.id)}
- defaultValues={initialValues}
- style={{ width: "100%" }}
- >
- <Hidden name="id" />
- <Hidden
- name="sourceDocumentReadableId"
- value={
- sourceDocuments.find((d) => d.id === sourceDocumentId)
- ?.name ?? ""
- }
- />
- <Hidden name="supplierId" value={supplierId ?? ""} />
- <VStack spacing={4} className="min-h-full">
- <div className="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-2 w-full">
- <Input name="receiptId" label="Receipt ID" isReadOnly />
- <ComboboxControlled
- name="locationId"
- label="Location"
- options={
- locations.map((l) => ({
- label: l.name,
- value: l.id,
- })) ?? []
- }
- value={locationId ?? undefined}
- onChange={(newValue) => {
- if (newValue) setLocationId(newValue.value as string);
- }}
- isReadOnly={isPosted}
- />
- <Select
- name="sourceDocument"
- label="Source Document"
- options={receiptSourceDocumentType.map((v) => ({
- label: v,
- value: v,
- }))}
- onChange={(newValue) => {
- if (newValue) {
- setSourceDocument(
- newValue.value as ReceiptSourceDocument
- );
- setSourceDocumentId(null);
- }
- }}
- isReadOnly={isPosted}
- />
- <ComboboxControlled
- name="sourceDocumentId"
- label="Source Document ID"
- options={sourceDocuments.map((d) => ({
- label: d.name,
- value: d.id,
- }))}
- value={sourceDocumentId ?? undefined}
- onChange={(newValue) => {
- if (newValue) {
- setSourceDocumentId(newValue.value as string);
- }
- }}
- isReadOnly={isPosted}
- />
- <Input
- name="externalDocumentId"
- label="External Reference"
- />
- <CustomFormFields table="receipt" />
- </div>
- </VStack>
- </ValidatedForm>
- </div>
+ <ValidatedForm
+ id={formId}
+ validator={receiptValidator}
+ method="post"
+ action={path.to.receiptDetails(initialValues.id)}
+ defaultValues={initialValues}
+ style={{ width: "100%" }}
+ >
+ <Card>
+ <CardHeader>
+ <CardTitle>{isEditing ? "Receipt" : "New Receipt"}</CardTitle>
+ {!isEditing && (
+ <CardDescription>
+ A receipt is a record of a part received from a supplier or
+ transfered from another location.
+ </CardDescription>
+ )}
+ </CardHeader>
+ <CardContent>
+ <Hidden name="id" />
+ <Hidden
+ name="sourceDocumentReadableId"
+ value={
+ sourceDocuments.find((d) => d.id === sourceDocumentId)?.name ?? ""
+ }
+ />
+ <Hidden name="supplierId" value={supplierId ?? ""} />
+ <VStack spacing={4} className="min-h-full">
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-2 w-full">
+ <Input name="receiptId" label="Receipt ID" isReadOnly />
+ <ComboboxControlled
+ name="locationId"
+ label="Location"
+ options={locationOptions}
+ value={locationId ?? undefined}
+ onChange={(newValue) => {
+ if (newValue) setLocationId(newValue.value as string);
+ }}
+ isReadOnly={isPosted}
+ />
+ <Select
+ name="sourceDocument"
+ label="Source Document"
+ options={receiptSourceDocumentType.map((v) => ({
+ label: v,
+ value: v,
+ }))}
+ onChange={(newValue) => {
+ if (newValue) {
+ setSourceDocument(newValue.value as ReceiptSourceDocument);
+ setSourceDocumentId(null);
+ }
+ }}
+ isReadOnly={isPosted}
+ />
+ <ComboboxControlled
+ name="sourceDocumentId"
+ label="Source Document ID"
+ options={sourceDocuments.map((d) => ({
+ label: d.name,
+ value: d.id,
+ }))}
+ value={sourceDocumentId ?? undefined}
+ onChange={(newValue) => {
+ if (newValue) {
+ setSourceDocumentId(newValue.value as string);
+ }
+ }}
+ isReadOnly={isPosted}
+ />
+ <Input name="externalDocumentId" label="External Reference" />
+ <CustomFormFields table="receipt" />
+ </div>
+ </VStack>
+ </CardContent>
+ <CardFooter>
+ <Submit
+ isDisabled={
+ isEditing
+ ? !permissions.can("update", "inventory")
+ : !permissions.can("create", "inventory")
+ }
+ >
+ Save
+ </Submit>
+ </CardFooter>
+ </Card>
+ </ValidatedForm>
- <VStack>
- <SectionTitle>Receipt Lines</SectionTitle>
- <DataGrid<ReceiptLine>
- data={internalReceiptLines}
- columns={receiptLineColumns}
- canEdit={!isPosted}
- contained={false}
- editableComponents={editableComponents}
- onDataChange={setReceiptLines}
- />
- </VStack>
- <SectionTitle>Notes</SectionTitle>
- <Notes notes={notes} documentId={initialValues.id} />
- </VStack>
- </DrawerBody>
- <DrawerFooter>
- <HStack>
- <Submit formId={formId} isDisabled={isDisabled}>
- Save
- </Submit>
- <Button size="md" variant="solid" onClick={onClose}>
- Cancel
- </Button>
- </HStack>
- </DrawerFooter>
- </DrawerContent>
- </Drawer>
- <Outlet />
- </>
+ // <VStack>
+ // <SectionTitle>Receipt Lines</SectionTitle>
+ // <DataGrid<ReceiptLine>
+ // data={internalReceiptLines}
+ // columns={receiptLineColumns}
+ // canEdit={!isPosted}
+ // contained={false}
+ // editableComponents={editableComponents}
+ // onDataChange={setReceiptLines}
+ // />
+ // </VStack>
+ // <SectionTitle>Notes</SectionTitle>
+ // <Notes notes={notes} documentId={initialValues.id} />
);
};
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/useReceiptForm.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/useReceiptForm.tsx
index 1464343c2a..58ccf67943 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/useReceiptForm.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptForm/useReceiptForm.tsx
@@ -1,4 +1,4 @@
-import { useNavigate } from "@remix-run/react";
+import { useNavigate, useParams } from "@remix-run/react";
import type { ColumnDef } from "@tanstack/react-table";
import { useCallback, useEffect, useMemo, useState } from "react";
import type { z } from "zod";
@@ -24,8 +24,12 @@ export default function useReceiptForm({
}) {
const permissions = usePermissions();
const navigate = useNavigate();
- const user = useUser();
const [params] = useUrlParams();
+ const { receiptId } = useParams();
+
+ if (!receiptId) throw new Error("receiptId not found");
+
+ const user = useUser();
const [error, setError] = useState<string | null>(null);
const { supabase } = useSupabase();
@@ -33,7 +37,9 @@ export default function useReceiptForm({
const routeData = useRouteData<{
locations: ListItem[];
- }>(path.to.receipts);
+ }>(path.to.receiptRoot);
+
+ console.log({ routeData });
const [internalReceiptLines, setReceiptLines] = useState<ReceiptLine[]>(
receiptLines ?? []
@@ -66,7 +72,6 @@ export default function useReceiptForm({
) {
await deleteReceipt();
}
-
navigate(path.to.receipts);
};
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptHeader.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptHeader.tsx
new file mode 100644
index 0000000000..bf4dbe1123
--- /dev/null
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptHeader.tsx
@@ -0,0 +1,142 @@
+import {
+ Card,
+ CardAction,
+ CardAttribute,
+ CardAttributeLabel,
+ CardAttributeValue,
+ CardAttributes,
+ CardContent,
+ CardDescription,
+ CardHeader,
+ CardTitle,
+ Enumerable,
+ HStack,
+ Menubar,
+ MenubarItem,
+ VStack,
+} from "@carbon/react";
+import { formatDate } from "@carbon/utils";
+
+import { useParams } from "@remix-run/react";
+import { Assign, EmployeeAvatar, useOptimisticAssignment } from "~/components";
+import { usePermissions, useRouteData } from "~/hooks";
+import type { Receipt, ReceiptLine } from "~/modules/inventory";
+import { ReceiptStatus } from "~/modules/inventory";
+import { path } from "~/utils/path";
+import useReceiptForm from "./ReceiptForm/useReceiptForm";
+
+const ReceiptHeader = () => {
+ const permissions = usePermissions();
+ const { receiptId } = useParams();
+ if (!receiptId) throw new Error("receiptId not found");
+
+ const routeData = useRouteData<{
+ receipt: Receipt;
+ receiptLines: ReceiptLine[];
+ }>(path.to.receipt(receiptId));
+
+ if (!routeData) throw new Error("Could not find routeData");
+
+ const { canPost, onPost } = useReceiptForm({
+ // @ts-ignore
+ receipt: routeData.receipt,
+ receiptLines: routeData.receiptLines ?? [],
+ });
+
+ const isPosted = routeData.receipt.status === "Posted";
+
+ const optimisticAssignment = useOptimisticAssignment({
+ id: receiptId,
+ table: "receipt",
+ });
+ const assignee =
+ optimisticAssignment !== undefined
+ ? optimisticAssignment
+ : routeData?.receipt?.assignee;
+
+ return (
+ <VStack>
+ {permissions.is("employee") && (
+ <Menubar>
+ <Assign
+ id={receiptId}
+ table="receipt"
+ value={routeData?.receipt?.assignee ?? ""}
+ />
+ <MenubarItem isDisabled={!canPost || isPosted} onClick={onPost}>
+ Post
+ </MenubarItem>
+ </Menubar>
+ )}
+ <Card>
+ <HStack className="justify-between items-start">
+ <CardHeader>
+ <CardTitle>{routeData?.receipt?.receiptId}</CardTitle>
+ <CardDescription>
+ {routeData?.receipt?.locationName}
+ </CardDescription>
+ </CardHeader>
+ <CardAction>
+ {/* <Button
+ variant="secondary"
+ onClick={() => alert("TODO")}
+ leftIcon={<FaHistory />}
+ >
+ View History
+ </Button> */}
+ </CardAction>
+ </HStack>
+ <CardContent>
+ <CardAttributes>
+ <CardAttribute>
+ <CardAttributeLabel>Assignee</CardAttributeLabel>
+ <CardAttributeValue>
+ {assignee ? (
+ <EmployeeAvatar employeeId={assignee ?? null} />
+ ) : (
+ "-"
+ )}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Location</CardAttributeLabel>
+ <CardAttributeValue>
+ <Enumerable value={routeData?.receipt?.locationName} />
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Source Document</CardAttributeLabel>
+ <CardAttributeValue>
+ <Enumerable
+ value={routeData?.receipt?.sourceDocument ?? null}
+ />
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Source Document ID</CardAttributeLabel>
+ <CardAttributeValue>
+ {routeData?.receipt?.sourceDocumentReadableId}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Posting Date</CardAttributeLabel>
+ <CardAttributeValue>
+ {routeData?.receipt?.postingDate
+ ? formatDate(routeData?.receipt?.postingDate)
+ : "-"}
+ </CardAttributeValue>
+ </CardAttribute>
+ <CardAttribute>
+ <CardAttributeLabel>Status</CardAttributeLabel>
+ <CardAttributeValue>
+ <ReceiptStatus status={routeData?.receipt?.status} />
+ </CardAttributeValue>
+ </CardAttribute>
+ </CardAttributes>
+ </CardContent>
+ </Card>
+ </VStack>
+ );
+};
+
+export default ReceiptHeader;
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/ReceiptSidebar.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/ReceiptSidebar.tsx
new file mode 100644
index 0000000000..87612185d0
--- /dev/null
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/ReceiptSidebar.tsx
@@ -0,0 +1,23 @@
+import { useParams } from "@remix-run/react";
+import { DetailSidebar } from "~/components/Layout";
+import { useRouteData } from "~/hooks";
+import type { ReceiptLine } from "~/modules/inventory";
+import type { Note } from "~/modules/shared";
+import { path } from "~/utils/path";
+import { useReceiptSidebar } from "./useReceiptSidebar";
+
+const ReceiptSidebar = () => {
+ const { receiptId } = useParams();
+ if (!receiptId) throw new Error("receiptId not found");
+
+ const routeData = useRouteData<{
+ receiptLines: ReceiptLine[];
+ notes: Note[];
+ }>(path.to.part(receiptId));
+
+ const links = useReceiptSidebar(routeData?.receiptLines, routeData?.notes);
+
+ return <DetailSidebar links={links} />;
+};
+
+export default ReceiptSidebar;
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/index.ts b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/index.ts
new file mode 100644
index 0000000000..54ff9d3042
--- /dev/null
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/index.ts
@@ -0,0 +1,3 @@
+import ReceiptSidebar from "./ReceiptSidebar";
+
+export default ReceiptSidebar;
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/useReceiptSidebar.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/useReceiptSidebar.tsx
new file mode 100644
index 0000000000..ea11c6b45c
--- /dev/null
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptSidebar/useReceiptSidebar.tsx
@@ -0,0 +1,46 @@
+import { useParams } from "@remix-run/react";
+import { BsBank, BsListCheck } from "react-icons/bs";
+import { PiMoneyFill } from "react-icons/pi";
+import { usePermissions } from "~/hooks";
+import type { ReceiptLine } from "~/modules/inventory/types";
+import type { Note } from "~/modules/shared";
+import type { Role } from "~/types";
+
+export function useReceiptSidebar(
+ lines: ReceiptLine[] = [],
+ notes: Note[] = []
+) {
+ const permissions = usePermissions();
+ const { receiptId } = useParams();
+ if (!receiptId) throw new Error("receiptId not found");
+
+ return [
+ {
+ name: "Details",
+ to: "details",
+ icon: BsBank,
+ shortcut: "Command+Shift+d",
+ },
+ {
+ name: "Lines",
+ to: "lines",
+ role: ["employee"],
+ count: lines.length,
+ icon: BsListCheck,
+ shortcut: "Command+Shift+l",
+ },
+
+ {
+ name: "Notes",
+ to: "notes",
+ role: ["employee"],
+ count: notes.length,
+ icon: PiMoneyFill,
+ shortcut: "Command+Shift+n",
+ },
+ ].filter(
+ (item) =>
+ item.role === undefined ||
+ item.role.some((role) => permissions.is(role as Role))
+ );
+}
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
index bc417a55fa..459db9e810 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/ReceiptsTable.tsx
@@ -48,7 +48,9 @@ const ReceiptsTable = memo(({ data, count, locations }: ReceiptsTableProps) => {
accessorKey: "receiptId",
header: "Receipt ID",
cell: ({ row }) => (
- <Hyperlink to={row.original.id!}>{row.original.receiptId}</Hyperlink>
+ <Hyperlink to={path.to.receiptDetails(row.original.id!)}>
+ {row.original.receiptId}
+ </Hyperlink>
),
},
{
@@ -238,7 +240,9 @@ const ReceiptsTable = memo(({ data, count, locations }: ReceiptsTableProps) => {
<MenuItem
disabled={!permissions.can("update", "inventory")}
onClick={() => {
- navigate(`${path.to.receipt(row.id!)}?${params.toString()}`);
+ navigate(
+ `${path.to.receiptDetails(row.id!)}?${params.toString()}`
+ );
}}
>
<MenuIcon icon={<BsFillPenFill />} />
diff --git a/apps/carbon/app/modules/inventory/ui/Receipts/index.ts b/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
index 72ecf4e6db..5b398849a1 100644
--- a/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
+++ b/apps/carbon/app/modules/inventory/ui/Receipts/index.ts
@@ -1,6 +1,15 @@
import ReceiptForm from "./ReceiptForm";
+import ReceiptHeader from "./ReceiptHeader";
import ReceiptPostModal from "./ReceiptPostModal";
-import ReceiptsTable from "./ReceiptsTable";
+import ReceiptSidebar from "./ReceiptSidebar";
import ReceiptStatus from "./ReceiptStatus";
+import ReceiptsTable from "./ReceiptsTable";
-export { ReceiptForm, ReceiptPostModal, ReceiptsTable, ReceiptStatus };
+export {
+ ReceiptForm,
+ ReceiptHeader,
+ ReceiptPostModal,
+ ReceiptSidebar,
+ ReceiptStatus,
+ ReceiptsTable,
+};
diff --git a/apps/carbon/app/routes/x+/inventory+/receipts.$receiptId.tsx b/apps/carbon/app/routes/x+/inventory+/receipts.$receiptId.tsx
index fe24f8cbf4..f0f730d8d7 100644
--- a/apps/carbon/app/routes/x+/inventory+/receipts.$receiptId.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/receipts.$receiptId.tsx
@@ -103,7 +103,7 @@ export default function EditReceiptsRoute() {
assignee={receipt.assignee}
// @ts-ignore
initialValues={initialValues}
- status={receipt.status}
+ status={receipt.status ?? "Draft"}
notes={notes}
receiptLines={receiptLines}
/>
diff --git a/apps/carbon/app/routes/x+/inventory+/receipts.new.tsx b/apps/carbon/app/routes/x+/inventory+/receipts.new.tsx
index a81044cd69..305d06ee7a 100644
--- a/apps/carbon/app/routes/x+/inventory+/receipts.new.tsx
+++ b/apps/carbon/app/routes/x+/inventory+/receipts.new.tsx
@@ -75,5 +75,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
);
}
+ console.log(`redirecting to ${path.to.receipt(insertReceipt.data.id)}`);
+
throw redirect(path.to.receipt(insertReceipt.data.id));
}
diff --git a/apps/carbon/app/routes/x+/receipt+/$receiptId._index.tsx b/apps/carbon/app/routes/x+/receipt+/$receiptId._index.tsx
new file mode 100644
index 0000000000..1a5dcab97d
--- /dev/null
+++ b/apps/carbon/app/routes/x+/receipt+/$receiptId._index.tsx
@@ -0,0 +1,9 @@
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { redirect } from "@remix-run/node";
+import { path } from "~/utils/path";
+
+export async function loader({ params }: LoaderFunctionArgs) {
+ const { receiptId } = params;
+ if (!receiptId) throw new Error("Could not find receiptId");
+ throw redirect(path.to.receiptDetails(receiptId));
+}
diff --git a/apps/carbon/app/routes/x+/receipt+/$receiptId.details.tsx b/apps/carbon/app/routes/x+/receipt+/$receiptId.details.tsx
new file mode 100644
index 0000000000..7dd8429fce
--- /dev/null
+++ b/apps/carbon/app/routes/x+/receipt+/$receiptId.details.tsx
@@ -0,0 +1,93 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import type { ActionFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { useParams } from "@remix-run/react";
+import { useRouteData } from "~/hooks";
+import type { Receipt, ReceiptLine } from "~/modules/inventory";
+import {
+ ReceiptForm,
+ receiptValidator,
+ upsertReceipt,
+} from "~/modules/inventory";
+import type { Note } from "~/modules/shared";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { getCustomFields, setCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error, success } from "~/utils/result";
+
+export async function action({ request }: ActionFunctionArgs) {
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ update: "inventory",
+ });
+
+ const formData = await request.formData();
+ const validation = await validator(receiptValidator).validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+ if (!id) throw new Error("id not found");
+
+ const updateReceipt = await upsertReceipt(client, {
+ id,
+ ...data,
+ updatedBy: userId,
+ customFields: setCustomFields(formData),
+ });
+
+ if (updateReceipt.error) {
+ return json(
+ {},
+ await flash(
+ request,
+ error(updateReceipt.error, "Failed to update receipt")
+ )
+ );
+ }
+
+ throw redirect(
+ path.to.receipt(id),
+ await flash(request, success("Updated receipt"))
+ );
+}
+
+export default function ReceiptDetailsRoute() {
+ const { receiptId } = useParams();
+ if (!receiptId) throw new Error("Could not find receiptId");
+
+ const routeData = useRouteData<{
+ receipt: Receipt;
+ receiptLines: ReceiptLine[];
+ notes: Note[];
+ }>(path.to.receipt(receiptId));
+
+ if (!routeData?.receipt)
+ throw new Error("Could not find receipt in routeData");
+
+ const initialValues = {
+ ...routeData.receipt,
+ receiptId: routeData.receipt.receiptId ?? undefined,
+ externalDocumentId: routeData.receipt.externalDocumentId ?? undefined,
+ sourceDocument: (routeData.receipt.sourceDocument ??
+ "Purchase Order") as "Purchase Order",
+ sourceDocumentId: routeData.receipt.sourceDocumentId ?? undefined,
+ sourceDocumentReadbleId:
+ routeData.receipt.sourceDocumentReadableId ?? undefined,
+ locationId: routeData.receipt.locationId ?? undefined,
+ ...getCustomFields(routeData.receipt.customFields),
+ };
+
+ return (
+ <ReceiptForm
+ key={initialValues.receiptId}
+ // @ts-ignore
+ initialValues={initialValues}
+ receiptLines={routeData.receiptLines}
+ />
+ );
+}
diff --git a/apps/carbon/app/routes/x+/receipt+/$receiptId.tsx b/apps/carbon/app/routes/x+/receipt+/$receiptId.tsx
new file mode 100644
index 0000000000..3cd2f5eed6
--- /dev/null
+++ b/apps/carbon/app/routes/x+/receipt+/$receiptId.tsx
@@ -0,0 +1,54 @@
+import type { LoaderFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { Outlet } from "@remix-run/react";
+import {
+ ReceiptHeader,
+ ReceiptSidebar,
+ getReceipt,
+ getReceiptLines,
+} from "~/modules/inventory";
+import { getNotes } from "~/modules/shared";
+import { requirePermissions } from "~/services/auth";
+import { flash } from "~/services/session.server";
+import { path } from "~/utils/path";
+import { error } from "~/utils/result";
+
+export async function loader({ request, params }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "inventory",
+ });
+
+ const { receiptId } = params;
+ if (!receiptId) throw new Error("Could not find receiptId");
+
+ const [receipt, receiptLines, notes] = await Promise.all([
+ getReceipt(client, receiptId),
+ getReceiptLines(client, receiptId),
+ getNotes(client, receiptId),
+ ]);
+
+ if (receipt.error) {
+ throw redirect(
+ path.to.receipts,
+ await flash(request, error(receipt.error, "Failed to load part summary"))
+ );
+ }
+
+ return json({
+ receipt: receipt.data,
+ receiptLines: receiptLines.data ?? [],
+ notes: notes.data ?? [],
+ });
+}
+
+export default function ReceiptRoute() {
+ return (
+ <>
+ <ReceiptHeader />
+ <div className="grid grid-cols-1 md:grid-cols-[1fr_4fr] h-full w-full gap-4">
+ <ReceiptSidebar />
+ <Outlet />
+ </div>
+ </>
+ );
+}
diff --git a/apps/carbon/app/routes/x+/receipt+/_layout.tsx b/apps/carbon/app/routes/x+/receipt+/_layout.tsx
new file mode 100644
index 0000000000..69532e9fea
--- /dev/null
+++ b/apps/carbon/app/routes/x+/receipt+/_layout.tsx
@@ -0,0 +1,42 @@
+import { VStack } from "@carbon/react";
+import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
+import { Outlet } from "@remix-run/react";
+import { getUnitOfMeasuresList } from "~/modules/parts";
+import { getLocationsList } from "~/modules/resources";
+import { requirePermissions } from "~/services/auth";
+import type { Handle } from "~/utils/handle";
+import { path } from "~/utils/path";
+
+export const meta: MetaFunction = () => {
+ return [{ title: "Carbon | Receipt" }];
+};
+
+export const handle: Handle = {
+ breadcrumb: "Receipts",
+ to: path.to.receipts,
+ module: "inventory",
+};
+
+export async function loader({ request }: LoaderFunctionArgs) {
+ const { client } = await requirePermissions(request, {
+ view: "inventory",
+ });
+
+ const [unitOfMeasures, locations] = await Promise.all([
+ getUnitOfMeasuresList(client),
+ getLocationsList(client),
+ ]);
+
+ return {
+ locations: locations?.data ?? [],
+ unitOfMeasures: unitOfMeasures?.data ?? [],
+ };
+}
+
+export default function ReceiptRoute() {
+ return (
+ <VStack spacing={4} className="h-full p-4">
+ <Outlet />
+ </VStack>
+ );
+}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index ba2bfac721..56aa08e149 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -445,11 +445,13 @@ export const path = {
),
quoteRelease: (id: string) => generatePath(`${x}/quote/${id}/release`),
quotes: `${x}/sales/quotes`,
- receipt: (id: string) => generatePath(`${x}/inventory/receipts/${id}`),
+ receipt: (id: string) => generatePath(`${x}/receipt/${id}`),
+ receiptDetails: (id: string) => generatePath(`${x}/receipt/${id}/details`),
receipts: `${x}/inventory/receipts`,
receiptInvoice: (id: string) => generatePath(`${x}/receipt/${id}/invoice`),
receiptPost: (id: string) =>
generatePath(`${x}/inventory/receipts/${id}/post`),
+ receiptRoot: `${x}/receipt`,
refreshSession: "/refresh-session",
requestForQuote: (id: string) => generatePath(`${x}/rfq/${id}`),
requestForQuoteFavorite: `${x}/purchasing/rfqs/favorite`,
diff --git a/www/hooks/useWindowSize.tsx b/www/hooks/useWindowSize.tsx
index da568e10e8..105fb4967f 100644
--- a/www/hooks/useWindowSize.tsx
+++ b/www/hooks/useWindowSize.tsx
@@ -1,4 +1,7 @@
-import { useLayoutEffect, useState } from "react";
+import { useEffect, useLayoutEffect, useState } from "react";
+
+export const useIsomorphicLayoutEffect =
+ typeof window !== "undefined" ? useLayoutEffect : useEffect;
export function useWindowSize() {
const [size, setSize] = useState<{
@@ -9,7 +12,7 @@ export function useWindowSize() {
height: null,
});
- useLayoutEffect(() => {
+ useIsomorphicLayoutEffect(() => {
const handleResize = () => {
setSize({
width: window.innerWidth,