add: webhook
This commit is contained in:
@@ -21,23 +21,16 @@ export const usePaths = (parent_id) => {
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const usePath = (id) => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
const cachedData = queryClient.getQueryData(["path", id]);
|
||||
|
||||
|
||||
return useQuery(
|
||||
["path", id],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/path/${id}`),
|
||||
{
|
||||
enabled: !!id,
|
||||
onSuccess: (data) => {
|
||||
console.log(`path ${id} - ${cachedData}` );
|
||||
}
|
||||
enabled: !!id
|
||||
}
|
||||
);
|
||||
};
|
||||
@@ -53,7 +46,6 @@ export const useCreatePath = () => {
|
||||
}),
|
||||
{
|
||||
onSuccess: (res, variables) => {
|
||||
console.log(JSON.stringify(variables));
|
||||
queryClient.invalidateQueries(["paths", variables.parent_id]);
|
||||
queryClient.invalidateQueries("tree");
|
||||
},
|
||||
|
||||
170
src/utils/webhook-queries.js
Normal file
170
src/utils/webhook-queries.js
Normal file
@@ -0,0 +1,170 @@
|
||||
import {fetch_ } from "./request-utils"
|
||||
import {useConfig} from "../ConfigProvider";
|
||||
import {useMutation, useQuery, useQueryClient} from "react-query";
|
||||
|
||||
export const useWebhooks = () =>{
|
||||
const queryClient = useQueryClient();
|
||||
const config = useConfig();
|
||||
return useQuery(
|
||||
"webhooks",
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/`),
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if(data)
|
||||
queryClient.setQueryData("webhooks", data);
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useCreateWebhook = () =>{
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation(
|
||||
(data) => fetch_(`${config.BACKEND_HOST}/api/webhook/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"hook_url": data
|
||||
}),
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries("webhooks");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useUpdateWebhook = () =>{
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
({id, data}) => fetch_(`${config.BACKEND_HOST}/api/webhook/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data)
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries("webhooks");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useDeleteWebhook = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(id) => fetch_(`${config.BACKEND_HOST}/api/webhook/${id}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries("webhooks");
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const useWebhookSettings = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
"webhook_setting",
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/`),
|
||||
{
|
||||
onSuccess: (data) => {
|
||||
if(data){
|
||||
for(const setting of data){
|
||||
queryClient.setQueryData(["webhook_setting", setting.id], setting);
|
||||
queryClient.setQueryData(["webhook_setting_path_id", setting.path_id], setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useWebhookSetting = (setting_id) => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
["webhook_setting", setting_id],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/${setting_id}`),
|
||||
{
|
||||
enabled: !!setting_id,
|
||||
onSuccess: (res) => {
|
||||
if(res)
|
||||
queryClient.setQueryData(["webhook_setting_path_id", res.path_id], res);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useWebhookSettingByPathId = (pathId) => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useQuery(
|
||||
["webhook_setting_path_id", pathId],
|
||||
() => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/path/${pathId}`),
|
||||
{
|
||||
enabled: !!pathId,
|
||||
onSuccess: (res) => {
|
||||
if(res)
|
||||
queryClient.setQueryData(["webhook_setting", res.id], res);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useCreateWebhookSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(data) => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(data)
|
||||
}),{
|
||||
onSuccess: (res) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", res.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", res.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const useUpdateWebhookSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
({id, data}) => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/${id}`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(data)
|
||||
}),{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", variables.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", variables.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export const useDeleteWebhookSetting = () => {
|
||||
const config = useConfig();
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation(
|
||||
(id) => fetch_(`${config.BACKEND_HOST}/api/webhook/setting/${id}`, {
|
||||
method: "DELETE",
|
||||
}),
|
||||
{
|
||||
onSuccess: (res, variables) => {
|
||||
queryClient.invalidateQueries(["webhook_setting", variables.id]);
|
||||
queryClient.invalidateQueries(["webhook_setting_path_id", variables.path_id]);
|
||||
queryClient.invalidateQueries("webhook_setting");
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user