修改客户管理认领和管理员字段展示逻辑
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
useState,
|
||||
} from "react"
|
||||
import { toast } from "sonner"
|
||||
import type { useDataTable } from "@/components/data-table"
|
||||
import type { ApiResponse } from "@/lib/api"
|
||||
|
||||
export function useStatus() {
|
||||
@@ -12,31 +13,39 @@ export function useStatus() {
|
||||
}
|
||||
|
||||
export function useFetch<TArgs extends unknown[], TResult>(
|
||||
table: ReturnType<typeof useDataTable>,
|
||||
fetchData: (...args: TArgs) => Promise<ApiResponse<TResult>>,
|
||||
messages: {
|
||||
done?: string
|
||||
fail?: string
|
||||
},
|
||||
setStatus?: Dispatch<SetStateAction<"load" | "fail" | "done">>,
|
||||
) {
|
||||
return useCallback(
|
||||
async (...args: TArgs) => {
|
||||
try {
|
||||
setStatus?.("load")
|
||||
table.setStatus?.("load")
|
||||
const resp = await fetchData(...args)
|
||||
if (!resp.success) {
|
||||
throw new Error(resp.message)
|
||||
}
|
||||
|
||||
setStatus?.("done")
|
||||
table.setStatus?.("done")
|
||||
table.refresh(table.pagination.page, table.pagination.size)
|
||||
toast.success(messages.done || "获取数据成功")
|
||||
} catch (e) {
|
||||
setStatus?.("fail")
|
||||
table.setStatus?.("fail")
|
||||
toast.error(messages.fail || "获取数据失败", {
|
||||
description: (e as Error).message || "未知错误",
|
||||
})
|
||||
}
|
||||
},
|
||||
[fetchData, setStatus, messages],
|
||||
[
|
||||
fetchData,
|
||||
table.setStatus,
|
||||
table.pagination.page,
|
||||
table.pagination.size,
|
||||
table.refresh,
|
||||
messages,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user