Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Convert configuration values to key value

François Zaninotto0c06d830b737
diff --git a/doc/src/content/docs/developers/customizing.mdx b/doc/src/content/docs/developers/customizing.mdx
index ed5f40d5..adfce60e 100644
--- a/doc/src/content/docs/developers/customizing.mdx
+++ b/doc/src/content/docs/developers/customizing.mdx
@@ -26,8 +26,14 @@ import { CRM } from "@/components/atomic-crm/root/CRM";
const App = () => (
<CRM
- companySectors={['Technology', 'Finance']}
- dealCategories={['Copywriting', 'Design']}
+ companySectors={[
+ { value: 'technology', label: 'Technology' },
+ { value: 'finance', label: 'Finance' },
+ ]}
+ dealCategories={[
+ { value: 'copywriting', label: 'Copywriting' },
+ { value: 'design', label: 'Design' },
+ ]}
dealPipelineStatuses={['won']}
dealStages={[
{ value: 'opportunity', label: 'Opportunity' },
@@ -40,7 +46,11 @@ const App = () => (
{ value: 'warm', label: 'Warm', color: '#e8cb7d' },
{ value: 'hot', label: 'Hot', color: '#e88b7d' },
]}
- taskTypes={['Call', 'Email', 'Meeting']}
+ taskTypes={[
+ { value: 'call', label: 'Call' },
+ { value: 'email', label: 'Email' },
+ { value: 'meeting', label: 'Meeting' },
+ ]}
/>
);
@@ -51,15 +61,15 @@ export default App;
| Props | Description | Type |
|-------------------------|-----------------------------------------------------------------------|-----------------|
-| `companySectors` | The list of company sectors used in the application. | string[] |
+| `companySectors` | The list of company sectors used in the application. | LabeledValue[] |
| `darkTheme` | The theme to use when the application is in dark mode. | RaThemeOptions |
-| `dealCategories` | The categories of deals used in the application. | string[] |
+| `dealCategories` | The categories of deals used in the application. | LabeledValue[] |
| `dealPipelineStatuses` | The statuses of deals in the pipeline used in the application | string[] |
| `dealStages` | The stages of deals used in the application. | DealStage[] |
| `lightTheme` | The theme to use when the application is in light mode. | RaThemeOptions |
| `logo` | The logo used in the CRM application. | string |
| `noteStatuses` | The statuses of notes used in the application. | NoteStatus[] |
-| `taskTypes` | The types of tasks used in the application. | string[] |
+| `taskTypes` | The types of tasks used in the application. | LabeledValue[] |
| `title` | The title of the CRM application. | string |
## Disabling Telemetry
diff --git a/doc/src/content/docs/index.mdx b/doc/src/content/docs/index.mdx
index d4dc0c09..e36812e3 100644
--- a/doc/src/content/docs/index.mdx
+++ b/doc/src/content/docs/index.mdx
@@ -102,8 +102,16 @@ import { CRM } from "@/components/atomic-crm/root/CRM";
const App = () => (
<CRM
title="Acme CRM"
- taskTypes={['Call', 'Email', 'Meeting']}
- dealCategories={['eCommerce', 'SaaS', 'Consulting']}
+ taskTypes={[
+ { value: 'call', label: 'Call' },
+ { value: 'email', label: 'Email' },
+ { value: 'meeting', label: 'Meeting' },
+ ]}
+ dealCategories={[
+ { value: 'ecommerce', label: 'eCommerce' },
+ { value: 'saas', label: 'SaaS' },
+ { value: 'consulting', label: 'Consulting' },
+ ]}
/>
);
diff --git a/src/components/atomic-crm/companies/CompanyAside.tsx b/src/components/atomic-crm/companies/CompanyAside.tsx
index 612d4f7f..d0b712b6 100644
--- a/src/components/atomic-crm/companies/CompanyAside.tsx
+++ b/src/components/atomic-crm/companies/CompanyAside.tsx
@@ -10,6 +10,7 @@ import { UrlField } from "@/components/admin/url-field";
import { SelectField } from "@/components/admin/select-field";
import { AsideSection } from "../misc/AsideSection";
+import { useConfigurationContext } from "../root/ConfigurationContext";
import { SaleName } from "../sales/SaleName";
import type { Company } from "../types";
import { sizes } from "./sizes";
@@ -97,17 +98,18 @@ export const CompanyInfo = ({ record }: { record: Company }) => {
};
export const ContextInfo = ({ record }: { record: Company }) => {
+ const { companySectors } = useConfigurationContext();
if (!record.revenue && !record.id) {
return null;
}
+ const sectorLabel = companySectors.find(
+ (s) => s.value === record.sector,
+ )?.label;
+
return (
<AsideSection title="Context">
- {record.sector && (
- <span>
- Sector: <TextField source="sector" />
- </span>
- )}
+ {sectorLabel && <span>Sector: {sectorLabel}</span>}
{record.size && (
<span>
Size: <SelectField source="size" choices={sizes} />
diff --git a/src/components/atomic-crm/companies/CompanyCard.tsx b/src/components/atomic-crm/companies/CompanyCard.tsx
index 25dbf88a..faa33317 100644
--- a/src/components/atomic-crm/companies/CompanyCard.tsx
+++ b/src/components/atomic-crm/companies/CompanyCard.tsx
@@ -5,14 +5,20 @@ import { ReferenceManyField } from "@/components/admin/reference-many-field";
import { Card } from "@/components/ui/card";
import { Avatar as ContactAvatar } from "../contacts/Avatar";
+import { useConfigurationContext } from "../root/ConfigurationContext";
import type { Company } from "../types";
import { CompanyAvatar } from "./CompanyAvatar";
export const CompanyCard = (props: { record?: Company }) => {
const createPath = useCreatePath();
const record = useRecordContext<Company>(props);
+ const { companySectors } = useConfigurationContext();
if (!record) return null;
+ const sectorLabel = companySectors.find(
+ (s) => s.value === record.sector,
+ )?.label;
+
return (
<Link
to={createPath({
@@ -27,7 +33,7 @@ export const CompanyCard = (props: { record?: Company }) => {
<CompanyAvatar />
<div className="text-center mt-1">
<h6 className="text-sm font-medium">{record.name}</h6>
- <p className="text-xs text-muted-foreground">{record.sector}</p>
+ <p className="text-xs text-muted-foreground">{sectorLabel}</p>
</div>
</div>
<div className="flex flex-row w-full justify-between gap-2">
diff --git a/src/components/atomic-crm/companies/CompanyInputs.tsx b/src/components/atomic-crm/companies/CompanyInputs.tsx
index 4867b1cb..5c819c0c 100644
--- a/src/components/atomic-crm/companies/CompanyInputs.tsx
+++ b/src/components/atomic-crm/companies/CompanyInputs.tsx
@@ -90,10 +90,9 @@ const CompanyContextInputs = () => {
<h6 className="text-lg font-semibold">Context</h6>
<SelectInput
source="sector"
- choices={companySectors.map((sector) => ({
- id: sector,
- name: sector,
- }))}
+ choices={companySectors}
+ optionText="label"
+ optionValue="value"
helperText={false}
/>
<SelectInput source="size" choices={sizes} helperText={false} />
diff --git a/src/components/atomic-crm/companies/CompanyListFilter.tsx b/src/components/atomic-crm/companies/CompanyListFilter.tsx
index f5275b00..000ab81b 100644
--- a/src/components/atomic-crm/companies/CompanyListFilter.tsx
+++ b/src/components/atomic-crm/companies/CompanyListFilter.tsx
@@ -10,10 +10,6 @@ import { sizes } from "./sizes";
export const CompanyListFilter = () => {
const { identity } = useGetIdentity();
const { companySectors } = useConfigurationContext();
- const sectors = companySectors.map((sector) => ({
- id: sector,
- name: sector,
- }));
return (
<div className="w-52 min-w-52 flex flex-col gap-8">
<FilterLiveForm>
@@ -32,12 +28,12 @@ export const CompanyListFilter = () => {
</FilterCategory>
<FilterCategory icon={<Truck className="h-4 w-4" />} label="Sector">
- {sectors.map((sector) => (
+ {companySectors.map((sector) => (
<ToggleFilterButton
className="w-full justify-between"
- label={sector.name}
- key={sector.name}
- value={{ sector: sector.id }}
+ label={sector.label}
+ key={sector.value}
+ value={{ sector: sector.value }}
/>
))}
</FilterCategory>
diff --git a/src/components/atomic-crm/companies/CompanyShow.tsx b/src/components/atomic-crm/companies/CompanyShow.tsx
index e0532f9b..e726578a 100644
--- a/src/components/atomic-crm/companies/CompanyShow.tsx
+++ b/src/components/atomic-crm/companies/CompanyShow.tsx
@@ -248,7 +248,7 @@ const CreateRelatedContactButton = () => {
const DealsIterator = () => {
const { data: deals, error, isPending } = useListContext<Deal>();
- const { dealStages } = useConfigurationContext();
+ const { dealStages, dealCategories } = useConfigurationContext();
if (isPending || error) return null;
const now = Date.now();
@@ -272,7 +272,9 @@ const DealsIterator = () => {
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})}
- {deal.category ? `, ${deal.category}` : ""}
+ {deal.category
+ ? `, ${dealCategories.find((c) => c.value === deal.category)?.label ?? deal.category}`
+ : ""}
</div>
</div>
<div className="text-right">
diff --git a/src/components/atomic-crm/deals/DealCard.tsx b/src/components/atomic-crm/deals/DealCard.tsx
index 5a32002e..ac9c4710 100644
--- a/src/components/atomic-crm/deals/DealCard.tsx
+++ b/src/components/atomic-crm/deals/DealCard.tsx
@@ -4,6 +4,7 @@ import { ReferenceField } from "@/components/admin/reference-field";
import { Card, CardContent } from "@/components/ui/card";
import { CompanyAvatar } from "../companies/CompanyAvatar";
+import { useConfigurationContext } from "../root/ConfigurationContext";
import type { Deal } from "../types";
export const DealCard = ({ deal, index }: { deal: Deal; index: number }) => {
@@ -27,7 +28,11 @@ export const DealCardContent = ({
snapshot?: any;
deal: Deal;
}) => {
+ const { dealCategories } = useConfigurationContext();
const redirect = useRedirect();
+ const categoryLabel = dealCategories.find(
+ (c) => c.value === deal.category,
+ )?.label;
const handleClick = () => {
redirect(`/deals/${deal.id}/show`, undefined, undefined, undefined, {
_scrollToTop: false,
@@ -68,7 +73,7 @@ export const DealCardContent = ({
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})}
- {deal.category ? `, ${deal.category}` : ""}
+ {categoryLabel ? `, ${categoryLabel}` : ""}
</p>
</div>
</CardContent>
diff --git a/src/components/atomic-crm/deals/DealInputs.tsx b/src/components/atomic-crm/deals/DealInputs.tsx
index 2e6480c5..6d8a11eb 100644
--- a/src/components/atomic-crm/deals/DealInputs.tsx
+++ b/src/components/atomic-crm/deals/DealInputs.tsx
@@ -70,10 +70,9 @@ const DealMiscInputs = () => {
<SelectInput
source="category"
label="Category"
- choices={dealCategories.map((type) => ({
- id: type,
- name: type,
- }))}
+ choices={dealCategories}
+ optionText="label"
+ optionValue="value"
helperText={false}
/>
<NumberInput
@@ -90,10 +89,9 @@ const DealMiscInputs = () => {
/>
<SelectInput
source="stage"
- choices={dealStages.map((stage) => ({
- id: stage.value,
- name: stage.label,
- }))}
+ choices={dealStages}
+ optionText="label"
+ optionValue="value"
defaultValue="opportunity"
helperText={false}
validate={required()}
diff --git a/src/components/atomic-crm/deals/DealList.tsx b/src/components/atomic-crm/deals/DealList.tsx
index 066b181c..71f0a7f8 100644
--- a/src/components/atomic-crm/deals/DealList.tsx
+++ b/src/components/atomic-crm/deals/DealList.tsx
@@ -33,8 +33,9 @@ const DealList = () => {
<SelectInput
source="category"
emptyText="Category"
- label={false}
- choices={dealCategories.map((type) => ({ id: type, name: type }))}
+ choices={dealCategories}
+ optionText="label"
+ optionValue="value"
/>,
<OnlyMineInput source="sales_id" alwaysOn />,
];
diff --git a/src/components/atomic-crm/deals/DealShow.tsx b/src/components/atomic-crm/deals/DealShow.tsx
index a1fb504c..641d3c98 100644
--- a/src/components/atomic-crm/deals/DealShow.tsx
+++ b/src/components/atomic-crm/deals/DealShow.tsx
@@ -48,7 +48,7 @@ export const DealShow = ({ open, id }: { open: boolean; id?: string }) => {
};
const DealShowContent = () => {
- const { dealStages } = useConfigurationContext();
+ const { dealStages, dealCategories } = useConfigurationContext();
const record = useRecordContext<Deal>();
if (!record) return null;
@@ -120,7 +120,10 @@ const DealShowContent = () => {
<span className="text-xs text-muted-foreground tracking-wide">
Category
</span>
- <span className="text-sm">{record.category}</span>
+ <span className="text-sm">
+ {dealCategories.find((c) => c.value === record.category)
+ ?.label ?? record.category}
+ </span>
</div>
)}
diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts
index 3d901e68..185a3177 100644
--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/companies.ts
@@ -27,7 +27,7 @@ export const generateCompanies = (db: Db, size = 55): Required<Company>[] => {
title: lorem.text(1),
src: `./logos/${id}.png`,
} as RAFile,
- sector: random.arrayElement(defaultCompanySectors),
+ sector: random.arrayElement(defaultCompanySectors).value,
size: random.arrayElement(sizes) as 1 | 10 | 50 | 250 | 500,
linkedin_url: `https://www.linkedin.com/company/${name
.toLowerCase()
diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
index d264b84b..3cae55c2 100644
--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/deals.ts
@@ -30,7 +30,7 @@ export const generateDeals = (db: Db): Deal[] => {
name: lowercaseName[0].toUpperCase() + lowercaseName.slice(1),
company_id: company.id,
contact_ids: contacts.map((contact) => contact.id),
- category: random.arrayElement(defaultDealCategories),
+ category: random.arrayElement(defaultDealCategories).value,
stage: random.arrayElement(defaultDealStages).value,
description: lorem.paragraphs(datatype.number({ min: 1, max: 4 })),
amount: datatype.number(1000) * 100,
diff --git a/src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts b/src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts
index 5f200439..9f67db5d 100644
--- a/src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts
+++ b/src/components/atomic-crm/providers/fakerest/dataGenerator/tasks.ts
@@ -5,34 +5,32 @@ import type { Task } from "../../../types";
import type { Db } from "./types";
import { randomDate } from "./utils";
-type TaskType = (typeof defaultTaskTypes)[number];
-
-export const type: TaskType[] = [
- "Email",
- "Email",
- "Email",
- "Email",
- "Email",
- "Email",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Call",
- "Demo",
- "Lunch",
- "Meeting",
- "Follow-up",
- "Follow-up",
- "Thank you",
- "Ship",
- "None",
+export const type: string[] = [
+ "email",
+ "email",
+ "email",
+ "email",
+ "email",
+ "email",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "call",
+ "demo",
+ "lunch",
+ "meeting",
+ "follow-up",
+ "follow-up",
+ "thank-you",
+ "ship",
+ "none",
];
export const generateTasks = (db: Db) => {
@@ -42,7 +40,7 @@ export const generateTasks = (db: Db) => {
return {
id,
contact_id: contact.id,
- type: random.arrayElement(defaultTaskTypes),
+ type: random.arrayElement(defaultTaskTypes).value,
text: lorem.sentence(),
due_date: randomDate(
datatype.boolean() ? new Date() : new Date(contact.first_seen),
diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsx
index fe34ed28..0e36d2b0 100644
--- a/src/components/atomic-crm/root/CRM.tsx
+++ b/src/components/atomic-crm/root/CRM.tsx
@@ -73,15 +73,15 @@ export type CRMProps = {
* default configurations and themes but allows for customization through props. The component
* seeds the store with any custom prop values for backwards compatibility.
*
- * @param {string[]} companySectors - The list of company sectors used in the application.
+ * @param {LabeledValue[]} companySectors - The list of company sectors used in the application.
* @param {RaThemeOptions} darkTheme - The theme to use when the application is in dark mode.
- * @param {string[]} dealCategories - The categories of deals used in the application.
+ * @param {LabeledValue[]} dealCategories - The categories of deals used in the application.
* @param {string[]} dealPipelineStatuses - The statuses of deals in the pipeline used in the application.
* @param {DealStage[]} dealStages - The stages of deals used in the application.
* @param {RaThemeOptions} lightTheme - The theme to use when the application is in light mode.
* @param {string} logo - The logo used in the CRM application.
* @param {NoteStatus[]} noteStatuses - The statuses of notes used in the application.
- * @param {string[]} taskTypes - The types of tasks used in the application.
+ * @param {LabeledValue[]} taskTypes - The types of tasks used in the application.
* @param {string} title - The title of the CRM application.
*
* @returns {JSX.Element} The rendered CRM application.
diff --git a/src/components/atomic-crm/root/ConfigurationContext.tsx b/src/components/atomic-crm/root/ConfigurationContext.tsx
index f411e5cc..de8fb8c6 100644
--- a/src/components/atomic-crm/root/ConfigurationContext.tsx
+++ b/src/components/atomic-crm/root/ConfigurationContext.tsx
@@ -1,17 +1,17 @@
import { useStore } from "ra-core";
-import type { DealStage, NoteStatus } from "../types";
+import type { DealStage, LabeledValue, NoteStatus } from "../types";
import { defaultConfiguration } from "./defaultConfiguration";
export const CONFIGURATION_STORE_KEY = "app.configuration";
export interface ConfigurationContextValue {
- companySectors: string[];
- dealCategories: string[];
+ companySectors: LabeledValue[];
+ dealCategories: LabeledValue[];
dealPipelineStatuses: string[];
dealStages: DealStage[];
noteStatuses: NoteStatus[];
- taskTypes: string[];
+ taskTypes: LabeledValue[];
title: string;
darkModeLogo: string;
lightModeLogo: string;
diff --git a/src/components/atomic-crm/root/defaultConfiguration.ts b/src/components/atomic-crm/root/defaultConfiguration.ts
index 5b0f2195..eece165a 100644
--- a/src/components/atomic-crm/root/defaultConfiguration.ts
+++ b/src/components/atomic-crm/root/defaultConfiguration.ts
@@ -6,17 +6,17 @@ export const defaultLightModeLogo = "./logos/logo_atomic_crm_light.svg";
export const defaultTitle = "Atomic CRM";
export const defaultCompanySectors = [
- "Communication Services",
- "Consumer Discretionary",
- "Consumer Staples",
- "Energy",
- "Financials",
- "Health Care",
- "Industrials",
- "Information Technology",
- "Materials",
- "Real Estate",
- "Utilities",
+ { value: "communication-services", label: "Communication Services" },
+ { value: "consumer-discretionary", label: "Consumer Discretionary" },
+ { value: "consumer-staples", label: "Consumer Staples" },
+ { value: "energy", label: "Energy" },
+ { value: "financials", label: "Financials" },
+ { value: "health-care", label: "Health Care" },
+ { value: "industrials", label: "Industrials" },
+ { value: "information-technology", label: "Information Technology" },
+ { value: "materials", label: "Materials" },
+ { value: "real-estate", label: "Real Estate" },
+ { value: "utilities", label: "Utilities" },
];
export const defaultDealStages = [
@@ -31,11 +31,11 @@ export const defaultDealStages = [
export const defaultDealPipelineStatuses = ["won"];
export const defaultDealCategories = [
- "Other",
- "Copywriting",
- "Print project",
- "UI Design",
- "Website design",
+ { value: "other", label: "Other" },
+ { value: "copywriting", label: "Copywriting" },
+ { value: "print-project", label: "Print project" },
+ { value: "ui-design", label: "UI Design" },
+ { value: "website-design", label: "Website design" },
];
export const defaultNoteStatuses = [
@@ -46,15 +46,15 @@ export const defaultNoteStatuses = [
];
export const defaultTaskTypes = [
- "None",
- "Email",
- "Demo",
- "Lunch",
- "Meeting",
- "Follow-up",
- "Thank you",
- "Ship",
- "Call",
+ { value: "none", label: "None" },
+ { value: "email", label: "Email" },
+ { value: "demo", label: "Demo" },
+ { value: "lunch", label: "Lunch" },
+ { value: "meeting", label: "Meeting" },
+ { value: "follow-up", label: "Follow-up" },
+ { value: "thank-you", label: "Thank you" },
+ { value: "ship", label: "Ship" },
+ { value: "call", label: "Call" },
];
export const defaultConfiguration: ConfigurationContextValue = {
diff --git a/src/components/atomic-crm/settings/AppConfigPage.tsx b/src/components/atomic-crm/settings/AppConfigPage.tsx
index 273dc405..fce5e19f 100644
--- a/src/components/atomic-crm/settings/AppConfigPage.tsx
+++ b/src/components/atomic-crm/settings/AppConfigPage.tsx
@@ -1,12 +1,20 @@
-import { Save } from "lucide-react";
+import {
+ ArrowDown,
+ ArrowUp,
+ Check,
+ Pencil,
+ PlusCircle,
+ Save,
+ XCircle,
+} from "lucide-react";
import { EditBase, Form, useNotify } from "ra-core";
-import { useMemo } from "react";
+import { useCallback, useMemo, useRef, useState } from "react";
import { useFormContext } from "react-hook-form";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
+import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
-import { ArrayInput } from "@/components/admin/array-input";
-import { SimpleFormIterator } from "@/components/admin/simple-form-iterator";
+import { IconButtonWithTooltip } from "@/components/admin/icon-button-with-tooltip";
import { TextInput } from "@/components/admin/text-input";
import ImageEditorField from "../misc/ImageEditorField";
@@ -25,20 +33,14 @@ const SECTIONS = [
{ id: "task-types", label: "Task Types" },
];
-const splitLines = (text: string): string[] =>
- text
- .split("\n")
- .map((s) => s.trim())
- .filter(Boolean);
-
const transformFormValues = (data: Record<string, any>) => ({
config: {
title: data.title,
lightModeLogo: data.lightModeLogo,
darkModeLogo: data.darkModeLogo,
- companySectors: splitLines(data.companySectors),
- dealCategories: splitLines(data.dealCategories),
- taskTypes: splitLines(data.taskTypes),
+ companySectors: data.companySectors,
+ dealCategories: data.dealCategories,
+ taskTypes: data.taskTypes,
dealStages: data.dealStages,
dealPipelineStatuses: data.dealPipelineStatuses,
noteStatuses: data.noteStatuses,
@@ -81,9 +83,9 @@ const AppConfigForm = () => {
title: config.title,
lightModeLogo: { src: config.lightModeLogo },
darkModeLogo: { src: config.darkModeLogo },
- companySectors: config.companySectors.join("\n"),
- dealCategories: config.dealCategories.join("\n"),
- taskTypes: config.taskTypes.join("\n"),
+ companySectors: config.companySectors,
+ dealCategories: config.dealCategories,
+ taskTypes: config.taskTypes,
dealStages: config.dealStages,
dealPipelineStatuses: config.dealPipelineStatuses,
noteStatuses: config.noteStatuses,
@@ -171,12 +173,9 @@ const AppConfigFormFields = () => {
<h2 className="text-xl font-semibold text-muted-foreground">
Company Sectors
</h2>
- <TextInput
+ <LabeledValueListInput
source="companySectors"
- label={false}
- multiline
- rows={8}
- helperText="One sector per line"
+ placeholder="New sector"
/>
</CardContent>
</Card>
@@ -187,12 +186,11 @@ const AppConfigFormFields = () => {
<h2 className="text-xl font-semibold text-muted-foreground">
Deal Stages
</h2>
- <ArrayInput source="dealStages" label={false}>
- <SimpleFormIterator inline disableReordering>
- <TextInput source="value" label={false} placeholder="Value" />
- <TextInput source="label" label={false} placeholder="Label" />
- </SimpleFormIterator>
- </ArrayInput>
+ <LabeledValueListInput
+ source="dealStages"
+ placeholder="New stage"
+ reorderable
+ />
<Separator />
@@ -244,12 +242,9 @@ const AppConfigFormFields = () => {
<h2 className="text-xl font-semibold text-muted-foreground">
Deal Categories
</h2>
- <TextInput
+ <LabeledValueListInput
source="dealCategories"
- label={false}
- multiline
- rows={6}
- helperText="One category per line"
+ placeholder="New category"
/>
</CardContent>
</Card>
@@ -260,18 +255,19 @@ const AppConfigFormFields = () => {
<h2 className="text-xl font-semibold text-muted-foreground">
Note Statuses
</h2>
- <ArrayInput source="noteStatuses" label={false}>
- <SimpleFormIterator inline disableReordering>
- <TextInput source="value" label={false} placeholder="Value" />
- <TextInput source="label" label={false} placeholder="Label" />
- <TextInput
- source="color"
+ <LabeledValueListInput
+ source="noteStatuses"
+ placeholder="New status"
+ >
+ {(item, _index, updateItem) => (
+ <input
type="color"
- label={false}
- inputClassName="w-16 p-1 h-9"
+ value={item.color || "#000000"}
+ onChange={(e) => updateItem({ color: e.target.value })}
+ className="w-8 h-8 p-0.5 rounded border cursor-pointer shrink-0"
/>
- </SimpleFormIterator>
- </ArrayInput>
+ )}
+ </LabeledValueListInput>
</CardContent>
</Card>
@@ -281,12 +277,9 @@ const AppConfigFormFields = () => {
<h2 className="text-xl font-semibold text-muted-foreground">
Task Types
</h2>
- <TextInput
+ <LabeledValueListInput
source="taskTypes"
- label={false}
- multiline
- rows={6}
- helperText="One type per line"
+ placeholder="New task type"
/>
</CardContent>
</Card>
@@ -307,3 +300,214 @@ const AppConfigFormFields = () => {
</div>
);
};
+
+/**
+ * Derive a stable slug value from a display label.
+ * e.g. "Communication Services" → "communication-services"
+ */
+const toSlug = (label: string): string =>
+ label
+ .toLowerCase()
+ .replace(/[^a-z0-9]+/g, "-")
+ .replace(/^-|-$/g, "");
+
+type LabeledItem = { value: string; label: string; [key: string]: any };
+
+/**
+ * An editable list of { value, label } items, rendered as one row per item.
+ * Users only see and edit the label. The value is auto-derived from the label
+ * when creating a new item, but remains unchanged when editing an existing one.
+ *
+ * Extra fields (e.g. color) can be added per row via the children render prop.
+ */
+const LabeledValueListInput = ({
+ source,
+ placeholder = "New item",
+ reorderable = false,
+ children,
+}: {
+ source: string;
+ placeholder?: string;
+ reorderable?: boolean;
+ children?: (
+ item: LabeledItem,
+ index: number,
+ updateItem: (updates: Record<string, any>) => void,
+ ) => React.ReactNode;
+}) => {
+ const { watch, setValue } = useFormContext();
+ const rawItems: (string | LabeledItem)[] = watch(source) ?? [];
+ // Normalize plain strings (from old config format) into { value, label }
+ const items: LabeledItem[] = rawItems.map((item) =>
+ typeof item === "string" ? { value: toSlug(item), label: item } : item,
+ );
+ const [editingIndex, setEditingIndex] = useState<number | null>(null);
+ const [editLabel, setEditLabel] = useState("");
+ const inputRef = useRef<HTMLInputElement>(null);
+
+ const setItems = useCallback(
+ (next: LabeledItem[]) => setValue(source, next, { shouldDirty: true }),
+ [setValue, source],
+ );
+
+ const startEditing = useCallback(
+ (index: number) => {
+ setEditLabel(items[index].label);
+ setEditingIndex(index);
+ setTimeout(() => inputRef.current?.focus(), 0);
+ },
+ [items],
+ );
+
+ const confirmEdit = useCallback(() => {
+ if (editingIndex == null) return;
+ const trimmed = editLabel.trim();
+ if (trimmed) {
+ const next = [...items];
+ const existing = next[editingIndex];
+ // Keep extra fields (e.g. color) and existing value; only derive value for new items
+ next[editingIndex] = {
+ ...existing,
+ value: existing.value || toSlug(trimmed),
+ label: trimmed,
+ };
+ setItems(next);
+ }
+ setEditingIndex(null);
+ }, [editingIndex, editLabel, items, setItems]);
+
+ const cancelEdit = useCallback(() => {
+ setEditingIndex(null);
+ }, []);
+
+ const removeItem = useCallback(
+ (index: number) => {
+ setItems(items.filter((_, i) => i !== index));
+ if (editingIndex === index) setEditingIndex(null);
+ },
+ [items, setItems, editingIndex],
+ );
+
+ const moveItem = useCallback(
+ (index: number, direction: -1 | 1) => {
+ const target = index + direction;
+ if (target < 0 || target >= items.length) return;
+ const next = [...items];
+ [next[index], next[target]] = [next[target], next[index]];
+ setItems(next);
+ // Keep editing index in sync if the edited item moved
+ if (editingIndex === index) setEditingIndex(target);
+ else if (editingIndex === target) setEditingIndex(index);
+ },
+ [items, setItems, editingIndex],
+ );
+
+ const addItem = useCallback(() => {
+ // Add an empty item — value will be derived on confirm
+ setItems([...items, { value: "", label: "" }]);
+ setEditLabel("");
+ setEditingIndex(items.length);
+ setTimeout(() => inputRef.current?.focus(), 0);
+ }, [items, setItems]);
+
+ return (
+ <div className="space-y-1">
+ <ul className="space-y-1">
+ {items.map((item, index) => {
+ const updateItem = (updates: Record<string, any>) => {
+ const next = [...items];
+ next[index] = { ...next[index], ...updates };
+ setItems(next);
+ };
+ return (
+ <li key={index} className="flex items-center gap-1">
+ {editingIndex === index ? (
+ <>
+ <Input
+ ref={inputRef}
+ value={editLabel}
+ onChange={(e) => setEditLabel(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ e.preventDefault();
+ confirmEdit();
+ } else if (e.key === "Escape") {
+ cancelEdit();
+ }
+ }}
+ onBlur={confirmEdit}
+ placeholder={placeholder}
+ className="h-8 text-sm"
+ />
+ {children?.(item, index, updateItem)}
+ <IconButtonWithTooltip
+ label="Confirm"
+ onClick={confirmEdit}
+ className="h-8 w-8 shrink-0"
+ >
+ <Check className="h-4 w-4" />
+ </IconButtonWithTooltip>
+ </>
+ ) : (
+ <>
+ <span className="flex-1 text-sm px-3 py-1 truncate">
+ {item.label || (
+ <span className="text-muted-foreground italic">
+ (empty)
+ </span>
+ )}
+ </span>
+ {children?.(item, index, updateItem)}
+ <IconButtonWithTooltip
+ label="Edit"
+ onClick={() => startEditing(index)}
+ className="h-8 w-8 shrink-0"
+ >
+ <Pencil className="h-3.5 w-3.5" />
+ </IconButtonWithTooltip>
+ {reorderable && (
+ <>
+ <IconButtonWithTooltip
+ label="Move up"
+ onClick={() => moveItem(index, -1)}
+ disabled={index === 0}
+ className="h-8 w-8 shrink-0"
+ >
+ <ArrowUp className="h-3.5 w-3.5" />
+ </IconButtonWithTooltip>
+ <IconButtonWithTooltip
+ label="Move down"
+ onClick={() => moveItem(index, 1)}
+ disabled={index === items.length - 1}
+ className="h-8 w-8 shrink-0"
+ >
+ <ArrowDown className="h-3.5 w-3.5" />
+ </IconButtonWithTooltip>
+ </>
+ )}
+ <IconButtonWithTooltip
+ label="Remove"
+ onClick={() => removeItem(index)}
+ className="h-8 w-8 shrink-0"
+ >
+ <XCircle className="h-4 w-4 text-red-500" />
+ </IconButtonWithTooltip>
+ </>
+ )}
+ </li>
+ );
+ })}
+ </ul>
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ onClick={addItem}
+ className="mt-1"
+ >
+ <PlusCircle className="h-4 w-4 mr-1" />
+ Add
+ </Button>
+ </div>
+ );
+};
diff --git a/src/components/atomic-crm/tasks/Task.tsx b/src/components/atomic-crm/tasks/Task.tsx
index fc8a839b..de5def80 100644
--- a/src/components/atomic-crm/tasks/Task.tsx
+++ b/src/components/atomic-crm/tasks/Task.tsx
@@ -13,6 +13,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import { useConfigurationContext } from "../root/ConfigurationContext";
import type { Contact, Task as TData } from "../types";
import { TaskEdit } from "./TaskEdit";
import { TaskEditSheet } from "./TaskEditSheet";
@@ -26,6 +27,7 @@ export const Task = ({
showContact?: boolean;
}) => {
const isMobile = useIsMobile();
+ const { taskTypes } = useConfigurationContext();
const notify = useNotify();
const queryClient = useQueryClient();
@@ -92,9 +94,12 @@ export const Task = ({
/>
<div className={`flex-grow ${task.done_date ? "line-through" : ""}`}>
<div className="text-sm">
- {task.type && task.type !== "None" && (
+ {task.type && task.type !== "none" && (
<>
- <span className="font-semibold text-sm">{task.type}</span>
+ <span className="font-semibold text-sm">
+ {taskTypes.find((t) => t.value === task.type)?.label ??
+ task.type}
+ </span>
&nbsp;
</>
)}
diff --git a/src/components/atomic-crm/tasks/TaskFormContent.tsx b/src/components/atomic-crm/tasks/TaskFormContent.tsx
index 14e62304..eb25c7c6 100644
--- a/src/components/atomic-crm/tasks/TaskFormContent.tsx
+++ b/src/components/atomic-crm/tasks/TaskFormContent.tsx
@@ -41,10 +41,9 @@ export const TaskFormContent = ({
<SelectInput
source="type"
validate={required()}
- choices={taskTypes.map((type) => ({
- id: type,
- name: type,
- }))}
+ choices={taskTypes}
+ optionText="label"
+ optionValue="value"
helperText={false}
/>
</div>
diff --git a/src/components/atomic-crm/types.ts b/src/components/atomic-crm/types.ts
index 1a90e747..de320837 100644
--- a/src/components/atomic-crm/types.ts
+++ b/src/components/atomic-crm/types.ts
@@ -209,14 +209,15 @@ export interface RAFile {
}
export type AttachmentNote = RAFile;
-export interface DealStage {
+
+export interface LabeledValue {
value: string;
label: string;
}
-export interface NoteStatus {
- value: string;
- label: string;
+export interface DealStage extends LabeledValue {}
+
+export interface NoteStatus extends LabeledValue {
color: string;
}
diff --git a/supabase/migrations/20260215134709_slugify_labeled_values.sql b/supabase/migrations/20260215134709_slugify_labeled_values.sql
new file mode 100644
index 00000000..9a842f2e
--- /dev/null
+++ b/supabase/migrations/20260215134709_slugify_labeled_values.sql
@@ -0,0 +1,40 @@
+-- Migrate old label-based values to slug-based values.
+--
+-- Previously, companySectors, dealCategories, and taskTypes were stored as
+-- plain string arrays (e.g. ["Energy", "Copywriting"]) in individual records.
+-- Now they use a { value, label } format where `value` is a slug derived from
+-- the label.
+--
+-- This migration converts record fields (companies.sector, deals.category, tasks.type,
+-- contact_notes.status) from display labels to slugs.
+
+-- Helper: replicates the toSlug() TypeScript function
+CREATE OR REPLACE FUNCTION pg_temp.to_slug(label text) RETURNS text AS $$
+BEGIN
+ RETURN TRIM(BOTH '-' FROM REGEXP_REPLACE(LOWER(label), '[^a-z0-9]+', '-', 'g'));
+END;
+$$ LANGUAGE plpgsql IMMUTABLE;
+
+-- Slugify record fields
+-- Only update rows where the value differs from its slug form
+
+UPDATE companies
+SET sector = pg_temp.to_slug(sector)
+WHERE sector IS NOT NULL
+ AND sector != pg_temp.to_slug(sector);
+
+UPDATE deals
+SET category = pg_temp.to_slug(category)
+WHERE category IS NOT NULL
+ AND category != pg_temp.to_slug(category);
+
+UPDATE tasks
+SET type = pg_temp.to_slug(type)
+WHERE type IS NOT NULL
+ AND type != pg_temp.to_slug(type);
+
+UPDATE contact_notes
+SET status = pg_temp.to_slug(status)
+WHERE status IS NOT NULL
+ AND status != pg_temp.to_slug(status);
+