A local-first personal finance app
fix: add missing error handling to transaction creation page (#6336)
Matiss Janis Aboltins3d19873e4fcd
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsxindex fe16647c45..726a28cabb 100644--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx@@ -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;}diff --git a/upcoming-release-notes/6336.md b/upcoming-release-notes/6336.mdnew file mode 100644index 0000000000..06fc7a063a--- /dev/null+++ b/upcoming-release-notes/6336.md@@ -0,0 +1,6 @@+---+category: Bugfix+authors: [MatissJanis]+---++Add error handling prompts for missing accounts and categories on the transaction creation page.