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: custom fields for customer contact form

Brad Barbin968c54d53517
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsx
index f572445318..c6d6a15b7b 100644
--- a/apps/carbon/app/components/Search/Search/Search.tsx
+++ b/apps/carbon/app/components/Search/Search/Search.tsx
@@ -19,6 +19,7 @@ import {
} from "@carbon/react";
import { useNavigate } from "@remix-run/react";
import idb from "localforage";
+import { nanoid } from "nanoid";
import { useCallback, useEffect, useState } from "react";
import { AiOutlinePartition } from "react-icons/ai";
import { BiListCheck } from "react-icons/bi";
@@ -153,15 +154,15 @@ const SearchModal = ({
onValueChange={onInputChange}
/>
<CommandList>
- <CommandEmpty>
+ <CommandEmpty key="empty">
{loading ? "Loading..." : "No results found."}
</CommandEmpty>
{recentResults.length > 0 && (
<>
- <CommandGroup heading="Recent Searches">
+ <CommandGroup heading="Recent Searches" key="recent">
{recentResults.map((result, index) => (
<CommandItem
- key={`${result.to}-${index}`}
+ key={`${result.to}-${nanoid()}-${index}`}
onSelect={() => onSelect(result)}
// append with : so we're not sharing a value with a static result
value={`:${result.to}`}
@@ -176,7 +177,7 @@ const SearchModal = ({
)}
{Object.entries(staticResults).map(([module, submodules]) => (
<>
- <CommandGroup heading={module} key={module}>
+ <CommandGroup heading={module} key={`static-${module}`}>
{submodules.map((submodule, index) => (
<CommandItem
key={`${submodule.to}-${submodule.name}-${index}`}
@@ -194,10 +195,10 @@ const SearchModal = ({
</>
))}
{searchResults.length > 0 && (
- <CommandGroup heading="Search Results">
- {searchResults.map((result, index) => (
+ <CommandGroup heading="Search Results" key="search">
+ {searchResults.map((result) => (
<CommandItem
- key={`${result.id}-${index}`}
+ key={`${result.id}-${nanoid()}`}
value={`${input}${result.id}`}
onSelect={() =>
onSelect({
diff --git a/apps/carbon/app/modules/sales/sales.service.ts b/apps/carbon/app/modules/sales/sales.service.ts
index d6f5cb11d9..3de11bac72 100644
--- a/apps/carbon/app/modules/sales/sales.service.ts
+++ b/apps/carbon/app/modules/sales/sales.service.ts
@@ -112,7 +112,7 @@ export async function getCustomerContact(
return client
.from("customerContact")
.select(
- "id, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes)"
+ "*, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes)"
)
.eq("id", customerContactId)
.single();
@@ -125,7 +125,7 @@ export async function getCustomerContacts(
return client
.from("customerContact")
.select(
- "id, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes), user(id, active)"
+ "*, contact(id, firstName, lastName, email, mobilePhone, homePhone, workPhone, fax, title, addressLine1, addressLine2, city, state, postalCode, country(id, name), birthday, notes), user(id, active)"
)
.eq("customerId", customerId);
}
@@ -137,7 +137,7 @@ export async function getCustomerLocation(
return client
.from("customerLocation")
.select(
- "id, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"
+ "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"
)
.eq("id", customerContactId)
.single();
@@ -150,7 +150,7 @@ export async function getCustomerLocations(
return client
.from("customerLocation")
.select(
- "id, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"
+ "*, address(id, addressLine1, addressLine2, city, state, country(id, name), postalCode)"
)
.eq("customerId", customerId);
}
@@ -453,6 +453,7 @@ export async function insertCustomerContact(
customerContact: {
customerId: string;
contact: z.infer<typeof customerContactValidator>;
+ customFields?: Json;
}
) {
const insertContact = await client
@@ -475,6 +476,7 @@ export async function insertCustomerContact(
{
customerId: customerContact.customerId,
contactId,
+ customFields: customerContact.customFields,
},
])
.select("id")
@@ -586,26 +588,20 @@ export async function updateCustomerContact(
client: SupabaseClient<Database>,
customerContact: {
contactId: string;
- contact: {
- firstName?: string;
- lastName?: string;
- email: string;
- mobilePhone?: string;
- homePhone?: string;
- workPhone?: string;
- fax?: string;
- title?: string;
- addressLine1?: string;
- addressLine2?: string;
- city?: string;
- state?: string;
- // countryId: string;
- postalCode?: string;
- birthday?: string;
- notes?: string;
- };
+ contact: z.infer<typeof customerContactValidator>;
+ customFields?: Json;
}
) {
+ if (customerContact.customFields) {
+ const customFieldUpdate = await client
+ .from("customerContact")
+ .update({ customFields: customerContact.customFields })
+ .eq("contactId", customerContact.contactId);
+
+ if (customFieldUpdate.error) {
+ return customFieldUpdate;
+ }
+ }
return client
.from("contact")
.update(sanitize(customerContact.contact))
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
index 0a7e704d7e..509866fea5 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.$customerContactId.tsx
@@ -2,6 +2,7 @@ import { validationError, validator } from "@carbon/remix-validated-form";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { useLoaderData, useNavigate, useParams } from "@remix-run/react";
+
import {
CustomerContactForm,
customerContactValidator,
@@ -10,6 +11,7 @@ import {
} from "~/modules/sales";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
+import { getCustomFields, setCustomFields } from "~/utils/form";
import { assertIsPost, badRequest, notFound } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -49,8 +51,9 @@ export async function action({ request, params }: ActionFunctionArgs) {
if (!customerId) throw notFound("customerId not found");
if (!customerContactId) throw notFound("customerContactId not found");
+ const formData = await request.formData();
const validation = await validator(customerContactValidator).validate(
- await request.formData()
+ formData
);
if (validation.error) {
@@ -68,6 +71,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const update = await updateCustomerContact(client, {
contactId,
contact,
+ customFields: setCustomFields(formData),
});
if (update.error) {
@@ -110,6 +114,7 @@ export default function EditCustomerContactRoute() {
state: contact?.contact?.state ?? "",
postalCode: contact?.contact?.postalCode ?? "",
birthday: contact?.contact?.birthday ?? undefined,
+ ...getCustomFields(contact?.customFields),
};
return (
diff --git a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
index 8bba6dfe57..c319c8cfe2 100644
--- a/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
+++ b/apps/carbon/app/routes/x+/customer+/$customerId.contacts.new.tsx
@@ -10,6 +10,7 @@ import {
} from "~/modules/sales";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session.server";
+import { setCustomFields } from "~/utils/form";
import { assertIsPost, notFound } from "~/utils/http";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
@@ -42,6 +43,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const createCustomerContact = await insertCustomerContact(client, {
customerId,
contact,
+ customFields: setCustomFields(formData),
});
if (createCustomerContact.error) {
return modal