Fix localStorage cleared because error were swallowed

This commit is contained in:
ekzyis 2023-08-11 23:35:37 +02:00
parent 38fddcf283
commit 73aa0d2d44
9 changed files with 14 additions and 11 deletions

View File

@ -90,7 +90,7 @@ export function BountyForm ({
onSubmit={
handleSubmit ||
(async ({ boost, bounty, cost, ...values }) => {
await invoiceableUpsertBounty(cost, boost, bounty, values)
return invoiceableUpsertBounty(cost, boost, bounty, values)
})
}
storageKeyPrefix={item ? undefined : 'bounty'}

View File

@ -79,7 +79,7 @@ export function DiscussionForm ({
}}
schema={schema}
onSubmit={handleSubmit || (async ({ boost, cost, ...values }) => {
await invoiceableUpsertDiscussion(cost, boost, values)
return invoiceableUpsertDiscussion(cost, boost, values)
})}
storageKeyPrefix={item ? undefined : 'discussion'}
>

View File

@ -470,8 +470,8 @@ export function Form ({
initialTouched={validateImmediately && initial}
validateOnBlur={false}
onSubmit={async (values, ...args) =>
onSubmit && onSubmit(values, ...args).then(() => {
if (!storageKeyPrefix) return
onSubmit && onSubmit(values, ...args).then((options) => {
if (!storageKeyPrefix || options?.keepLocalStorage) return
Object.keys(values).forEach(v => {
window.localStorage.removeItem(storageKeyPrefix + '-' + v)
if (Array.isArray(values[v])) {

View File

@ -225,13 +225,16 @@ export const useInvoiceable = (fn, options = defaultOptions) => {
/>
)
})
return
return { keepLocalStorage: true }
}
throw error
}
}
setFnArgs(args)
return createInvoice({ variables: { amount } })
await createInvoice({ variables: { amount } })
// tell onSubmit handler that we want to keep local storage
// even though the submit handler was "successful"
return { keepLocalStorage: true }
}, [fn, setFnArgs, createInvoice])
return actionFn

View File

@ -76,7 +76,7 @@ export default function ItemAct ({ onClose, itemId, act, strike }) {
}}
schema={amountSchema}
onSubmit={async ({ amount }) => {
await invoiceableAct(amount)
return invoiceableAct(amount)
}}
>
<Input

View File

@ -102,7 +102,7 @@ export default function JobForm ({ item, sub }) {
schema={jobSchema}
storageKeyPrefix={storageKeyPrefix}
onSubmit={(async ({ maxBid, stop, start, ...values }) => {
await invoiceableUpsertJob(1000, maxBid, stop, start, values)
return invoiceableUpsertJob(1000, maxBid, stop, start, values)
})}
>
<div className='form-group'>

View File

@ -119,7 +119,7 @@ export function LinkForm ({ item, sub, editThreshold, children }) {
}}
schema={schema}
onSubmit={async ({ boost, title, cost, ...values }) => {
await invoiceableUpsertLink(cost, boost, title, values)
return invoiceableUpsertLink(cost, boost, title, values)
}}
storageKeyPrefix={item ? undefined : 'link'}
>

View File

@ -70,7 +70,7 @@ export function PollForm ({ item, sub, editThreshold, children }) {
}}
schema={schema}
onSubmit={async ({ boost, title, options, cost, ...values }) => {
await invoiceableUpsertPoll(cost, boost, title, options, values)
return invoiceableUpsertPoll(cost, boost, title, options, values)
}}
storageKeyPrefix={item ? undefined : 'poll'}
>

View File

@ -130,7 +130,7 @@ export default function Reply ({ item, onSuccess, replyOpen, children, placehold
}}
schema={commentSchema}
onSubmit={async ({ cost, ...values }, { resetForm }) => {
await invoiceableCreateComment(cost, values, parentId, resetForm)
return invoiceableCreateComment(cost, values, parentId, resetForm)
}}
storageKeyPrefix={'reply-' + parentId}
>