Skip to content
Snippets Groups Projects
Unverified Commit b3669b30 authored by Joel Jeremy Marquez's avatar Joel Jeremy Marquez Committed by GitHub
Browse files

Fix reports form submit handlers (#3462)

* Fix form submit handlers

* Release notes
parent 6f41b20c
No related branches found
No related tags found
No related merge requests found
import React, { createRef, useEffect, useState } from 'react'; import React, { createRef, useEffect, useState } from 'react';
import { Form } from 'react-aria-components';
import { theme } from '../../style/theme'; import { theme } from '../../style/theme';
import { Button } from '../common/Button2'; import { Button } from '../common/Button2';
...@@ -24,7 +25,18 @@ export function SaveReportChoose({ onApply }: SaveReportChooseProps) { ...@@ -24,7 +25,18 @@ export function SaveReportChoose({ onApply }: SaveReportChooseProps) {
return ( return (
<> <>
<form> <Form
onSubmit={e => {
e.preventDefault();
if (!value) {
setErr('Invalid report entered');
return;
}
onApply(value);
}}
>
<View style={{ flexDirection: 'row', align: 'center' }}> <View style={{ flexDirection: 'row', align: 'center' }}>
<Text style={{ userSelect: 'none', flex: 1 }}>Choose Report</Text> <Text style={{ userSelect: 'none', flex: 1 }}>Choose Report</Text>
<View style={{ flex: 1 }} /> <View style={{ flex: 1 }} />
...@@ -47,21 +59,11 @@ export function SaveReportChoose({ onApply }: SaveReportChooseProps) { ...@@ -47,21 +59,11 @@ export function SaveReportChoose({ onApply }: SaveReportChooseProps) {
style={{ marginTop: 15 }} style={{ marginTop: 15 }}
> >
<View style={{ flex: 1 }} /> <View style={{ flex: 1 }} />
<Button <Button variant="primary" type="submit">
variant="primary"
onPress={() => {
if (!value) {
setErr('Invalid report entered');
return;
}
onApply(value);
}}
>
Apply Apply
</Button> </Button>
</Stack> </Stack>
</form> </Form>
{err !== '' ? ( {err !== '' ? (
<Stack direction="row" align="center" style={{ padding: 10 }}> <Stack direction="row" align="center" style={{ padding: 10 }}>
<Text style={{ color: theme.errorText }}>{err}</Text> <Text style={{ color: theme.errorText }}>{err}</Text>
......
import React, { type RefObject, useEffect } from 'react'; import React, { type RefObject, useEffect } from 'react';
import { Form } from 'react-aria-components';
import { type CustomReportEntity } from 'loot-core/types/models/reports'; import { type CustomReportEntity } from 'loot-core/types/models/reports';
...@@ -44,7 +45,15 @@ export function SaveReportName({ ...@@ -44,7 +45,15 @@ export function SaveReportName({
return ( return (
<> <>
{menuItem !== 'update-report' && ( {menuItem !== 'update-report' && (
<form> <Form
onSubmit={e => {
e.preventDefault();
onAddUpdate({
menuChoice: menuItem ?? undefined,
reportData: report ?? undefined,
});
}}
>
<Stack <Stack
direction="row" direction="row"
justify="flex-end" justify="flex-end"
...@@ -65,20 +74,11 @@ export function SaveReportName({ ...@@ -65,20 +74,11 @@ export function SaveReportName({
style={{ marginTop: 10 }} style={{ marginTop: 10 }}
/> />
</FormField> </FormField>
<Button <Button variant="primary" type="submit" style={{ marginTop: 30 }}>
variant="primary"
style={{ marginTop: 30 }}
onPress={() => {
onAddUpdate({
menuChoice: menuItem ?? undefined,
reportData: report ?? undefined,
});
}}
>
{menuItem === 'save-report' ? 'Add' : 'Update'} {menuItem === 'save-report' ? 'Add' : 'Update'}
</Button> </Button>
</Stack> </Stack>
</form> </Form>
)} )}
{err !== '' ? ( {err !== '' ? (
<Stack direction="row" align="center" style={{ padding: 10 }}> <Stack direction="row" align="center" style={{ padding: 10 }}>
......
---
category: Bugfix
authors: [joel-jeremy]
---
Fix save report forms submit handler so that it doesn't trigger a reload of an entire page on submit.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment