Fix localStorage cleared because error were swallowed
This commit is contained in:
parent
38fddcf283
commit
73aa0d2d44
@ -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'}
|
||||
|
@ -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'}
|
||||
>
|
||||
|
@ -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])) {
|
||||
|
@ -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
|
||||
|
@ -76,7 +76,7 @@ export default function ItemAct ({ onClose, itemId, act, strike }) {
|
||||
}}
|
||||
schema={amountSchema}
|
||||
onSubmit={async ({ amount }) => {
|
||||
await invoiceableAct(amount)
|
||||
return invoiceableAct(amount)
|
||||
}}
|
||||
>
|
||||
<Input
|
||||
|
@ -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'>
|
||||
|
@ -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'}
|
||||
>
|
||||
|
@ -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'}
|
||||
>
|
||||
|
@ -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}
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user