feat: добавить рабочий dashboard admin
- добавлен Mantine theme provider и AppShell layout\n- сгенерирован Backend API клиент и добавлены infra/business хуки\n- добавлены таблица assets, detail/presets panels и create asset modal
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { useState } from "react"
|
||||
import { useSWRConfig } from "swr"
|
||||
import { backendApi, getAssetsListKey } from "infra/backend-api"
|
||||
|
||||
import { ASSETS_DASHBOARD_LIST_PARAMS } from "../config/assets.config"
|
||||
import type { CreateAssetAction, CreateAssetInput } from "../types/assets-api.type"
|
||||
|
||||
const toError = (error: unknown) => (error instanceof Error ? error : new Error("Неизвестная ошибка"))
|
||||
|
||||
/**
|
||||
* Сценарий создания asset с обновлением списка.
|
||||
*/
|
||||
export const useCreateAsset = (): CreateAssetAction => {
|
||||
const { mutate } = useSWRConfig()
|
||||
const [error, setError] = useState<Error | null>(null)
|
||||
const [isCreating, setIsCreating] = useState(false)
|
||||
|
||||
const createAsset = async (input: CreateAssetInput) => {
|
||||
setError(null)
|
||||
setIsCreating(true)
|
||||
|
||||
try {
|
||||
const createdAsset = await backendApi.assets.createAsset(input)
|
||||
await mutate(getAssetsListKey(ASSETS_DASHBOARD_LIST_PARAMS))
|
||||
|
||||
return createdAsset
|
||||
} catch (caughtError) {
|
||||
const nextError = toError(caughtError)
|
||||
setError(nextError)
|
||||
throw nextError
|
||||
} finally {
|
||||
setIsCreating(false)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
createAsset,
|
||||
error,
|
||||
isCreating,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user