fix(folio-web): keep submit live for 400ms after saving

Defers the navigation back so the button is tappable while the label
reads Saved, widening the double-submit window the counting property
is there to catch.
This commit is contained in:
pj committed 2026-08-17 23:27:37 +05:30
1 parent bc0f286e29
commit 8c8e87761d
1 file changed
+21 -2
@@ -9,6 +9,8 @@ import { parseCents } from '../format'
import { back, navigate } from '../router'
import { BackButton, Header, Screen } from '../components/Screen'
const SAVED_NOTICE_MILLIS = 400
export function AddTransactionPage(props: {
accountId: string
onCreated: () => void
@@ -19,6 +21,7 @@ export function AddTransactionPage(props: {
const [note, setNote] = useState('')
const [err, setErr] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [saved, setSaved] = useState(false)
useEffect(() => {
let alive = true
@@ -30,6 +33,15 @@ export function AddTransactionPage(props: {
}
}, [props.accountId])
useEffect(() => {
if (!saved) return
const timer = window.setTimeout(
() => back(`/accounts/${props.accountId}`),
SAVED_NOTICE_MILLIS,
)
return () => window.clearTimeout(timer)
}, [saved, props.accountId])
async function onSubmit(e: FormEvent) {
e.preventDefault()
if (busy) return
@@ -51,7 +63,7 @@ export function AddTransactionPage(props: {
note,
})
props.onCreated()
back(`/accounts/${props.accountId}`)
setSaved(true)
} catch (e) {
setErr(e instanceof Error ? e.message : 'Could not save transaction')
} finally {
@@ -85,6 +97,13 @@ export function AddTransactionPage(props: {
}
const submitDisabled = busy || amount.trim() === ''
const submitLabel = busy
? 'Saving…'
: saved
? 'Saved'
: type === 'credit'
? 'Add credit'
: 'Add debit'
return (
<Screen
@@ -107,7 +126,7 @@ export function AddTransactionPage(props: {
form="add-txn-form"
disabled={submitDisabled}
>
{busy ? 'Saving…' : type === 'credit' ? 'Add credit' : 'Add debit'}
{submitLabel}
</button>
}
>