Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
chore: redirect to detail page after sku list create
Browse files Browse the repository at this point in the history
  • Loading branch information
pfferrari committed Mar 11, 2024
1 parent a28683f commit ec19e9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/app/src/hooks/useCreateSkuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
adaptFormValuesToSkuListCreate
} from '#components/SkuListForm/utils'
import { useCoreSdkProvider } from '@commercelayer/app-elements'
import type { SkuList } from '@commercelayer/sdk'
import { useCallback, useState } from 'react'

interface CreateSkuListHook {
isCreatingSkuList: boolean
createSkuListError?: any
createSkuList: (formValues: SkuListFormValues) => Promise<void>
createSkuList: (formValues: SkuListFormValues) => Promise<SkuList | undefined>
}

export function useCreateSkuList(): CreateSkuListHook {
Expand Down Expand Up @@ -39,6 +40,7 @@ export function useCreateSkuList(): CreateSkuListHook {
})
)
}
return createdSkuList
} catch (err) {
setCreateSkuListError(err)
} finally {
Expand Down
8 changes: 6 additions & 2 deletions packages/app/src/pages/SkuListNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ export function SkuListNew(): JSX.Element {
apiError={createSkuListError}
isSubmitting={isCreatingSkuList}
onSubmit={(formValues) => {
void createSkuList(formValues).then(() => {
setLocation(goBackUrl)
void createSkuList(formValues).then((createdSkuList) => {
if (createdSkuList != null) {
setLocation(
appRoutes.details.makePath({ skuListId: createdSkuList.id })
)
}
})
}}
/>
Expand Down

0 comments on commit ec19e9e

Please sign in to comment.