2022-11-04 08:30:10 +00:00
|
|
|
import type { Policy, PolicyTemplate } from "@halo-dev/api-client";
|
2024-06-25 04:31:44 +00:00
|
|
|
import { coreApiClient } from "@halo-dev/api-client";
|
2023-02-23 09:08:12 +00:00
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
2024-06-26 10:42:50 +00:00
|
|
|
import type { Ref } from "vue";
|
2022-09-04 17:06:11 +00:00
|
|
|
|
|
|
|
interface useFetchAttachmentPolicyReturn {
|
2023-02-23 09:08:12 +00:00
|
|
|
policies: Ref<Policy[] | undefined>;
|
|
|
|
isLoading: Ref<boolean>;
|
2022-09-04 17:06:11 +00:00
|
|
|
handleFetchPolicies: () => void;
|
|
|
|
}
|
|
|
|
|
2022-11-04 08:30:10 +00:00
|
|
|
interface useFetchAttachmentPolicyTemplatesReturn {
|
2023-02-23 09:08:12 +00:00
|
|
|
policyTemplates: Ref<PolicyTemplate[] | undefined>;
|
|
|
|
isLoading: Ref<boolean>;
|
2022-11-04 08:30:10 +00:00
|
|
|
handleFetchPolicyTemplates: () => void;
|
|
|
|
}
|
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
export function useFetchAttachmentPolicy(): useFetchAttachmentPolicyReturn {
|
|
|
|
const { data, isLoading, refetch } = useQuery<Policy[]>({
|
|
|
|
queryKey: ["attachment-policies"],
|
|
|
|
queryFn: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await coreApiClient.storage.policy.listPolicy();
|
2023-02-23 09:08:12 +00:00
|
|
|
return data.items;
|
|
|
|
},
|
|
|
|
refetchInterval(data) {
|
2024-05-23 02:54:49 +00:00
|
|
|
const hasDeletingPolicy = data?.some(
|
2022-11-18 07:22:22 +00:00
|
|
|
(policy) => !!policy.metadata.deletionTimestamp
|
|
|
|
);
|
2024-05-23 02:54:49 +00:00
|
|
|
return hasDeletingPolicy ? 1000 : false;
|
2023-02-23 09:08:12 +00:00
|
|
|
},
|
2022-11-18 07:22:22 +00:00
|
|
|
});
|
|
|
|
|
2022-09-04 17:06:11 +00:00
|
|
|
return {
|
2023-02-23 09:08:12 +00:00
|
|
|
policies: data,
|
|
|
|
isLoading,
|
|
|
|
handleFetchPolicies: refetch,
|
2022-09-04 17:06:11 +00:00
|
|
|
};
|
|
|
|
}
|
2022-11-04 08:30:10 +00:00
|
|
|
|
2023-02-23 09:08:12 +00:00
|
|
|
export function useFetchAttachmentPolicyTemplate(): useFetchAttachmentPolicyTemplatesReturn {
|
|
|
|
const { data, isLoading, refetch } = useQuery<PolicyTemplate[]>({
|
|
|
|
queryKey: ["attachment-policy-templates"],
|
|
|
|
queryFn: async () => {
|
2022-11-04 08:30:10 +00:00
|
|
|
const { data } =
|
2024-06-25 04:31:44 +00:00
|
|
|
await coreApiClient.storage.policyTemplate.listPolicyTemplate();
|
2023-02-23 09:08:12 +00:00
|
|
|
return data.items;
|
|
|
|
},
|
2022-11-04 08:30:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2023-02-23 09:08:12 +00:00
|
|
|
policyTemplates: data,
|
|
|
|
isLoading,
|
|
|
|
handleFetchPolicyTemplates: refetch,
|
2022-11-04 08:30:10 +00:00
|
|
|
};
|
|
|
|
}
|