CI / Static checks (push) Has been cancelled
CI / Production build (push) Has been cancelled
CI / API integration (push) Has been cancelled
CI / Taro builds (acheng-campus-food) (push) Has been cancelled
CI / Taro builds (atelier-solopreneur) (push) Has been cancelled
CI / Taro builds (linjing-editorial) (push) Has been cancelled
CI / Browser regression (push) Has been cancelled
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
import { App } from "antd";
|
|
import type { TrustContent, TrustContentInput } from "@personal-brand/api-client";
|
|
import { createApiClient } from "../../../lib/api.js";
|
|
|
|
export function useTrustContentMutations({
|
|
editing,
|
|
closeEditor,
|
|
}: {
|
|
editing: TrustContent | null;
|
|
closeEditor: () => void;
|
|
}) {
|
|
const { message } = App.useApp();
|
|
const client = createApiClient();
|
|
const queryClient = useQueryClient();
|
|
|
|
const save = useMutation({
|
|
mutationFn: (values: TrustContentInput) =>
|
|
editing
|
|
? client.updateAdminTrustContent(editing.id, values)
|
|
: client.createAdminTrustContent(values),
|
|
onSuccess: () => {
|
|
message.success("品牌内容已保存为草稿,发布后小程序才会更新");
|
|
closeEditor();
|
|
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
|
},
|
|
});
|
|
|
|
const remove = useMutation({
|
|
mutationFn: (id: string) => client.deleteAdminTrustContent(id),
|
|
onSuccess: () => {
|
|
message.success("品牌内容已删除");
|
|
void queryClient.invalidateQueries({ queryKey: ["trust-content"] });
|
|
},
|
|
});
|
|
|
|
return { save, remove };
|
|
}
|