Skip to content

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

Make currency configurable

François Zaninottodf94c8f31056
diff --git a/doc/src/content/docs/developers/customizing.mdx b/doc/src/content/docs/developers/customizing.mdx
index 808026c2..717b4b74 100644
--- a/doc/src/content/docs/developers/customizing.mdx
+++ b/doc/src/content/docs/developers/customizing.mdx
@@ -61,18 +61,19 @@ export default App;
`<CRM>` accepts the following props:
-| Props | Description | Type |
-| ---------------------- | ------------------------------------------------------------- | -------------- |
-| `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. | 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. | LabeledValue[] |
-| `title` | The title of the CRM application. | string |
+| Props | Description | Type |
+| ---------------------- | ------------------------------------------------------------------------------------ | -------------- |
+| `companySectors` | The list of company sectors used in the application. | LabeledValue[] |
+| `currency` | The ISO 4217 currency code used to format monetary values (default: `"USD"`). | string |
+| `darkTheme` | The theme to use when the application is in dark mode. | RaThemeOptions |
+| `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. | LabeledValue[] |
+| `title` | The title of the CRM application. | string |
## Languages (i18n)
diff --git a/src/components/atomic-crm/companies/CompanyCard.tsx b/src/components/atomic-crm/companies/CompanyCard.tsx
index e8a74f1f..b75982e7 100644
--- a/src/components/atomic-crm/companies/CompanyCard.tsx
+++ b/src/components/atomic-crm/companies/CompanyCard.tsx
@@ -1,4 +1,4 @@
-import { DollarSign } from "lucide-react";
+import { Handshake } from "lucide-react";
import { Link } from "react-router";
import {
useCreatePath,
@@ -51,7 +51,7 @@ export const CompanyCard = (props: { record?: Company }) => {
</div>
{record.nb_deals ? (
<div className="flex items-center ml-2 gap-0.5">
- <DollarSign className="w-4 h-4 text-muted-foreground" />
+ <Handshake className="w-4 h-4 text-muted-foreground" />
<span className="text-sm font-medium">{record.nb_deals}</span>
<span className="text-xs text-muted-foreground">
{translate("resources.deals.name", {
diff --git a/src/components/atomic-crm/companies/CompanyShow.tsx b/src/components/atomic-crm/companies/CompanyShow.tsx
index 5af84594..a0375b46 100644
--- a/src/components/atomic-crm/companies/CompanyShow.tsx
+++ b/src/components/atomic-crm/companies/CompanyShow.tsx
@@ -262,7 +262,7 @@ const DealsIterator = () => {
const translate = useTranslate();
const [locale = "en"] = useLocaleState();
const { data: deals, error, isPending } = useListContext<Deal>();
- const { dealStages, dealCategories } = useConfigurationContext();
+ const { dealStages, dealCategories, currency } = useConfigurationContext();
if (isPending || error) return null;
return (
<div>
@@ -280,7 +280,7 @@ const DealsIterator = () => {
{deal.amount.toLocaleString("en-US", {
notation: "compact",
style: "currency",
- currency: "USD",
+ currency,
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})}
diff --git a/src/components/atomic-crm/dashboard/DealsChart.tsx b/src/components/atomic-crm/dashboard/DealsChart.tsx
index dbd3bcde..dd85bba1 100644
--- a/src/components/atomic-crm/dashboard/DealsChart.tsx
+++ b/src/components/atomic-crm/dashboard/DealsChart.tsx
@@ -1,6 +1,6 @@
import { ResponsiveBar } from "@nivo/bar";
import { format, startOfMonth } from "date-fns";
-import { DollarSign } from "lucide-react";
+import { TrendingUp } from "lucide-react";
import { useGetList, useTranslate } from "ra-core";
import { memo, useMemo } from "react";
@@ -20,11 +20,10 @@ const threeMonthsAgo = new Date(
).toISOString();
const DEFAULT_LOCALE = "en-US";
-const CURRENCY = "USD";
export const DealsChart = memo(() => {
const translate = useTranslate();
- const { dealStages } = useConfigurationContext();
+ const { dealStages, currency } = useConfigurationContext();
const acceptedLanguages = navigator
? navigator.languages || [navigator.language]
: [DEFAULT_LOCALE];
@@ -93,7 +92,7 @@ export const DealsChart = memo(() => {
<div className="flex flex-col">
<div className="flex items-center mb-4">
<div className="mr-3 flex">
- <DollarSign className="text-muted-foreground w-6 h-6" />
+ <TrendingUp className="text-muted-foreground w-6 h-6" />
</div>
<h2 className="text-xl font-semibold text-muted-foreground">
{translate("crm.dashboard.deals_chart")}
@@ -121,7 +120,7 @@ export const DealsChart = memo(() => {
<strong>{indexValue}: </strong>&nbsp;{value > 0 ? "+" : ""}
{value.toLocaleString(acceptedLanguages.at(0) ?? DEFAULT_LOCALE, {
style: "currency",
- currency: CURRENCY,
+ currency,
})}
</div>
)}
diff --git a/src/components/atomic-crm/dashboard/DealsPipeline.tsx b/src/components/atomic-crm/dashboard/DealsPipeline.tsx
index c41fed92..8a93f28f 100644
--- a/src/components/atomic-crm/dashboard/DealsPipeline.tsx
+++ b/src/components/atomic-crm/dashboard/DealsPipeline.tsx
@@ -17,7 +17,8 @@ import type { Deal } from "../types";
export const DealsPipeline = () => {
const translate = useTranslate();
const { identity } = useGetIdentity();
- const { dealStages, dealPipelineStatuses } = useConfigurationContext();
+ const { dealStages, dealPipelineStatuses, currency } =
+ useConfigurationContext();
const { data, total, isPending } = useGetList<Deal>(
"deals",
{
@@ -68,7 +69,7 @@ export const DealsPipeline = () => {
`${deal.amount.toLocaleString("en-US", {
notation: "compact",
style: "currency",
- currency: "USD",
+ currency,
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})} , ${findDealLabel(dealStages, deal.stage)}`
diff --git a/src/components/atomic-crm/deals/DealCard.tsx b/src/components/atomic-crm/deals/DealCard.tsx
index 9a5f8be6..c10534fe 100644
--- a/src/components/atomic-crm/deals/DealCard.tsx
+++ b/src/components/atomic-crm/deals/DealCard.tsx
@@ -30,7 +30,7 @@ export const DealCardContent = ({
snapshot?: any;
deal: Deal;
}) => {
- const { dealCategories } = useConfigurationContext();
+ const { dealCategories, currency } = useConfigurationContext();
const redirect = useRedirect();
const handleClick = () => {
redirect(`/deals/${deal.id}/show`, undefined, undefined, undefined, {
@@ -79,7 +79,7 @@ export const DealCardContent = ({
options={{
notation: "compact",
style: "currency",
- currency: "USD",
+ currency,
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
}}
diff --git a/src/components/atomic-crm/deals/DealColumn.tsx b/src/components/atomic-crm/deals/DealColumn.tsx
index ee21240b..4bcbc886 100644
--- a/src/components/atomic-crm/deals/DealColumn.tsx
+++ b/src/components/atomic-crm/deals/DealColumn.tsx
@@ -13,7 +13,7 @@ export const DealColumn = ({
deals: Deal[];
}) => {
const totalAmount = deals.reduce((sum, deal) => sum + deal.amount, 0);
- const { dealStages } = useConfigurationContext();
+ const { dealStages, currency } = useConfigurationContext();
return (
<div className="flex-1 pb-8">
<div className="flex flex-col items-center">
@@ -24,7 +24,7 @@ export const DealColumn = ({
{totalAmount.toLocaleString("en-US", {
notation: "compact",
style: "currency",
- currency: "USD",
+ currency,
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})}
diff --git a/src/components/atomic-crm/deals/DealShow.tsx b/src/components/atomic-crm/deals/DealShow.tsx
index 01325d86..61248b97 100644
--- a/src/components/atomic-crm/deals/DealShow.tsx
+++ b/src/components/atomic-crm/deals/DealShow.tsx
@@ -50,7 +50,7 @@ export const DealShow = ({ open, id }: { open: boolean; id?: string }) => {
const DealShowContent = () => {
const translate = useTranslate();
- const { dealStages, dealCategories } = useConfigurationContext();
+ const { dealStages, dealCategories, currency } = useConfigurationContext();
const record = useRecordContext<Deal>();
if (!record) return null;
@@ -112,7 +112,7 @@ const DealShowContent = () => {
{record.amount.toLocaleString("en-US", {
notation: "compact",
style: "currency",
- currency: "USD",
+ currency,
currencyDisplay: "narrowSymbol",
minimumSignificantDigits: 3,
})}
diff --git a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts b/src/components/atomic-crm/providers/commons/englishCrmMessages.ts
index 7983ec6f..6fa6f463 100644
--- a/src/components/atomic-crm/providers/commons/englishCrmMessages.ts
+++ b/src/components/atomic-crm/providers/commons/englishCrmMessages.ts
@@ -449,6 +449,7 @@ export const englishCrmMessages = {
dark_mode_logo: "Dark Mode Logo",
deals: {
categories: "Categories",
+ currency: "Currency",
pipeline_help:
"Select which deal stages should count as pipeline deals.",
pipeline_statuses: "Pipeline Statuses",
diff --git a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts b/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts
index b79e2f6e..1d5fedab 100644
--- a/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts
+++ b/src/components/atomic-crm/providers/commons/frenchCrmMessages.ts
@@ -455,6 +455,7 @@ export const frenchCrmMessages = {
dark_mode_logo: "Logo du mode sombre",
deals: {
categories: "Catégories",
+ currency: "Devise",
pipeline_help:
"Sélectionnez les étapes d'affaire à considérer comme des affaires dans le pipeline.",
pipeline_statuses: "Statuts des pipelines",
diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsx
index 42bb781b..f94e1e62 100644
--- a/src/components/atomic-crm/root/CRM.tsx
+++ b/src/components/atomic-crm/root/CRM.tsx
@@ -39,6 +39,7 @@ import {
import type { CrmDataProvider } from "../providers/types";
import {
defaultCompanySectors,
+ defaultCurrency,
defaultDarkModeLogo,
defaultDealCategories,
defaultDealPipelineStatuses,
@@ -74,6 +75,7 @@ export type CRMProps = {
* seeds the store with any custom prop values for backwards compatibility.
*
* @param {LabeledValue[]} companySectors - The list of company sectors used in the application.
+ * @param {string} currency - The ISO 4217 currency code used to format monetary values (e.g. "USD", "EUR", "GBP").
* @param {RaThemeOptions} darkTheme - The theme to use when the application is in dark mode.
* @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.
@@ -107,6 +109,7 @@ export type CRMProps = {
*/
export const CRM = ({
companySectors = defaultCompanySectors,
+ currency = defaultCurrency,
dealCategories = defaultDealCategories,
dealPipelineStatuses = defaultDealPipelineStatuses,
dealStages = defaultDealStages,
@@ -143,6 +146,7 @@ export const CRM = ({
if (!store.getItem(CONFIGURATION_STORE_KEY)) {
store.setItem(CONFIGURATION_STORE_KEY, {
companySectors,
+ currency,
dealCategories,
dealPipelineStatuses,
dealStages,
diff --git a/src/components/atomic-crm/root/ConfigurationContext.tsx b/src/components/atomic-crm/root/ConfigurationContext.tsx
index b5b4757f..6efedbaf 100644
--- a/src/components/atomic-crm/root/ConfigurationContext.tsx
+++ b/src/components/atomic-crm/root/ConfigurationContext.tsx
@@ -8,6 +8,7 @@ export const CONFIGURATION_STORE_KEY = "app.configuration";
export interface ConfigurationContextValue {
companySectors: LabeledValue[];
+ currency: string;
dealCategories: LabeledValue[];
dealPipelineStatuses: string[];
dealStages: DealStage[];
diff --git a/src/components/atomic-crm/root/defaultConfiguration.ts b/src/components/atomic-crm/root/defaultConfiguration.ts
index eece165a..cd8916d5 100644
--- a/src/components/atomic-crm/root/defaultConfiguration.ts
+++ b/src/components/atomic-crm/root/defaultConfiguration.ts
@@ -3,6 +3,8 @@ import type { ConfigurationContextValue } from "./ConfigurationContext";
export const defaultDarkModeLogo = "./logos/logo_atomic_crm_dark.svg";
export const defaultLightModeLogo = "./logos/logo_atomic_crm_light.svg";
+export const defaultCurrency = "USD";
+
export const defaultTitle = "Atomic CRM";
export const defaultCompanySectors = [
@@ -59,6 +61,7 @@ export const defaultTaskTypes = [
export const defaultConfiguration: ConfigurationContextValue = {
companySectors: defaultCompanySectors,
+ currency: defaultCurrency,
dealCategories: defaultDealCategories,
dealPipelineStatuses: defaultDealPipelineStatuses,
dealStages: defaultDealStages,
diff --git a/src/components/atomic-crm/settings/SettingsPage.tsx b/src/components/atomic-crm/settings/SettingsPage.tsx
index aedba409..d45f73a5 100644
--- a/src/components/atomic-crm/settings/SettingsPage.tsx
+++ b/src/components/atomic-crm/settings/SettingsPage.tsx
@@ -16,6 +16,7 @@ import { Card, CardContent } from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { toSlug } from "@/lib/toSlug";
import { ArrayInput } from "@/components/admin/array-input";
+import { AutocompleteInput } from "@/components/admin/autocomplete-input";
import { SimpleFormIterator } from "@/components/admin/simple-form-iterator";
import { TextInput } from "@/components/admin/text-input";
@@ -102,11 +103,25 @@ export const validateItemsInUse = (
return undefined;
};
+const getCurrencyChoices = () => {
+ const displayNames = new Intl.DisplayNames(
+ typeof navigator !== "undefined"
+ ? (navigator.languages as string[])
+ : ["en"],
+ { type: "currency" },
+ );
+ return Intl.supportedValuesOf("currency").map((code) => ({
+ id: code,
+ name: `${code} – ${displayNames.of(code)}`,
+ }));
+};
+
const transformFormValues = (data: Record<string, any>) => ({
config: {
title: data.title,
lightModeLogo: data.lightModeLogo,
darkModeLogo: data.darkModeLogo,
+ currency: data.currency,
companySectors: ensureValues(data.companySectors),
dealCategories: ensureValues(data.dealCategories),
taskTypes: ensureValues(data.taskTypes),
@@ -154,6 +169,7 @@ const SettingsForm = () => {
title: config.title,
lightModeLogo: { src: config.lightModeLogo },
darkModeLogo: { src: config.darkModeLogo },
+ currency: config.currency,
companySectors: config.companySectors,
dealCategories: config.dealCategories,
taskTypes: config.taskTypes,
@@ -173,6 +189,7 @@ const SettingsForm = () => {
const SettingsFormFields = () => {
const translate = useTranslate();
+ const currencyChoices = useMemo(() => getCurrencyChoices(), []);
const {
watch,
setValue,
@@ -321,6 +338,19 @@ const SettingsFormFields = () => {
smart_count: 2,
})}
</h2>
+ <h3 className="text-lg font-medium text-muted-foreground">
+ {translate("crm.settings.deals.currency")}
+ </h3>
+ <AutocompleteInput
+ source="currency"
+ label={false}
+ choices={currencyChoices}
+ inputText={(choice) => choice?.id}
+ modal
+ />
+
+ <Separator />
+
<h3 className="text-lg font-medium text-muted-foreground">
{translate("crm.settings.deals.stages")}
</h3>