mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 19:14:22 -05:00
fix: add missing error handling to transaction creation page (#6336)
* feat: Show add account prompt when no accounts exist Co-authored-by: matiss <matiss@mja.lv> * Fix: Show category creation prompt when no categories exist Co-authored-by: matiss <matiss@mja.lv> * Refactor: Navigate to budget instead of opening modal Co-authored-by: matiss <matiss@mja.lv> * Add release notes for PR #6336 * [autofix.ci] apply automated fixes --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
71fe875462
commit
3d19873e4f
@@ -1290,10 +1290,12 @@ function TransactionEditUnconnected({
|
||||
lastTransaction,
|
||||
dateFormat,
|
||||
}: TransactionEditUnconnectedProps) {
|
||||
const { t } = useTranslation();
|
||||
const { transactionId } = useParams();
|
||||
const { state: locationState } = useLocation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const [transactions, setTransactions] = useState<TransactionEntity[]>([]);
|
||||
const [fetchedTransactions, setFetchedTransactions] = useState<
|
||||
TransactionEntity[]
|
||||
@@ -1526,11 +1528,109 @@ function TransactionEditUnconnected({
|
||||
[transactions],
|
||||
);
|
||||
|
||||
if (
|
||||
categories.length === 0 ||
|
||||
accounts.length === 0 ||
|
||||
transactions.length === 0
|
||||
) {
|
||||
if (accounts.length === 0) {
|
||||
return (
|
||||
<Page
|
||||
header={
|
||||
<MobilePageHeader
|
||||
title={t('New Transaction')}
|
||||
leftContent={<MobileBackButton />}
|
||||
/>
|
||||
}
|
||||
padding={0}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 20,
|
||||
backgroundColor: theme.mobilePageBackground,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 15,
|
||||
textAlign: 'center',
|
||||
marginBottom: 20,
|
||||
lineHeight: '1.5em',
|
||||
}}
|
||||
>
|
||||
<Trans>
|
||||
To add a transaction, you need to{' '}
|
||||
<strong>create an account first</strong>. You can add an account
|
||||
from the accounts page.
|
||||
</Trans>
|
||||
</Text>
|
||||
<Button
|
||||
variant="primary"
|
||||
onPress={() => {
|
||||
dispatch(
|
||||
pushModal({
|
||||
modal: { name: 'add-account', options: {} },
|
||||
}),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<Trans>Add account</Trans>
|
||||
</Button>
|
||||
</View>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
||||
if (categories.length === 0) {
|
||||
return (
|
||||
<Page
|
||||
header={
|
||||
<MobilePageHeader
|
||||
title={t('New Transaction')}
|
||||
leftContent={<MobileBackButton />}
|
||||
/>
|
||||
}
|
||||
padding={0}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
padding: 20,
|
||||
backgroundColor: theme.mobilePageBackground,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
fontSize: 15,
|
||||
textAlign: 'center',
|
||||
marginBottom: 20,
|
||||
lineHeight: '1.5em',
|
||||
}}
|
||||
>
|
||||
<Trans>
|
||||
To add a transaction, you need to{' '}
|
||||
<strong>create a category first</strong>. You can add categories
|
||||
from the budget page.
|
||||
</Trans>
|
||||
</Text>
|
||||
<Button
|
||||
variant="primary"
|
||||
onPress={() => {
|
||||
navigate('/budget');
|
||||
}}
|
||||
>
|
||||
<Trans>Go to budget</Trans>
|
||||
</Button>
|
||||
</View>
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
||||
// This check ensures the component only renders after the transaction state
|
||||
// has been properly initialized. When creating a new transaction (transactionId === 'new'),
|
||||
// the transaction is created in a useEffect that runs after the component mounts.
|
||||
// Returning null here acts as a loading state until that initialization completes.
|
||||
if (transactions.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user