From c77cce2501d4005eb358f04ebf51e7c0d4935906 Mon Sep 17 00:00:00 2001 From: Bartosz Dokurno Date: Mon, 29 Apr 2024 18:42:45 +0200 Subject: [PATCH] Change organization currency selection to enum Fixes: #57 --- .../dto/path-organization-settings.dto.ts | 10 ++++++++-- .../src/components/Helpers/Currency.tsx | 6 ++++-- .../OrganizationCardHeader.tsx | 4 +++- .../OrganizationPreferencesTab.tsx | 19 +++++++++++++++---- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/apps/api/src/models/organizations/dto/path-organization-settings.dto.ts b/apps/api/src/models/organizations/dto/path-organization-settings.dto.ts index 5c489065..760974ab 100644 --- a/apps/api/src/models/organizations/dto/path-organization-settings.dto.ts +++ b/apps/api/src/models/organizations/dto/path-organization-settings.dto.ts @@ -1,8 +1,14 @@ -import { IsIn, IsOptional } from 'class-validator'; +import { IsEnum, IsOptional } from 'class-validator'; import { IPatchOrganizationSettingsDto } from 'shared-types'; +import { OrgValueCalculationStrategy } from '../schemas/org-settings'; +import { Currency } from 'country-code-enum'; export class PatchOrganizationSettingsDto implements IPatchOrganizationSettingsDto { @IsOptional() - @IsIn(['buyPrice', 'sellPrice']) + @IsEnum(OrgValueCalculationStrategy) valueCalculationStrategy?: string; + + @IsOptional() + @IsEnum(Currency) + currency?: string; } diff --git a/apps/client/src/components/Helpers/Currency.tsx b/apps/client/src/components/Helpers/Currency.tsx index 7d30bfa3..871930f2 100644 --- a/apps/client/src/components/Helpers/Currency.tsx +++ b/apps/client/src/components/Helpers/Currency.tsx @@ -4,15 +4,17 @@ import { Utils } from '../../utils/utils'; export interface CurrencyProps { children: string | number; + suffix?: string; } -function Currency({ children }: CurrencyProps) { +function Currency({ children, suffix }: CurrencyProps) { const { organization } = useContext(CurrentAppContext); + const resolvedSuffix = organization?.settings.currency || 'USD'; const value = useMemo(() => Utils.humanizeNumber(Number(children)), [children]); return (
- {value}
{organization?.settings.currency || 'USD'}
+ {value}
{suffix || resolvedSuffix}
); } diff --git a/apps/client/src/components/OrganizationCard/OrganizationCardHeader.tsx b/apps/client/src/components/OrganizationCard/OrganizationCardHeader.tsx index 0fd75027..83fd4c71 100644 --- a/apps/client/src/components/OrganizationCard/OrganizationCardHeader.tsx +++ b/apps/client/src/components/OrganizationCard/OrganizationCardHeader.tsx @@ -21,7 +21,9 @@ function OrganizationCardHeader({ organization }: OrganizationCardProps) {
- {organization.stats.totalValue} + + {organization.stats.totalValue} + {organization.stats.totalProducts} diff --git a/apps/client/src/components/Pages/Organization/OrganizationPreferencesTab.tsx b/apps/client/src/components/Pages/Organization/OrganizationPreferencesTab.tsx index 63bbf6fc..906e90b7 100644 --- a/apps/client/src/components/Pages/Organization/OrganizationPreferencesTab.tsx +++ b/apps/client/src/components/Pages/Organization/OrganizationPreferencesTab.tsx @@ -1,10 +1,10 @@ import { useOutletContext } from 'react-router-dom'; import { OrganizationDto } from 'shared-types'; import RealtimeOrgSettingSelect from '../../RealtimeOrgSettingSelect'; +import { Currency } from 'country-code-enum'; function OrganizationPreferencesTab() { const organization = useOutletContext(); - return (

Organization Preferences

@@ -14,9 +14,10 @@ function OrganizationPreferencesTab() { + + ({ value: key, label: key }))} + />
); }