TASKS-1823 WebManager module
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { queryClient } from '#app/providers/QueryProvider';
|
||||
import { axiosClient } from '#infrastructure/axios';
|
||||
import { MODULE_API_ENDPOINT } from '../config/meta';
|
||||
import { Entity } from '../entities/Entity';
|
||||
import { detailedKeyBuilder } from './keys';
|
||||
|
||||
export const invalidateDetailed = async (id?: number) => {
|
||||
if (id === undefined) {
|
||||
await queryClient.invalidateQueries(detailedKeyBuilder.invalidateAll());
|
||||
} else {
|
||||
await queryClient.invalidateQueries(detailedKeyBuilder.invalidate({ id: String(id) }));
|
||||
}
|
||||
};
|
||||
|
||||
export interface DetailedPayload {
|
||||
id: string;
|
||||
}
|
||||
export const useGetDetailed = (payload?: DetailedPayload) => {
|
||||
return useQuery({
|
||||
queryKey: detailedKeyBuilder.store(payload as DetailedPayload),
|
||||
queryFn: async () => {
|
||||
return axiosClient
|
||||
.get<Entity>(`${MODULE_API_ENDPOINT}/${payload?.id}`)
|
||||
.then((data) => data.data);
|
||||
},
|
||||
enabled: Boolean(payload?.id),
|
||||
throwOnError(_error) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user