Commit 0b0da348 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: correctly return from onsubmit in success casae

parent 5eb7ded4
Pipeline #181568 canceled with stage
in 5 minutes and 13 seconds
......@@ -80,6 +80,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -97,7 +98,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -105,11 +106,18 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -82,6 +82,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -99,7 +100,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -107,12 +108,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ id },
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -80,6 +80,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -97,7 +98,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -105,11 +106,18 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -82,6 +82,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -99,7 +100,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -107,12 +108,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ id },
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -78,6 +78,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -95,7 +96,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -103,11 +104,18 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -80,6 +80,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -97,7 +98,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -105,12 +106,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ id },
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -78,6 +78,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -95,7 +96,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -103,11 +104,18 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -80,6 +80,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -97,7 +98,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
async function onSubmit({ draft, ...unsanitized }: ItemFormValues) {
if (auth.session?.accessToken == null) {
toast.error('Authentication required.')
return Promise.reject()
......@@ -105,12 +106,19 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
const values = sanitizeFormValues(unsanitized)
return create.mutateAsync([
await create.mutateAsync([
{ id },
{ draft },
values,
{ token: auth.session.accessToken },
])
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
function onValidate(values: Partial<ItemFormValues>) {
......
......@@ -124,6 +124,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -171,6 +172,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
/** This will only get called when the above didn't throw. */
onSuccess(createdWorkflow)
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
const [state, setState] = useState<{
......
......@@ -138,6 +138,7 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
} else if (data.status === 'draft') {
/** Stay on page and don't clear form when saving as draft. */
// router.push({ pathname: '/' })
window.scroll(0, 0)
} else {
router.push({ pathname: '/success' })
}
......@@ -209,6 +210,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
/** This will only get called when the above didn't throw. */
onSuccess(updatedWorkflow)
/**
* If `onSubmit` resolves to `undefined` it's a successful submit.
* If the promise resolves to something else the submit has failed.
* If the promise rejects it's a network error (or similar).
*/
return Promise.resolve()
}
const [state, setState] = useState<{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment