Skip to content

A local-first personal finance app

add action button to trigger applyBudgetTemplatesInGroup to mobile (#5293)

Dreptschar38ab63638a99
diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryGroupActionMenu.tsx b/packages/desktop-client/src/components/mobile/budget/CategoryGroupActionMenu.tsx
new file mode 100644
index 0000000000..ce8cb12c18
--- /dev/null
+++ b/packages/desktop-client/src/components/mobile/budget/CategoryGroupActionMenu.tsx
@@ -0,0 +1,43 @@
+import React, { type ComponentPropsWithoutRef } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { Menu } from '@actual-app/components/menu';
+
+import { useFeatureFlag } from '@desktop-client/hooks/useFeatureFlag';
+
+type CategoryGroupActionMenuProps = Omit<
+ ComponentPropsWithoutRef<typeof Menu>,
+ 'onMenuSelect' | 'items'
+> & {
+ onApplyBudgetTemplatesInGroup: () => void;
+};
+export function CategoryGroupActionMenu({
+ onApplyBudgetTemplatesInGroup,
+ ...props
+}: CategoryGroupActionMenuProps) {
+ const { t } = useTranslation();
+
+ const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
+ return (
+ <Menu
+ {...props}
+ onMenuSelect={name => {
+ switch (name) {
+ case 'apply-budget-templates-in-group':
+ onApplyBudgetTemplatesInGroup();
+ break;
+ }
+ }}
+ items={[
+ ...(isGoalTemplatesEnabled
+ ? [
+ {
+ name: 'apply-budget-templates-in-group',
+ text: t('Apply budget template'),
+ },
+ ]
+ : []),
+ ]}
+ />
+ );
+}
diff --git a/packages/desktop-client/src/components/mobile/budget/index.tsx b/packages/desktop-client/src/components/mobile/budget/index.tsx
index 96e8d60337..28e914750b 100644
--- a/packages/desktop-client/src/components/mobile/budget/index.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/index.tsx
@@ -151,6 +151,21 @@ export function Budget() {
[dispatch],
);
+ const onApplyBudgetTemplatesInGroup = useCallback(
+ async categories => {
+ dispatch(
+ applyBudgetAction({
+ month: startMonth,
+ type: 'apply-multiple-templates',
+ args: {
+ categories,
+ },
+ }),
+ );
+ },
+ [dispatch, startMonth],
+ );
+
const onDeleteGroup = useCallback(
async groupId => {
const group = categoryGroups?.find(g => g.id === groupId);
@@ -378,6 +393,7 @@ export function Budget() {
onEditNotes: onOpenCategoryGroupNotesModal,
onDelete: onDeleteGroup,
onToggleVisibility: onToggleGroupVisibility,
+ onApplyBudgetTemplatesInGroup,
},
},
}),
@@ -391,6 +407,7 @@ export function Budget() {
onOpenNewCategoryModal,
onSaveGroup,
onToggleGroupVisibility,
+ onApplyBudgetTemplatesInGroup,
],
);
diff --git a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx
index bb3858aef0..400e7ed4c2 100644
--- a/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/CategoryGroupMenuModal.tsx
@@ -1,10 +1,5 @@
// @ts-strict-ignore
-import React, {
- type ComponentProps,
- useRef,
- useState,
- type CSSProperties,
-} from 'react';
+import React, { type ComponentProps, useRef, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
@@ -12,6 +7,8 @@ import {
SvgDotsHorizontalTriple,
SvgAdd,
SvgTrash,
+ SvgCheveronDown,
+ SvgCheveronUp,
} from '@actual-app/components/icons/v1';
import {
SvgNotesPaper,
@@ -20,9 +17,10 @@ import {
} from '@actual-app/components/icons/v2';
import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
-import { styles } from '@actual-app/components/styles';
+import { styles, type CSSProperties } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { css } from '@emotion/css';
import {
Modal,
@@ -30,9 +28,12 @@ import {
ModalHeader,
ModalTitle,
} from '@desktop-client/components/common/Modal';
+import { CategoryGroupActionMenu } from '@desktop-client/components/mobile/budget/CategoryGroupActionMenu';
import { Notes } from '@desktop-client/components/Notes';
import { useCategories } from '@desktop-client/hooks/useCategories';
+import { useFeatureFlag } from '@desktop-client/hooks/useFeatureFlag';
import { useNotes } from '@desktop-client/hooks/useNotes';
+import { useUndo } from '@desktop-client/hooks/useUndo';
import { type Modal as ModalType } from '@desktop-client/modals/modalsSlice';
type CategoryGroupMenuModalProps = Extract<
@@ -48,10 +49,15 @@ export function CategoryGroupMenuModal({
onDelete,
onToggleVisibility,
onClose,
+ onApplyBudgetTemplatesInGroup,
}: CategoryGroupMenuModalProps) {
+ const [showMore, setShowMore] = useState(false);
const { grouped: categoryGroups } = useCategories();
const group = categoryGroups.find(g => g.id === groupId);
const notes = useNotes(group.id);
+ const { showUndoNotification } = useUndo();
+ const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
+ const { t } = useTranslation();
const onRename = newName => {
if (newName && newName !== group.name) {
@@ -62,6 +68,10 @@ export function CategoryGroupMenuModal({
}
};
+ const onShowMore = () => {
+ setShowMore(!showMore);
+ };
+
const _onAddCategory = () => {
onAddCategory?.(group.id, group.is_income);
};
@@ -78,6 +88,12 @@ export function CategoryGroupMenuModal({
onToggleVisibility?.(group.id);
};
+ const _onApplyBudgetTemplatesInGroup = () => {
+ onApplyBudgetTemplatesInGroup?.(
+ group.categories.filter(c => !c.hidden).map(c => c.id),
+ );
+ };
+
const buttonStyle: CSSProperties = {
...styles.mediumText,
height: styles.mobileMinHeight,
@@ -88,6 +104,22 @@ export function CategoryGroupMenuModal({
marginRight: '1%',
};
+ const actionButtonStyle: CSSProperties = {
+ ...styles.mediumText,
+ height: styles.mobileMinHeight,
+ color: theme.formLabelText,
+ // Adjust based on desired number of buttons per row.
+ flexBasis: '100%',
+ };
+
+ const defaultMenuItemStyle: CSSProperties = {
+ ...styles.mobileMenuItem,
+ height: styles.mobileMinHeight,
+ color: theme.menuItemText,
+ borderRadius: 0,
+ borderTop: `1px solid ${theme.pillBorder}`,
+ };
+
return (
<Modal
name="category-group-menu"
@@ -165,7 +197,50 @@ export function CategoryGroupMenuModal({
/>
<Trans>Edit notes</Trans>
</Button>
+ {isGoalTemplatesEnabled && (
+ <Button
+ variant="bare"
+ className={css([
+ actionButtonStyle,
+ {
+ '&[data-pressed], &[data-hovered]': {
+ backgroundColor: 'transparent',
+ color: buttonStyle.color,
+ },
+ },
+ ])}
+ onPress={onShowMore}
+ >
+ {!showMore ? (
+ <SvgCheveronUp
+ width={30}
+ height={30}
+ style={{ paddingRight: 5 }}
+ />
+ ) : (
+ <SvgCheveronDown
+ width={30}
+ height={30}
+ style={{ paddingRight: 5 }}
+ />
+ )}
+ <Trans>Actions</Trans>
+ </Button>
+ )}
</View>
+ {showMore && (
+ <CategoryGroupActionMenu
+ style={{ overflowY: 'auto', paddingTop: 10 }}
+ getItemStyle={() => defaultMenuItemStyle}
+ onApplyBudgetTemplatesInGroup={() => {
+ _onApplyBudgetTemplatesInGroup();
+ close();
+ showUndoNotification({
+ message: t('budget templates have been applied.'),
+ });
+ }}
+ />
+ )}
</View>
</>
)}
diff --git a/packages/desktop-client/src/modals/modalsSlice.ts b/packages/desktop-client/src/modals/modalsSlice.ts
index 8fd71b9ac2..2509fd5303 100644
--- a/packages/desktop-client/src/modals/modalsSlice.ts
+++ b/packages/desktop-client/src/modals/modalsSlice.ts
@@ -331,6 +331,9 @@ export type Modal =
onDelete: (groupId: CategoryGroupEntity['id']) => void;
onToggleVisibility: (groupId: CategoryGroupEntity['id']) => void;
onClose?: () => void;
+ onApplyBudgetTemplatesInGroup?: (
+ categories: Array<CategoryEntity['id']>,
+ ) => void;
};
}
| {
diff --git a/upcoming-release-notes/5293.md b/upcoming-release-notes/5293.md
new file mode 100644
index 0000000000..3b7e070412
--- /dev/null
+++ b/upcoming-release-notes/5293.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [Dreptschar]
+---
+
+Adds a button to mobile CategoryGroupMenu that allows users to apply all budget templates in this group