A local-first personal finance app
Improve schedule edit form responsiveness for mobile support (#6178)
Matiss Janis Aboltins2dfd62adb847
diff --git a/packages/desktop-client/src/components/autocomplete/AccountAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/AccountAutocomplete.tsxindex b9ea2fd995..e058df1a9d 100644--- a/packages/desktop-client/src/components/autocomplete/AccountAutocomplete.tsx+++ b/packages/desktop-client/src/components/autocomplete/AccountAutocomplete.tsx@@ -170,8 +170,11 @@ export function AccountAutocomplete({renderAccountItem,closeOnBlur,hiddenAccounts,+ inputProps,...props}: AccountAutocompleteProps) {+ const { t } = useTranslation();+const accounts = useAccounts() || [];//remove closed accounts if needed@@ -197,6 +200,10 @@ export function AccountAutocomplete({embedded={embedded}closeOnBlur={closeOnBlur}suggestions={accountSuggestions}+ inputProps={{+ ...inputProps,+ 'aria-label': t('Account'),+ }}renderItems={(items, getItemProps, highlightedIndex) => (<AccountListitems={items}diff --git a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsxindex c834652eb9..90c1efbb8c 100644--- a/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx+++ b/packages/desktop-client/src/components/autocomplete/PayeeAutocomplete.tsx@@ -347,6 +347,8 @@ export function PayeeAutocomplete({payees,...props}: PayeeAutocompleteProps) {+ const { t } = useTranslation();+const commonPayees = useCommonPayees();const retrievedPayees = usePayees();if (!payees) {@@ -474,6 +476,7 @@ export function PayeeAutocomplete({setRawPayee('');setPayeeFieldFocused(false);},+ 'aria-label': t('Payee'),onFocus: () => setPayeeFieldFocused(true),onChangeValue: setRawPayee,}}diff --git a/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx b/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsxindex b3f76b049d..09aae945aa 100644--- a/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx+++ b/packages/desktop-client/src/components/schedules/ScheduleEditForm.tsx@@ -3,6 +3,7 @@ import React from 'react';import { Trans, useTranslation } from 'react-i18next';import { Button } from '@actual-app/components/button';+import { useResponsive } from '@actual-app/components/hooks/useResponsive';import { InitialFocus } from '@actual-app/components/initial-focus';import { SpaceBetween } from '@actual-app/components/space-between';import { Text } from '@actual-app/components/text';@@ -16,8 +17,6 @@ import {type TransactionEntity,} from 'loot-core/types/models';-import { AccountAutocomplete } from '@desktop-client/components/autocomplete/AccountAutocomplete';-import { PayeeAutocomplete } from '@desktop-client/components/autocomplete/PayeeAutocomplete';import {FormField,FormLabel,@@ -50,7 +49,7 @@ export type ScheduleFormFields = {name: null | string;};-type ScheduleEditFormDispatch =+export type ScheduleEditFormDispatch =| {type: 'set-field';field: 'name' | 'account' | 'payee';@@ -97,8 +96,6 @@ type ScheduleEditFormProps = {onSwitchTransactions: (mode: 'linked' | 'matched') => void;onLinkTransactions: (ids: string[], scheduleId?: string) => Promise<void>;onUnlinkTransactions: (ids: string[]) => Promise<void>;- onSave: () => Promise<void>;- onCancel: () => void;};export function ScheduleEditForm({@@ -117,270 +114,287 @@ export function ScheduleEditForm({onSwitchTransactions,onLinkTransactions,onUnlinkTransactions,- onSave,- onCancel,}: ScheduleEditFormProps) {const locale = useLocale();const { t } = useTranslation();const dateFormat = useDateFormat() || 'MM/dd/yyyy';+ const { isNarrowWidth } = useResponsive();return (<>- <SpaceBetween style={{ marginTop: 10 }}>- <FormField style={{ flex: 1 }}>- <FormLabel title={t('Schedule Name')} htmlFor="name-field" />- <InitialFocus>- <GenericInput- type="string"- value={fields.name}- onChange={e => {- dispatch({ type: 'set-field', field: 'name', value: e });- }}- />- </InitialFocus>- </FormField>- </SpaceBetween>- <SpaceBetween style={{ marginTop: 20 }}>- <FormField style={{ flex: 1 }}>- <FormLabel- title={t('Payee')}- id="payee-label"- htmlFor="payee-field"- />- <PayeeAutocomplete- value={fields.payee}- labelProps={{ id: 'payee-label' }}- inputProps={{ id: 'payee-field', placeholder: t('(none)') }}- onSelect={id =>- dispatch({ type: 'set-field', field: 'payee', value: id })- }- />- </FormField>-- <FormField style={{ flex: 1 }}>- <FormLabel- title={t('Account')}- id="account-label"- htmlFor="account-field"- />- <AccountAutocomplete- includeClosedAccounts={false}- value={fields.account}- labelProps={{ id: 'account-label' }}- inputProps={{ id: 'account-field', placeholder: t('(none)') }}- onSelect={id =>- dispatch({ type: 'set-field', field: 'account', value: id })- }- />- </FormField>-- <FormField style={{ flex: 1 }}>- <SpaceBetween style={{ marginBottom: 3, alignItems: 'center' }}>+ <View style={{ display: 'block', overflow: 'scroll', padding: 10 }}>+ <SpaceBetween style={{ marginTop: 10 }}>+ <FormField style={{ flex: 1 }}>+ <FormLabel title={t('Schedule Name')} htmlFor="name-field" />+ <InitialFocus>+ <GenericInput+ type="string"+ value={fields.name}+ onChange={e => {+ dispatch({ type: 'set-field', field: 'name', value: e });+ }}+ />+ </InitialFocus>+ </FormField>+ </SpaceBetween>+ <SpaceBetween+ style={{+ marginTop: 20,+ display: isNarrowWidth ? 'grid' : 'flex',+ gridTemplateColumns: '1fr 1fr',+ }}+ >+ <FormField style={{ flex: 1 }}><FormLabel- title={t('Amount')}- htmlFor="amount-field"- style={{ margin: 0, flex: 1 }}+ title={t('Payee')}+ id="payee-label"+ htmlFor="payee-field"/>- <OpSelect- ops={['isapprox', 'is', 'isbetween']}- value={fields.amountOp as 'isapprox' | 'is' | 'isbetween'}- formatOp={op => {- switch (op) {- case 'is':- return t('is exactly');- case 'isapprox':- return t('is approximately');- case 'isbetween':- return t('is between');- default:- throw new Error('Invalid op for select: ' + op);- }- }}- style={{- padding: '0 10px',- color: theme.pageTextLight,- fontSize: 12,- }}- onChange={(_, op) =>- dispatch({- type: 'set-field',- field: 'amountOp',- value: op,- })- }- />- </SpaceBetween>- {fields.amountOp === 'isbetween' ? (- <BetweenAmountInput- // @ts-expect-error fix me- defaultValue={fields.amount}- onChange={value =>- dispatch({- type: 'set-field',- field: 'amount',- value,- })- }- />- ) : (- <AmountInput- id="amount-field"- // @ts-expect-error fix me- value={fields.amount}- onUpdate={value =>- dispatch({- type: 'set-field',- field: 'amount',- value,- })+ <GenericInput+ type="id"+ field="payee"+ value={fields.payee || ''}+ onChange={id =>+ dispatch({ type: 'set-field', field: 'payee', value: id })}/>- )}- </FormField>- </SpaceBetween>+ </FormField>- <View style={{ marginTop: 20 }}>- <FormLabel title={t('Date')} />- </View>-- <SpaceBetween- style={{- alignItems: 'flex-start',- justifyContent: 'space-between',- }}- >- <View style={{ width: '13.44rem' }}>- {repeats ? (- <RecurringSchedulePicker- // @ts-expect-error fix me- value={fields.date}- onChange={value =>- dispatch({ type: 'set-field', field: 'date', value })- }+ <FormField style={{ flex: 1 }}>+ <FormLabel+ title={t('Account')}+ id="account-label"+ htmlFor="account-field"/>- ) : (- <DateSelect- // @ts-expect-error fix me- value={fields.date}- onSelect={date =>- dispatch({ type: 'set-field', field: 'date', value: date })+ <GenericInput+ type="id"+ field="account"+ value={fields.account || ''}+ onChange={id =>+ dispatch({ type: 'set-field', field: 'account', value: id })}- dateFormat={dateFormat}/>- )}+ </FormField>- {upcomingDates && (- <View style={{ fontSize: 13, marginTop: 20 }}>- <Text style={{ color: theme.pageTextLight, fontWeight: 600 }}>- <Trans>Upcoming dates</Trans>- </Text>- <SpaceBetween- direction="vertical"- gap={5}+ <FormField style={{ flex: 1, gridColumn: '1 / -1' }}>+ <SpaceBetween style={{ marginBottom: 3, alignItems: 'center' }}>+ <FormLabel+ title={t('Amount')}+ htmlFor="amount-field"+ style={{ margin: 0, flex: 1 }}+ />+ <OpSelect+ ops={['isapprox', 'is', 'isbetween']}+ value={fields.amountOp as 'isapprox' | 'is' | 'isbetween'}+ formatOp={op => {+ switch (op) {+ case 'is':+ return t('is exactly');+ case 'isapprox':+ return t('is approximately');+ case 'isbetween':+ return t('is between');+ default:+ throw new Error('Invalid op for select: ' + op);+ }+ }}style={{- marginTop: 10,+ padding: '0 10px',color: theme.pageTextLight,- alignItems: 'flex-start',+ fontSize: 12,}}- >- {upcomingDates.map(date => (- <View key={date}>- {monthUtils.format(date, `${dateFormat} EEEE`, locale)}- </View>- ))}- </SpaceBetween>- </View>- )}+ onChange={(_, op) =>+ dispatch({+ type: 'set-field',+ field: 'amountOp',+ value: op,+ })+ }+ />+ </SpaceBetween>+ {fields.amountOp === 'isbetween' ? (+ <BetweenAmountInput+ // @ts-expect-error fix me+ defaultValue={fields.amount}+ onChange={value =>+ dispatch({+ type: 'set-field',+ field: 'amount',+ value,+ })+ }+ />+ ) : (+ <AmountInput+ id="amount-field"+ // @ts-expect-error fix me+ value={fields.amount}+ onUpdate={value =>+ dispatch({+ type: 'set-field',+ field: 'amount',+ value,+ })+ }+ />+ )}+ </FormField>+ </SpaceBetween>++ <View style={{ marginTop: 20 }}>+ <FormLabel title={t('Date')} /></View>- <View+ <SpaceBetweenstyle={{- marginTop: 5,- flexDirection: 'row',- alignItems: 'center',- userSelect: 'none',+ alignItems: 'flex-start',+ justifyContent: 'space-between',}}>- <Checkbox- id="form_repeats"- checked={repeats}- onChange={e => {- dispatch({ type: 'set-repeats', repeats: e.target.checked });- }}- />- <label htmlFor="form_repeats" style={{ userSelect: 'none' }}>- <Trans>Repeats</Trans>- </label>- </View>+ <View style={{ width: '13.44rem' }}>+ {repeats ? (+ <RecurringSchedulePicker+ // @ts-expect-error fix me+ value={fields.date}+ onChange={value =>+ dispatch({ type: 'set-field', field: 'date', value })+ }+ />+ ) : (+ <DateSelect+ // @ts-expect-error fix me+ value={fields.date}+ onSelect={date =>+ dispatch({ type: 'set-field', field: 'date', value: date })+ }+ dateFormat={dateFormat}+ />+ )}++ {upcomingDates && (+ <View style={{ fontSize: 13, marginTop: 20 }}>+ <Text style={{ color: theme.pageTextLight, fontWeight: 600 }}>+ <Trans>Upcoming dates</Trans>+ </Text>+ <SpaceBetween+ direction="vertical"+ gap={5}+ style={{+ marginTop: 10,+ color: theme.pageTextLight,+ alignItems: 'flex-start',+ }}+ >+ {upcomingDates.map(date => (+ <View key={date}>+ {monthUtils.format(date, `${dateFormat} EEEE`, locale)}+ </View>+ ))}+ </SpaceBetween>+ </View>+ )}+ </View>- <SpaceBetween direction="vertical" style={{ alignItems: 'flex-end' }}><Viewstyle={{marginTop: 5,flexDirection: 'row',alignItems: 'center',userSelect: 'none',- justifyContent: 'flex-end',}}><Checkbox- id="form_posts_transaction"- checked={fields.posts_transaction}+ id="form_repeats"+ checked={repeats}onChange={e => {- dispatch({- type: 'set-field',- field: 'posts_transaction',- value: e.target.checked,- });+ dispatch({ type: 'set-repeats', repeats: e.target.checked });}}/>- <label- htmlFor="form_posts_transaction"- style={{ userSelect: 'none' }}- >- <Trans>Automatically add transaction</Trans>+ <label htmlFor="form_repeats" style={{ userSelect: 'none' }}>+ <Trans>Repeats</Trans></label></View>- <Text- style={{- width: 350,- textAlign: 'right',- color: theme.pageTextLight,- marginTop: 10,- fontSize: 13,- lineHeight: '1.4em',- }}+ <SpaceBetween+ gap={5}+ direction="vertical"+ style={{ alignItems: 'flex-end' }}>- <Trans>- If checked, the schedule will automatically create transactions- for you in the specified account- </Trans>- </Text>+ <View+ style={{+ marginTop: 5,+ flexDirection: 'row',+ alignItems: 'center',+ userSelect: 'none',+ justifyContent: 'flex-end',+ }}+ >+ <Checkbox+ id="form_posts_transaction"+ checked={fields.posts_transaction}+ onChange={e => {+ dispatch({+ type: 'set-field',+ field: 'posts_transaction',+ value: e.target.checked,+ });+ }}+ />+ <label+ htmlFor="form_posts_transaction"+ style={{ userSelect: 'none' }}+ >+ <Trans>Automatically add transaction</Trans>+ </label>+ </View>- {!adding && schedule.rule && (- <SpaceBetween style={{ marginTop: 20, alignItems: 'center' }}>- {isCustom && (- <Text- style={{- color: theme.pageTextLight,- fontSize: 13,- textAlign: 'right',- width: 350,- }}- >- <Trans>This schedule has custom conditions and actions</Trans>- </Text>- )}- <Button onPress={() => onEditRule(schedule.rule)}>- <Trans>Edit as rule</Trans>- </Button>- </SpaceBetween>- )}+ <Text+ style={{+ width: 350,+ textAlign: 'right',+ color: theme.pageTextLight,+ fontSize: 13,+ lineHeight: '1.4em',+ }}+ >+ <Trans>+ If checked, the schedule will automatically create transactions+ for you in the specified account+ </Trans>+ </Text>++ {!adding && schedule.rule && (+ <SpaceBetween style={{ marginTop: 20, alignItems: 'center' }}>+ {isCustom && (+ <Text+ style={{+ color: theme.pageTextLight,+ fontSize: 13,+ textAlign: 'right',+ width: 350,+ }}+ >+ <Trans>+ This schedule has custom conditions and actions+ </Trans>+ </Text>+ )}+ <Button onPress={() => onEditRule(schedule.rule)}>+ <Trans>Edit as rule</Trans>+ </Button>+ </SpaceBetween>+ )}+ </SpaceBetween></SpaceBetween>- </SpaceBetween>+ </View>- <View style={{ marginTop: 30, flex: 1 }}>+ <View+ style={{+ padding: 10,+ minHeight: 150,+ borderTop: `1px solid ${theme.tableBorder}`,+ }}+ ><SelectedProvider instance={selectedInst}>{adding ? (<View style={{ flexDirection: 'row', padding: '5px 0' }}>@@ -465,21 +479,9 @@ export function ScheduleEditForm({</SelectedProvider></View>- <SpaceBetween- style={{- marginTop: 20,- justifyContent: 'flex-end',- alignItems: 'center',- }}- >- {error && <Text style={{ color: theme.errorText }}>{error}</Text>}- <Button style={{ marginRight: 10 }} onPress={onCancel}>- <Trans>Cancel</Trans>- </Button>- <Button variant="primary" onPress={onSave}>- {adding ? t('Add') : t('Save')}- </Button>- </SpaceBetween>+ {error && (+ <Text style={{ color: theme.errorText, marginTop: 10 }}>{error}</Text>+ )}</>);}diff --git a/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx b/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsxindex 53d1613c43..b98e53842b 100644--- a/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx+++ b/packages/desktop-client/src/components/schedules/ScheduleEditModal.tsx@@ -1,7 +1,9 @@// @ts-strict-ignoreimport React, { useEffect, useReducer } from 'react';-import { useTranslation } from 'react-i18next';+import { useTranslation, Trans } from 'react-i18next';+import { Button } from '@actual-app/components/button';+import { SpaceBetween } from '@actual-app/components/space-between';import { t } from 'i18next';import { send, sendCatch } from 'loot-core/platform/client/fetch';@@ -600,9 +602,22 @@ export function ScheduleEditModal({ id, transaction }: ScheduleEditModalProps) {onSwitchTransactions={onSwitchTransactions}onLinkTransactions={onLinkTransactions}onUnlinkTransactions={onUnlinkTransactions}- onSave={() => onSave(close)}- onCancel={close}/>++ <SpaceBetween+ style={{+ marginTop: 20,+ justifyContent: 'flex-end',+ alignItems: 'center',+ }}+ >+ <Button onPress={close}>+ <Trans>Cancel</Trans>+ </Button>+ <Button variant="primary" onPress={() => onSave(close)}>+ {adding ? t('Add') : t('Save')}+ </Button>+ </SpaceBetween></>)}</Modal>diff --git a/upcoming-release-notes/6178.md b/upcoming-release-notes/6178.mdnew file mode 100644index 0000000000..a9b41e3e1d--- /dev/null+++ b/upcoming-release-notes/6178.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [MatissJanis]+---++Improve schedule edit form responsitivity for mobile support (soon)