Skip to content

Commit

Permalink
Make currency nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Jan 8, 2025
1 parent 0463bfa commit 580e7b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ const Preferences: React.FC = () => {
}
accountListId={accountListId}
currency={
accountPreferencesData?.accountList?.settings?.currency || ''
accountPreferencesData?.accountList?.settings?.currency || null
}
disabled={onSetupTour && setup !== 1}
handleSetupChange={handleSetupChange}
Expand All @@ -267,7 +267,7 @@ const Preferences: React.FC = () => {
handleAccordionChange={handleAccordionChange}
expandedPanel={expandedPanel}
currency={
accountPreferencesData?.accountList?.settings?.currency || ''
accountPreferencesData?.accountList?.settings?.currency || null
}
accountListId={accountListId}
disabled={onSetupTour}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const preferencesSchema: yup.ObjectSchema<
interface CurrencyAccordionProps {
handleAccordionChange: (panel: string) => void;
expandedPanel: string;
currency: string;
currency: string | null;
accountListId: string;
disabled?: boolean;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ export const CurrencyAccordion: React.FC<CurrencyAccordionProps> = ({
onAccordionChange={handleAccordionChange}
expandedPanel={expandedPanel}
label={label}
value={currency}
value={currency ?? ''}
fullWidth
disabled={disabled}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ interface ComponentsProps {
const Components: React.FC<ComponentsProps> = ({
monthlyGoal,
machineCalculatedGoal,
machineCalculatedGoalCurrency = null,
machineCalculatedGoalCurrency = 'USD',
expandedPanel,
}) => (
<SnackbarProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const accountPreferencesSchema: yup.ObjectSchema<

const formatMonthlyGoal = (
goal: number | null,
currency: string,
currency: string | null,
locale: string,
): string => {
if (goal === null) {
return '';
}

if (currency && locale) {
if (currency) {
return currencyFormat(goal, currency, locale);
}
return goal.toString();
Expand All @@ -39,7 +39,7 @@ interface MonthlyGoalAccordionProps {
expandedPanel: string;
monthlyGoal: number | null;
accountListId: string;
currency: string;
currency: string | null;
disabled?: boolean;
handleSetupChange: () => Promise<void>;
}
Expand Down Expand Up @@ -67,9 +67,14 @@ export const MonthlyGoalAccordion: React.FC<MonthlyGoalAccordionProps> = ({
});
const calculatedGoal = data?.healthIndicatorData[0]?.machineCalculatedGoal;
const calculatedCurrency =
data?.healthIndicatorData[0]?.machineCalculatedGoalCurrency ?? currency;
data?.healthIndicatorData[0]?.machineCalculatedGoalCurrency;
const formattedCalculatedGoal = useMemo(
() => formatMonthlyGoal(calculatedGoal ?? null, calculatedCurrency, locale),
() =>
formatMonthlyGoal(
calculatedGoal ?? null,
calculatedCurrency ?? null,
locale,
),
[calculatedGoal, calculatedCurrency, locale],
);

Expand Down

0 comments on commit 580e7b1

Please sign in to comment.