Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SSHOC
sshoc-marketplace-frontend
Commits
0b0da348
Commit
0b0da348
authored
Mar 17, 2021
by
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
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/components/item/DatasetCreateForm/DatasetCreateForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/DatasetEditForm/DatasetEditForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/PublicationCreateForm/PublicationCreateForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/PublicationEditForm/PublicationEditForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/ToolCreateForm/ToolCreateForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/ToolEditForm/ToolEditForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/TrainingMaterialEditForm/TrainingMaterialEditForm.tsx
View file @
0b0da348
...
...
@@ -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
>
)
{
...
...
src/components/item/WorkflowCreateForm/WorkflowCreateForm.tsx
View file @
0b0da348
...
...
@@ -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
<
{
...
...
src/components/item/WorkflowEditForm/WorkflowEditForm.tsx
View file @
0b0da348
...
...
@@ -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
<
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment