sync
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useState } from "react"
|
||||
import { useSWRConfig } from "swr"
|
||||
import { backendApi, getAssetsListKey } from "infra/backend-api"
|
||||
import { backendApi, getAssetsListKey, getProjectAssetsKey } from "infra/backend-api"
|
||||
|
||||
import { ASSETS_DASHBOARD_LIST_PARAMS } from "../config/assets.config"
|
||||
import { toError } from "../lib/to-error"
|
||||
@@ -19,8 +19,15 @@ export const useCreateAsset = (): CreateAssetAction => {
|
||||
setIsCreating(true)
|
||||
|
||||
try {
|
||||
const createdAsset = await backendApi.assets.createAsset(input)
|
||||
await mutate(getAssetsListKey(ASSETS_DASHBOARD_LIST_PARAMS))
|
||||
const { projectSlug, ...request } = input
|
||||
const createdAsset = projectSlug
|
||||
? await backendApi.projects.createProjectAsset({ projectSlug }, request)
|
||||
: await backendApi.assets.createAsset(request)
|
||||
|
||||
await Promise.all([
|
||||
mutate(getAssetsListKey(ASSETS_DASHBOARD_LIST_PARAMS)),
|
||||
projectSlug ? mutate(getProjectAssetsKey(projectSlug, ASSETS_DASHBOARD_LIST_PARAMS)) : Promise.resolve(),
|
||||
])
|
||||
|
||||
return createdAsset
|
||||
} catch (caughtError) {
|
||||
|
||||
Reference in New Issue
Block a user