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: create a Location component that displays location name and address

Rob Carringtonc52e7ec3921e
diff --git a/apps/carbon/app/components/Address.tsx b/apps/carbon/app/components/Address.tsx
index 7c7fdde2b6..231e8828ce 100644
--- a/apps/carbon/app/components/Address.tsx
+++ b/apps/carbon/app/components/Address.tsx
@@ -1,11 +1,4 @@
-import {
- ActionMenu,
- DropdownMenuIcon,
- DropdownMenuItem,
- VStack,
-} from "@carbon/react";
-import { LuMapPin } from "react-icons/lu";
-import type { Action } from "~/types";
+import { VStack } from "@carbon/react";
type AddressProps = {
address: {
@@ -14,33 +7,21 @@ type AddressProps = {
addressLine1: string | null;
postalCode: string | null;
};
- actions: Action[];
};
-const Address = ({ address, actions }: AddressProps) => {
+const Address = ({ address }: AddressProps) => {
const location = `${address.city ?? ""}, ${address.state ?? ""}`;
const addressZip = `${address.addressLine1 ?? ""} ${
address.postalCode ?? ""
}`;
return (
- <div className="grid w-full gap-4 grid-cols-[auto_1fr_auto]">
- <LuMapPin className="w-8 h-8" />
+ <div>
<VStack spacing={0}>
<p className="font-bold line-clamp-1">{location}</p>
<p className="text-sm text-muted-foreground line-clamp-1">
{addressZip}
</p>
</VStack>
- {actions.length > 0 && (
- <ActionMenu>
- {actions.map((action) => (
- <DropdownMenuItem key={action.label} onClick={action.onClick}>
- {action.icon && <DropdownMenuIcon icon={action.icon} />}
- {action.label}
- </DropdownMenuItem>
- ))}
- </ActionMenu>
- )}
</div>
);
};
diff --git a/apps/carbon/app/components/Location.tsx b/apps/carbon/app/components/Location.tsx
new file mode 100644
index 0000000000..8e90cecfc9
--- /dev/null
+++ b/apps/carbon/app/components/Location.tsx
@@ -0,0 +1,54 @@
+import {
+ ActionMenu,
+ DropdownMenuIcon,
+ DropdownMenuItem,
+ VStack,
+} from "@carbon/react";
+import { LuMapPin } from "react-icons/lu";
+import type { Action } from "~/types";
+
+type LocationProps = {
+ location: {
+ name: string;
+ address: {
+ city: string | null;
+ state: string | null;
+ addressLine1: string | null;
+ postalCode: string | null;
+ };
+ };
+ actions: Action[];
+};
+
+const Location = ({ location, actions }: LocationProps) => {
+ const cityStateJoined = `${location.address.city ?? ""}, ${
+ location.address.state ?? ""
+ }`;
+ const addressZip = `${location.address.addressLine1 ?? ""} ${
+ location.address.postalCode ?? ""
+ }`;
+ return (
+ <div className="grid w-full gap-4 grid-cols-[auto_1fr_auto]">
+ <LuMapPin className="w-8 h-8" />
+ <p className="font-bold line-clamp-1">{location.name}</p>
+ <VStack spacing={0}>
+ <p className="font-bold line-clamp-1">{cityStateJoined}</p>
+ <p className="text-sm text-muted-foreground line-clamp-1">
+ {addressZip}
+ </p>
+ </VStack>
+ {actions.length > 0 && (
+ <ActionMenu>
+ {actions.map((action) => (
+ <DropdownMenuItem key={action.label} onClick={action.onClick}>
+ {action.icon && <DropdownMenuIcon icon={action.icon} />}
+ {action.label}
+ </DropdownMenuItem>
+ ))}
+ </ActionMenu>
+ )}
+ </div>
+ );
+};
+
+export default Location;
diff --git a/apps/carbon/app/components/index.ts b/apps/carbon/app/components/index.ts
index ed50afccc6..02ac61d888 100644
--- a/apps/carbon/app/components/index.ts
+++ b/apps/carbon/app/components/index.ts
@@ -11,6 +11,7 @@ import EmployeeAvatar from "./EmployeeAvatar";
import EmployeeAvatarGroup from "./EmployeeAvatarGroup";
import Empty from "./Empty";
import Hyperlink from "./Hyperlink";
+import Location from "./Location";
import MultiSelect from "./MultiSelect";
import New from "./New";
import Select from "./Select";
@@ -34,6 +35,7 @@ export {
EmployeeAvatarGroup,
Empty,
Hyperlink,
+ Location,
MultiSelect,
New,
Select,
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
index bb2ee896fb..ac97aa143c 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierLocations.tsx
@@ -11,7 +11,7 @@ import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { IoMdAdd } from "react-icons/io";
import { LuPencil, LuTrash } from "react-icons/lu";
-import { Address, New } from "~/components";
+import { Location, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { SupplierLocation } from "~/modules/purchasing/types";
@@ -93,8 +93,8 @@ const SupplierLocations = ({ locations }: SupplierLocationsProps) => {
{locations?.map((location) => (
<li key={location.id}>
{location.address && !Array.isArray(location.address) ? (
- <Address
- address={location.address}
+ <Location
+ location={location}
actions={getActions(location)}
/>
) : null}
diff --git a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
index 4752444a91..bd5beaed39 100644
--- a/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
+++ b/apps/carbon/app/modules/sales/ui/Customer/CustomerLocations.tsx
@@ -10,7 +10,7 @@ import {
import { Outlet, useNavigate, useParams } from "@remix-run/react";
import { useCallback, useState } from "react";
import { LuPencil, LuTrash } from "react-icons/lu";
-import { Address, New } from "~/components";
+import { Location, New } from "~/components";
import { ConfirmDelete } from "~/components/Modals";
import { usePermissions } from "~/hooks";
import type { CustomerLocation } from "~/modules/sales";
@@ -80,8 +80,8 @@ const CustomerLocations = ({ locations }: CustomerLocationsProps) => {
{locations?.map((location) => (
<li key={location.id}>
{location.address && !Array.isArray(location.address) ? (
- <Address
- address={location.address}
+ <Location
+ location={location}
actions={getActions(location)}
/>
) : null}