Files
actual/packages/desktop-client/src/components/budget/report/budgetsummary/BudgetMonthMenu.tsx

82 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import React, { type ComponentPropsWithoutRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useFeatureFlag } from '../../../../hooks/useFeatureFlag';
import { Menu } from '../../../common/Menu';
type BudgetMonthMenuProps = Omit<
ComponentPropsWithoutRef<typeof Menu>,
'onMenuSelect' | 'items'
> & {
onCopyLastMonthBudget: () => void;
onSetBudgetsToZero: () => void;
onSetMonthsAverage: (numberOfMonths: number) => void;
onCheckTemplates: () => void;
onApplyBudgetTemplates: () => void;
onOverwriteWithBudgetTemplates: () => void;
};
export function BudgetMonthMenu({
onCopyLastMonthBudget,
onSetBudgetsToZero,
onSetMonthsAverage,
onCheckTemplates,
onApplyBudgetTemplates,
onOverwriteWithBudgetTemplates,
...props
}: BudgetMonthMenuProps) {
const { t } = useTranslation();
const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
return (
<Menu
{...props}
onMenuSelect={name => {
switch (name) {
case 'copy-last':
onCopyLastMonthBudget();
break;
case 'set-zero':
onSetBudgetsToZero();
break;
case 'set-3-avg':
onSetMonthsAverage(3);
break;
case 'check-templates':
onCheckTemplates();
break;
case 'apply-goal-template':
onApplyBudgetTemplates();
break;
case 'overwrite-goal-template':
onOverwriteWithBudgetTemplates();
break;
}
}}
items={[
{ name: 'copy-last', text: t('Copy last months budget') },
{ name: 'set-zero', text: t('Set budgets to zero') },
{
name: 'set-3-avg',
text: t('Set budgets to 3 month average'),
},
...(isGoalTemplatesEnabled
? [
{
name: 'check-templates',
text: t('Check templates'),
},
{
name: 'apply-goal-template',
text: t('Apply budget template'),
},
{
name: 'overwrite-goal-template',
text: t('Overwrite with budget template'),
},
]
: []),
]}
/>
);
}