Skip to content

Commit

Permalink
Change organization currency selection to enum
Browse files Browse the repository at this point in the history
Fixes: #57
  • Loading branch information
MrBartusek committed Apr 29, 2024
1 parent 8214112 commit c77cce2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
6 changes: 4 additions & 2 deletions apps/client/src/components/Helpers/Currency.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex items-baseline gap-1">
{value} <div className="text-muted">{organization?.settings.currency || 'USD'}</div>
{value} <div className="text-muted">{suffix || resolvedSuffix}</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function OrganizationCardHeader({ organization }: OrganizationCardProps) {
<div className="flex items-center gap-4">
<div className="hidden items-center gap-3 md:flex">
<OrganizationStatsChip icon={BsWallet}>
<Currency>{organization.stats.totalValue}</Currency>
<Currency suffix={organization.settings.currency}>
{organization.stats.totalValue}
</Currency>
</OrganizationStatsChip>
<OrganizationStatsChip icon={BsTag}>
{organization.stats.totalProducts}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<OrganizationDto>();

return (
<div className="my-8">
<h2 className="mb-4 text-3xl">Organization Preferences</h2>
Expand All @@ -14,16 +14,27 @@ function OrganizationPreferencesTab() {

<RealtimeOrgSettingSelect
name="Organization value calculation strategy"
description="How should total organization and warehouse value be calculated. Buy price - organization
value will be calculated using real products value. Sell Price - organization value will be
calculated by value of items as if they were sold."
description="How should total organization and warehouse value be calculated.
Buy price - organization value will be calculated using real products value.
Sell Price - organization value will be calculated by value of items as if
they were sold."
organization={organization}
property="valueCalculationStrategy"
options={[
{ value: 'buyPrice', label: 'Buy price' },
{ value: 'sellPrice', label: 'Sell price' },
]}
/>

<RealtimeOrgSettingSelect
name="Organization currency"
description="Which currency should this organization use? Please note that this
is solely a visual representation, and your current prices will not be revalued
into the new currency."
organization={organization}
property="currency"
options={Object.keys(Currency).map((key) => ({ value: key, label: key }))}
/>
</div>
);
}
Expand Down

0 comments on commit c77cce2

Please sign in to comment.