Skip to content

A local-first personal finance app

automation UI: allow "save by date" automations not to repeat (#7810)

Matt Fiddaman92d4f82b6685
diff --git a/packages/desktop-client/src/components/budget/goals/editor/BySaveAutomation.tsx b/packages/desktop-client/src/components/budget/goals/editor/BySaveAutomation.tsx
index f5f013bfd1..c5dc025ab7 100644
--- a/packages/desktop-client/src/components/budget/goals/editor/BySaveAutomation.tsx
+++ b/packages/desktop-client/src/components/budget/goals/editor/BySaveAutomation.tsx
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react';
-import { useTranslation } from 'react-i18next';
+import { Trans, useTranslation } from 'react-i18next';
import { Input } from '@actual-app/components/input';
import { Select } from '@actual-app/components/select';
@@ -10,6 +10,7 @@ import type { ByTemplate } from '@actual-app/core/types/models/templates';
import { updateTemplate } from '#components/budget/goals/actions';
import type { Action } from '#components/budget/goals/actions';
import { FormField, FormLabel } from '#components/forms';
+import { LabeledCheckbox } from '#components/forms/LabeledCheckbox';
import { AmountInput } from '#components/util/AmountInput';
import { GenericInput } from '#components/util/GenericInput';
import { useFormat } from '#hooks/useFormat';
@@ -44,6 +45,8 @@ export const BySaveAutomation = ({
}
};
+ const repeats = !!template.repeat;
+
return (
<>
<SpaceBetween align="center" gap={10} style={{ marginTop: 10 }}>
@@ -82,34 +85,63 @@ export const BySaveAutomation = ({
</SpaceBetween>
<SpaceBetween align="center" gap={10} style={{ marginTop: 10 }}>
<FormField style={{ flex: 1 }}>
- <FormLabel
- title={t('Repeat every')}
- htmlFor="by-repeat-amount-field"
- />
- <Input
- id="by-repeat-amount-field"
- type="number"
- min={1}
- step={1}
- value={rawRepeat}
- onChangeValue={setRawRepeat}
- onBlur={commitRepeat}
- />
- </FormField>
- <FormField style={{ flex: 1 }}>
- <FormLabel title={t('Period')} htmlFor="by-period-field" />
- <Select
- id="by-period-field"
- value={template.annual ? 'year' : 'month'}
- onChange={value =>
- dispatch(updateTemplate({ type: 'by', annual: value === 'year' }))
+ <LabeledCheckbox
+ id="by-repeats-field"
+ checked={repeats}
+ onChange={e =>
+ dispatch(
+ updateTemplate(
+ e.target.checked
+ ? {
+ type: 'by',
+ annual: false,
+ repeat: template.repeat ?? 1,
+ }
+ : { type: 'by', annual: undefined, repeat: undefined },
+ ),
+ )
}
- options={[
- ['month', t('Months')],
- ['year', t('Years')],
- ]}
- />
+ >
+ <span style={{ marginLeft: 6, fontSize: 12, whiteSpace: 'nowrap' }}>
+ <Trans>Repeats</Trans>
+ </span>
+ </LabeledCheckbox>
</FormField>
+ {repeats && (
+ <>
+ <FormField style={{ flex: 1 }}>
+ <FormLabel
+ title={t('Repeat every')}
+ htmlFor="by-repeat-amount-field"
+ />
+ <Input
+ id="by-repeat-amount-field"
+ type="number"
+ min={1}
+ step={1}
+ value={rawRepeat}
+ onChangeValue={setRawRepeat}
+ onBlur={commitRepeat}
+ />
+ </FormField>
+ <FormField style={{ flex: 1 }}>
+ <FormLabel title={t('Period')} htmlFor="by-period-field" />
+ <Select
+ id="by-period-field"
+ value={template.annual ? 'year' : 'month'}
+ onChange={value =>
+ dispatch(
+ updateTemplate({ type: 'by', annual: value === 'year' }),
+ )
+ }
+ options={[
+ ['month', t('Months')],
+ ['year', t('Years')],
+ ]}
+ />
+ </FormField>
+ </>
+ )}
</SpaceBetween>
</>
);
diff --git a/packages/desktop-client/src/components/budget/goals/reducer.ts b/packages/desktop-client/src/components/budget/goals/reducer.ts
index c6c161b50a..f2ced53bcc 100644
--- a/packages/desktop-client/src/components/budget/goals/reducer.ts
+++ b/packages/desktop-client/src/components/budget/goals/reducer.ts
@@ -51,7 +51,10 @@ export const getInitialState = (template: Template | null): ReducerState => {
throw new Error('Goal is not yet supported');
case 'by':
return {
- template,
+ template:
+ template.annual !== undefined && template.repeat == null
+ ? { ...template, repeat: 1 }
+ : template,
displayType: 'by',
};
case 'remainder':
diff --git a/upcoming-release-notes/7810.md b/upcoming-release-notes/7810.md
new file mode 100644
index 0000000000..5a07c6b5a7
--- /dev/null
+++ b/upcoming-release-notes/7810.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [matt-fidd]
+---
+
+Automation UI: Allow "save by date" automations not to repeat