Skip to content

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

feat(i18n): complete remaining settings, sales and notes translations

Anibal Svarcascc6adac0446c
diff --git a/src/components/admin/sort-button.tsx b/src/components/admin/sort-button.tsx
index 55000e03..3b0ea2d3 100644
--- a/src/components/admin/sort-button.tsx
+++ b/src/components/admin/sort-button.tsx
@@ -62,6 +62,35 @@ const SortButtonComponent = (props: SortButtonProps) => {
const isMobile = useIsMobile();
const [open, setOpen] = React.useState(false);
+ const getFieldLabel = React.useCallback(
+ (field: string) => {
+ if (resource) {
+ const resourceCandidates = [resource];
+ if (resource.endsWith("_summary")) {
+ resourceCandidates.push(resource.replace(/_summary$/, ""));
+ }
+
+ for (const resourceName of resourceCandidates) {
+ const fieldLabel = translate(`crm.${resourceName}.fields.${field}`, {
+ _: "",
+ });
+ if (fieldLabel) return fieldLabel;
+
+ const inputLabel = translate(`crm.${resourceName}.inputs.${field}`, {
+ _: "",
+ });
+ if (inputLabel) return inputLabel;
+ }
+ }
+
+ return translateLabel({
+ resource,
+ source: field,
+ });
+ },
+ [resource, translate, translateLabel],
+ );
+
const handleChangeSort = (field: string) => {
setSort({
field,
@@ -70,10 +99,7 @@ const SortButtonComponent = (props: SortButtonProps) => {
setOpen(false);
};
- const fieldLabel = translateLabel({
- resource,
- source: sort.field,
- });
+ const fieldLabel = getFieldLabel(sort.field);
const buttonLabel = translate(label, {
field: fieldLabel,
field_lower_first:
@@ -118,10 +144,7 @@ const SortButtonComponent = (props: SortButtonProps) => {
<DropdownMenuContent align="start">
{fields.map((field) => (
<DropdownMenuItem key={field} onClick={() => handleChangeSort(field)}>
- {translateLabel({
- resource,
- source: field,
- })}{" "}
+ {getFieldLabel(field)}{" "}
{translate(
`ra.sort.${
sort.field === field ? inverseOrder(sort.order) : "ASC"
diff --git a/src/components/admin/theme-mode-toggle.tsx b/src/components/admin/theme-mode-toggle.tsx
index 4dfbdb22..4e7edf47 100644
--- a/src/components/admin/theme-mode-toggle.tsx
+++ b/src/components/admin/theme-mode-toggle.tsx
@@ -1,4 +1,5 @@
import { Check, Moon, Sun } from "lucide-react";
+import { useTranslate } from "ra-core";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
@@ -19,6 +20,7 @@ import { useTheme } from "@/components/admin/use-theme";
*/
export function ThemeModeToggle() {
const { theme, setTheme } = useTheme();
+ const translate = useTranslate();
return (
<DropdownMenu modal={false}>
@@ -26,20 +28,22 @@ export function ThemeModeToggle() {
<Button variant="ghost" size="icon" className="hidden sm:inline-flex">
<Sun className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
- <span className="sr-only">Toggle theme</span>
+ <span className="sr-only">
+ {translate("crm.theme.toggle", { _: "Toggle theme" })}
+ </span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
- Light
+ {translate("crm.theme.light_short", { _: "Light" })}
<Check className={cn("ml-auto", theme !== "light" && "hidden")} />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("dark")}>
- Dark
+ {translate("crm.theme.dark_short", { _: "Dark" })}
<Check className={cn("ml-auto", theme !== "dark" && "hidden")} />
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("system")}>
- System
+ {translate("crm.theme.system_short", { _: "System" })}
<Check className={cn("ml-auto", theme !== "system" && "hidden")} />
</DropdownMenuItem>
</DropdownMenuContent>
diff --git a/src/components/atomic-crm/notes/Note.tsx b/src/components/atomic-crm/notes/Note.tsx
index 7ad40141..08fe2c84 100644
--- a/src/components/atomic-crm/notes/Note.tsx
+++ b/src/components/atomic-crm/notes/Note.tsx
@@ -115,7 +115,7 @@ export const Note = ({
>
<WithRecord render={(record) => <SaleName sale={record} />} />
</ReferenceField>{" "}
- added a note{" "}
+ {translate("crm.notes.feed.added", { _: "added a note" })}{" "}
{showStatus && note.status && (
<Status className="ml-2" status={note.status} />
)}
diff --git a/src/components/atomic-crm/notes/NoteCreateSheet.tsx b/src/components/atomic-crm/notes/NoteCreateSheet.tsx
index c81d4e25..a8efa64e 100644
--- a/src/components/atomic-crm/notes/NoteCreateSheet.tsx
+++ b/src/components/atomic-crm/notes/NoteCreateSheet.tsx
@@ -6,6 +6,7 @@ import {
useGetOne,
useNotify,
useRedirect,
+ useTranslate,
useUpdate,
} from "ra-core";
import { CreateSheet } from "../misc/CreateSheet";
@@ -36,6 +37,7 @@ export const NoteCreateSheet = ({
const dataProvider = useDataProvider();
const notify = useNotify();
const redirect = useRedirect();
+ const translate = useTranslate();
if (!identity) return null;
@@ -51,7 +53,11 @@ export const NoteCreateSheet = ({
data: { last_seen: new Date().toISOString(), status: data.status },
previousData: contact,
});
- notify("Note added");
+ notify("crm.notes.added", {
+ messageArgs: {
+ _: "Note added",
+ },
+ });
redirect("show", "contacts", referenceRecordId);
onOpenChange(false);
};
@@ -61,9 +67,16 @@ export const NoteCreateSheet = ({
resource="contact_notes"
title={
<h1 className="text-xl font-semibold truncate pr-10">
- {!selectContact ? "Create Note for " : "Create Note"}
+ {!selectContact
+ ? translate("crm.notes.sheet.create_for", {
+ _: "Create note for",
+ })
+ : translate("crm.notes.sheet.create", { _: "Create note" })}
{!selectContact && (
- <RecordRepresentation record={contact} resource="contacts" />
+ <>
+ {" "}
+ <RecordRepresentation record={contact} resource="contacts" />
+ </>
)}
</h1>
}
diff --git a/src/components/atomic-crm/notes/NoteEditSheet.tsx b/src/components/atomic-crm/notes/NoteEditSheet.tsx
index ef5f771e..05938004 100644
--- a/src/components/atomic-crm/notes/NoteEditSheet.tsx
+++ b/src/components/atomic-crm/notes/NoteEditSheet.tsx
@@ -3,6 +3,7 @@ import {
type Identifier,
RecordRepresentation,
useCreatePath,
+ useTranslate,
WithRecord,
} from "ra-core";
import { EditSheet } from "../misc/EditSheet";
@@ -21,6 +22,7 @@ export const NoteEditSheet = ({
noteId,
}: NoteEditSheetProps) => {
const createPath = useCreatePath();
+ const translate = useTranslate();
const getRedirectTo = (record: any) => {
return createPath({
resource: "contacts",
@@ -39,16 +41,19 @@ export const NoteEditSheet = ({
reference="contacts"
render={({ referenceRecord }) => (
<h1 className="text-xl font-semibold truncate pr-10">
- Edit Note
{referenceRecord ? (
<>
- {" for "}
+ {translate("crm.notes.sheet.edit_for", {
+ _: "Edit note for",
+ })}{" "}
<RecordRepresentation
record={referenceRecord}
resource="contacts"
/>
</>
- ) : null}
+ ) : (
+ translate("crm.notes.sheet.edit", { _: "Edit note" })
+ )}
</h1>
)}
/>
diff --git a/src/components/atomic-crm/notes/NotesIteratorMobile.tsx b/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
index ea2b7172..8357007d 100644
--- a/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
+++ b/src/components/atomic-crm/notes/NotesIteratorMobile.tsx
@@ -1,5 +1,10 @@
import type { Identifier } from "ra-core";
-import { InfinitePaginationContext, useTimeout, WithRecord } from "ra-core";
+import {
+ InfinitePaginationContext,
+ useTimeout,
+ useTranslate,
+ WithRecord,
+} from "ra-core";
import { Link } from "react-router";
import { ReferenceField } from "@/components/admin/reference-field";
import { Button } from "@/components/ui/button";
@@ -23,7 +28,7 @@ export const NotesIteratorMobile = ({
}) => {
const { data, error, isPending, infinitePaginationContextValue, refetch } =
useAddInfinitePagination();
-
+ const translate = useTranslate();
const oneSecondHasPassed = useTimeout(1000);
if (isPending) {
if (!oneSecondHasPassed) {
@@ -47,7 +52,9 @@ export const NotesIteratorMobile = ({
return (
<div className="p-4">
<div className="text-center text-muted-foreground mb-4">
- Error loading notes
+ {translate("crm.notes.list.error_loading", {
+ _: "Error loading notes",
+ })}
</div>
<div className="text-center mt-2">
<Button
@@ -56,7 +63,7 @@ export const NotesIteratorMobile = ({
}}
>
<RotateCcw />
- Retry
+ {translate("crm.common.retry", { _: "Retry" })}
</Button>
</div>
</div>
@@ -88,36 +95,40 @@ export const NoteMobile = ({
note: ContactNote;
contactId: Identifier;
showStatus?: boolean;
-}) => (
- <Link
- to={`/contacts/${contactId}/notes/${note.id}`}
- className="block active:bg-accent/50 -mx-2 px-2 py-2 rounded-md"
- >
- <div className="flex items-center space-x-2 w-full">
- <div className="inline-flex h-full items-center text-sm text-muted-foreground">
- By{" "}
- <ReferenceField
- record={note}
- resource="contact_notes"
- source="sales_id"
- reference="sales"
- link={false}
- >
- <WithRecord render={(record) => <SaleName sale={record} />} />
- </ReferenceField>
- {showStatus && note.status && (
- <Status className="ml-2" status={note.status} />
- )}
+}) => {
+ const translate = useTranslate();
+
+ return (
+ <Link
+ to={`/contacts/${contactId}/notes/${note.id}`}
+ className="block active:bg-accent/50 -mx-2 px-2 py-2 rounded-md"
+ >
+ <div className="flex items-center space-x-2 w-full">
+ <div className="inline-flex h-full items-center text-sm text-muted-foreground">
+ {translate("crm.common.by", { _: "By" })}{" "}
+ <ReferenceField
+ record={note}
+ resource="contact_notes"
+ source="sales_id"
+ reference="sales"
+ link={false}
+ >
+ <WithRecord render={(record) => <SaleName sale={record} />} />
+ </ReferenceField>
+ {showStatus && note.status && (
+ <Status className="ml-2" status={note.status} />
+ )}
+ </div>
+ <div className="flex-1" />
+ <span className="text-sm text-muted-foreground">
+ <RelativeDate date={note.date} />
+ </span>
</div>
- <div className="flex-1" />
- <span className="text-sm text-muted-foreground">
- <RelativeDate date={note.date} />
- </span>
- </div>
- {note.text && (
- <p className="pt-2 text-sm line-clamp-3">
- {note.text.replace(/\s+/g, " ").trim()}
- </p>
- )}
- </Link>
-);
+ {note.text && (
+ <p className="pt-2 text-sm line-clamp-3">
+ {note.text.replace(/\s+/g, " ").trim()}
+ </p>
+ )}
+ </Link>
+ );
+};
diff --git a/src/components/atomic-crm/root/englishCrmMessages.ts b/src/components/atomic-crm/root/englishCrmMessages.ts
index 82578b16..d3b1555e 100644
--- a/src/components/atomic-crm/root/englishCrmMessages.ts
+++ b/src/components/atomic-crm/root/englishCrmMessages.ts
@@ -89,6 +89,8 @@ export const englishCrmMessages = {
website: "Website",
linkedin_url: "LinkedIn URL",
phone_number: "Phone number",
+ created_at: "Created at",
+ nb_contacts: "Number of contacts",
revenue: "Revenue",
sector: "Sector",
size: "Size",
@@ -195,6 +197,11 @@ export const englishCrmMessages = {
list: {
error_loading: "Error loading contacts",
},
+ fields: {
+ first_name: "First name",
+ last_name: "Last name",
+ last_seen: "Last seen",
+ },
merge: {
action: "Merge with another contact",
confirm: "Merge Contacts",
@@ -355,8 +362,20 @@ export const englishCrmMessages = {
update: "Update note",
add_this: "Add this note",
},
+ sheet: {
+ create: "Create note",
+ create_for: "Create note for",
+ edit: "Edit note",
+ edit_for: "Edit note for",
+ },
deleted: "Note deleted",
empty: "No notes yet",
+ feed: {
+ added: "added a note",
+ },
+ list: {
+ error_loading: "Error loading notes",
+ },
note_for: "Note for",
stepper: {
hint: "Go to a contact page and add a note",
@@ -386,11 +405,20 @@ export const englishCrmMessages = {
"User created. They will soon receive an email to set their password.",
title: "Create a new user",
},
+ edit: {
+ error: "An error occurred. Please try again.",
+ record_not_found: "Record not found",
+ success: "User updated successfully",
+ title: "Edit %{name}",
+ },
name: "User |||| Users",
action: {
new: "New user",
},
fields: {
+ first_name: "First name",
+ last_name: "Last name",
+ email: "Email",
admin: "Admin",
disabled: "Disabled",
},
@@ -423,6 +451,16 @@ export const englishCrmMessages = {
sections: {
branding: "Branding",
},
+ validation: {
+ duplicate: "Duplicate %{display_name}: %{items}",
+ in_use:
+ "Cannot remove %{display_name} that are still used by deals: %{items}",
+ validating: "Validating…",
+ entities: {
+ categories: "categories",
+ stages: "stages",
+ },
+ },
},
tasks: {
action: {
@@ -479,6 +517,7 @@ export const englishCrmMessages = {
light_short: "Light",
system: "System theme",
system_short: "System",
+ toggle: "Toggle theme",
},
language: "Language",
navigation: {
@@ -511,6 +550,7 @@ export const englishCrmMessages = {
},
password_reset_sent:
"A reset password email has been sent to your email address",
+ record_not_found: "Record not found",
title: "Profile",
updated: "Your profile has been updated",
update_error: "An error occurred. Please try again",
diff --git a/src/components/atomic-crm/root/frenchCrmMessages.ts b/src/components/atomic-crm/root/frenchCrmMessages.ts
index f589fbce..d60c4f70 100644
--- a/src/components/atomic-crm/root/frenchCrmMessages.ts
+++ b/src/components/atomic-crm/root/frenchCrmMessages.ts
@@ -89,6 +89,8 @@ export const frenchCrmMessages = {
website: "Site web",
linkedin_url: "URL LinkedIn",
phone_number: "Numéro de téléphone",
+ created_at: "Date de création",
+ nb_contacts: "Nombre de contacts",
revenue: "Chiffre d'affaires",
sector: "Secteur",
size: "Taille",
@@ -198,6 +200,11 @@ export const frenchCrmMessages = {
list: {
error_loading: "Erreur lors du chargement des contacts",
},
+ fields: {
+ first_name: "Prénom",
+ last_name: "Nom",
+ last_seen: "Dernière activité",
+ },
merge: {
action: "Fusionner avec un autre contact",
confirm: "Fusionner les contacts",
@@ -359,8 +366,20 @@ export const frenchCrmMessages = {
update: "Mettre à jour la note",
add_this: "Ajouter cette note",
},
+ sheet: {
+ create: "Créer une note",
+ create_for: "Créer une note pour",
+ edit: "Modifier la note",
+ edit_for: "Modifier la note pour",
+ },
deleted: "Note supprimée",
empty: "Aucune note pour l'instant",
+ feed: {
+ added: "a ajouté une note",
+ },
+ list: {
+ error_loading: "Erreur lors du chargement des notes",
+ },
note_for: "Note pour",
stepper: {
hint: "Accédez à une page de contact et ajoutez une note",
@@ -391,11 +410,20 @@ export const frenchCrmMessages = {
"Utilisateur créé. Ils recevront prochainement un email pour définir leur mot de passe.",
title: "Créer un nouvel utilisateur",
},
+ edit: {
+ error: "Une erreur s'est produite. Veuillez réessayer.",
+ record_not_found: "Enregistrement introuvable",
+ success: "Utilisateur mis à jour avec succès",
+ title: "Modifier %{name}",
+ },
name: "Utilisateur |||| Utilisateurs",
action: {
new: "Nouvel utilisateur",
},
fields: {
+ first_name: "Prénom",
+ last_name: "Nom",
+ email: "E-mail",
admin: "Admin",
disabled: "Désactivé",
},
@@ -428,6 +456,16 @@ export const frenchCrmMessages = {
sections: {
branding: "Image de marque",
},
+ validation: {
+ duplicate: "%{display_name} en double : %{items}",
+ in_use:
+ "Impossible de supprimer %{display_name} encore utilisés par des affaires : %{items}",
+ validating: "Validation…",
+ entities: {
+ categories: "catégories",
+ stages: "étapes",
+ },
+ },
},
tasks: {
action: {
@@ -484,6 +522,7 @@ export const frenchCrmMessages = {
light_short: "Clair",
system: "Thème système",
system_short: "Système",
+ toggle: "Changer de thème",
},
language: "Langue",
navigation: {
@@ -516,6 +555,7 @@ export const frenchCrmMessages = {
},
password_reset_sent:
"Un e-mail de réinitialisation du mot de passe a été envoyé à votre adresse e-mail",
+ record_not_found: "Enregistrement introuvable",
title: "Profil",
updated: "Votre profil a été mis à jour",
update_error: "Une erreur s'est produite. Veuillez réessayer",
diff --git a/src/components/atomic-crm/sales/SalesEdit.tsx b/src/components/atomic-crm/sales/SalesEdit.tsx
index 9f0f6120..908f68e5 100644
--- a/src/components/atomic-crm/sales/SalesEdit.tsx
+++ b/src/components/atomic-crm/sales/SalesEdit.tsx
@@ -5,6 +5,7 @@ import {
useNotify,
useRecordContext,
useRedirect,
+ useTranslate,
} from "ra-core";
import type { SubmitHandler } from "react-hook-form";
import { SimpleForm } from "@/components/admin/simple-form";
@@ -31,21 +32,35 @@ export function SalesEdit() {
const dataProvider = useDataProvider<CrmDataProvider>();
const notify = useNotify();
const redirect = useRedirect();
+ const translate = useTranslate();
const { mutate } = useMutation({
mutationKey: ["signup"],
mutationFn: async (data: SalesFormData) => {
if (!record) {
- throw new Error("Record not found");
+ throw new Error(
+ translate("crm.sales.edit.record_not_found", {
+ _: "Record not found",
+ }),
+ );
}
return dataProvider.salesUpdate(record.id, data);
},
onSuccess: () => {
redirect("/sales");
- notify("User updated successfully");
+ notify("crm.sales.edit.success", {
+ messageArgs: {
+ _: "User updated successfully",
+ },
+ });
},
onError: () => {
- notify("An error occurred. Please try again.");
+ notify("crm.sales.edit.error", {
+ type: "error",
+ messageArgs: {
+ _: "An error occurred. Please try again.",
+ },
+ });
},
});
@@ -73,10 +88,14 @@ export function SalesEdit() {
const SaleEditTitle = () => {
const record = useRecordContext<Sale>();
+ const translate = useTranslate();
if (!record) return null;
return (
<h2 className="text-lg font-semibold mb-4">
- Edit {record?.first_name} {record?.last_name}
+ {translate("crm.sales.edit.title", {
+ name: `${record.first_name} ${record.last_name}`,
+ _: `Edit ${record.first_name} ${record.last_name}`,
+ })}
</h2>
);
};
diff --git a/src/components/atomic-crm/sales/SalesInputs.tsx b/src/components/atomic-crm/sales/SalesInputs.tsx
index 0a01cb37..4570681a 100644
--- a/src/components/atomic-crm/sales/SalesInputs.tsx
+++ b/src/components/atomic-crm/sales/SalesInputs.tsx
@@ -9,20 +9,33 @@ export function SalesInputs() {
const record = useRecordContext<Sale>();
return (
<div className="space-y-4 w-full">
- <TextInput source="first_name" validate={required()} helperText={false} />
- <TextInput source="last_name" validate={required()} helperText={false} />
+ <TextInput
+ source="first_name"
+ label="crm.sales.fields.first_name"
+ validate={required()}
+ helperText={false}
+ />
+ <TextInput
+ source="last_name"
+ label="crm.sales.fields.last_name"
+ validate={required()}
+ helperText={false}
+ />
<TextInput
source="email"
+ label="crm.sales.fields.email"
validate={[required(), email()]}
helperText={false}
/>
<BooleanInput
source="administrator"
+ label="crm.sales.fields.admin"
readOnly={record?.id === identity?.id}
helperText={false}
/>
<BooleanInput
source="disabled"
+ label="crm.sales.fields.disabled"
readOnly={record?.id === identity?.id}
helperText={false}
/>
diff --git a/src/components/atomic-crm/sales/SalesList.tsx b/src/components/atomic-crm/sales/SalesList.tsx
index 290c5b41..5c852a8f 100644
--- a/src/components/atomic-crm/sales/SalesList.tsx
+++ b/src/components/atomic-crm/sales/SalesList.tsx
@@ -58,9 +58,12 @@ export function SalesList() {
sort={{ field: "first_name", order: "ASC" }}
>
<DataTable>
- <DataTable.Col source="first_name" />
- <DataTable.Col source="last_name" />
- <DataTable.Col source="email" />
+ <DataTable.Col
+ source="first_name"
+ label="crm.sales.fields.first_name"
+ />
+ <DataTable.Col source="last_name" label="crm.sales.fields.last_name" />
+ <DataTable.Col source="email" label="crm.sales.fields.email" />
<DataTable.Col label={false}>
<OptionsField />
</DataTable.Col>
diff --git a/src/components/atomic-crm/settings/ProfilePage.tsx b/src/components/atomic-crm/settings/ProfilePage.tsx
index bf1cbf4c..6379074a 100644
--- a/src/components/atomic-crm/settings/ProfilePage.tsx
+++ b/src/components/atomic-crm/settings/ProfilePage.tsx
@@ -32,6 +32,7 @@ export const ProfilePage = () => {
const { data, refetch: refetchUser } = useGetOne("sales", {
id: identity?.id,
});
+ const translate = useTranslate();
const notify = useNotify();
const dataProvider = useDataProvider<CrmDataProvider>();
@@ -39,7 +40,11 @@ export const ProfilePage = () => {
mutationKey: ["signup"],
mutationFn: async (data: SalesFormData) => {
if (!identity) {
- throw new Error("Record not found");
+ throw new Error(
+ translate("crm.profile.record_not_found", {
+ _: "Record not found",
+ }),
+ );
}
return dataProvider.salesUpdate(identity.id, data);
},
@@ -96,7 +101,11 @@ const ProfileForm = ({
mutationKey: ["updatePassword"],
mutationFn: async () => {
if (!identity) {
- throw new Error("Record not found");
+ throw new Error(
+ translate("crm.profile.record_not_found", {
+ _: "Record not found",
+ }),
+ );
}
return dataProvider.updatePassword(identity.id);
},
@@ -118,7 +127,11 @@ const ProfileForm = ({
mutationKey: ["signup"],
mutationFn: async (data: SalesFormData) => {
if (!record) {
- throw new Error("Record not found");
+ throw new Error(
+ translate("crm.profile.record_not_found", {
+ _: "Record not found",
+ }),
+ );
}
return dataProvider.salesUpdate(record.id, data);
},
@@ -239,12 +252,13 @@ const TextRender = ({
source: string;
isEditMode: boolean;
}) => {
+ const label = `crm.sales.fields.${source}`;
if (isEditMode) {
- return <TextInput source={source} helperText={false} />;
+ return <TextInput source={source} label={label} helperText={false} />;
}
return (
<div className="m-2">
- <RecordField source={source} />
+ <RecordField source={source} label={label} />
</div>
);
};
diff --git a/src/components/atomic-crm/settings/SettingsPage.tsx b/src/components/atomic-crm/settings/SettingsPage.tsx
index b2948f09..fe784d96 100644
--- a/src/components/atomic-crm/settings/SettingsPage.tsx
+++ b/src/components/atomic-crm/settings/SettingsPage.tsx
@@ -134,6 +134,14 @@ const SettingsFormFields = () => {
const dealStages = watch("dealStages");
const dealPipelineStatuses: string[] = watch("dealPipelineStatuses") ?? [];
+ const stageDisplayName = translate(
+ "crm.settings.validation.entities.stages",
+ { _: "stages" },
+ );
+ const categoryDisplayName = translate(
+ "crm.settings.validation.entities.categories",
+ { _: "categories" },
+ );
const { data: deals } = useGetList("deals", {
pagination: { page: 1, perPage: 1000 },
@@ -141,14 +149,50 @@ const SettingsFormFields = () => {
const validateDealStages = useCallback(
(stages: { value: string; label: string }[] | undefined) =>
- validateItemsInUse(stages, deals, "stage", "stages"),
- [deals],
+ validateItemsInUse(stages, deals, "stage", stageDisplayName, {
+ duplicate: (displayName, duplicates) =>
+ translate("crm.settings.validation.duplicate", {
+ display_name: displayName,
+ items: duplicates.join(", "),
+ _: `Duplicate ${displayName}: ${duplicates.join(", ")}`,
+ }),
+ inUse: (displayName, inUse) =>
+ translate("crm.settings.validation.in_use", {
+ display_name: displayName,
+ items: inUse.join(", "),
+ _:
+ `Cannot remove ${displayName} that are still used by deals: ` +
+ inUse.join(", "),
+ }),
+ validating: translate("crm.settings.validation.validating", {
+ _: "Validating…",
+ }),
+ }),
+ [deals, stageDisplayName, translate],
);
const validateDealCategories = useCallback(
(categories: { value: string; label: string }[] | undefined) =>
- validateItemsInUse(categories, deals, "category", "categories"),
- [deals],
+ validateItemsInUse(categories, deals, "category", categoryDisplayName, {
+ duplicate: (displayName, duplicates) =>
+ translate("crm.settings.validation.duplicate", {
+ display_name: displayName,
+ items: duplicates.join(", "),
+ _: `Duplicate ${displayName}: ${duplicates.join(", ")}`,
+ }),
+ inUse: (displayName, inUse) =>
+ translate("crm.settings.validation.in_use", {
+ display_name: displayName,
+ items: inUse.join(", "),
+ _:
+ `Cannot remove ${displayName} that are still used by deals: ` +
+ inUse.join(", "),
+ }),
+ validating: translate("crm.settings.validation.validating", {
+ _: "Validating…",
+ }),
+ }),
+ [categoryDisplayName, deals, translate],
);
return (
diff --git a/src/components/atomic-crm/settings/validateItemsInUse.ts b/src/components/atomic-crm/settings/validateItemsInUse.ts
index 3a87ab27..3594fdc0 100644
--- a/src/components/atomic-crm/settings/validateItemsInUse.ts
+++ b/src/components/atomic-crm/settings/validateItemsInUse.ts
@@ -1,6 +1,12 @@
import type { RaRecord } from "ra-core";
import { toSlug } from "@/lib/toSlug";
+type ValidateItemsInUseMessages = {
+ duplicate?: (displayName: string, duplicates: string[]) => string;
+ inUse?: (displayName: string, inUse: string[]) => string;
+ validating?: string;
+};
+
/**
* Validate that no items were removed if they are still referenced by existing deals.
* Also rejects duplicate slug values.
@@ -11,6 +17,7 @@ export const validateItemsInUse = (
deals: RaRecord[] | undefined,
fieldName: string,
displayName: string,
+ messages?: ValidateItemsInUseMessages,
) => {
if (!items) return undefined;
// Check for duplicate slugs
@@ -22,10 +29,14 @@ export const validateItemsInUse = (
seen.add(slug);
}
if (duplicates.size > 0) {
- return `Duplicate ${displayName}: ${[...duplicates].join(", ")}`;
+ const duplicatesList = [...duplicates];
+ return (
+ messages?.duplicate?.(displayName, duplicatesList) ??
+ `Duplicate ${displayName}: ${duplicatesList.join(", ")}`
+ );
}
// Check that no in-use value was removed (skip if deals haven't loaded)
- if (!deals) return "Validating…";
+ if (!deals) return messages?.validating ?? "Validating…";
const values = new Set(slugs);
const inUse = [
...new Set(
@@ -37,7 +48,10 @@ export const validateItemsInUse = (
),
];
if (inUse.length > 0) {
- return `Cannot remove ${displayName} that are still used by deals: ${inUse.join(", ")}`;
+ return (
+ messages?.inUse?.(displayName, inUse) ??
+ `Cannot remove ${displayName} that are still used by deals: ${inUse.join(", ")}`
+ );
}
return undefined;
};