This commit is contained in:
@@ -2,6 +2,7 @@ import {
|
||||
API_ENDPOINTS,
|
||||
companiesService,
|
||||
companyCategoriesService,
|
||||
type ICompanyLink,
|
||||
type TCompanyCategoryApiResponse,
|
||||
} from "@/lib/api";
|
||||
import {
|
||||
@@ -100,6 +101,26 @@ export const useUploadCompanyDocuments = (id: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useAddCompanyLinks = (id: string) => {
|
||||
const queryClient = useQueryClient();
|
||||
const mutationKey = useMemo(
|
||||
() => [API_ENDPOINTS.COMPANIES.LINKS(id), "add-links"],
|
||||
[id],
|
||||
);
|
||||
|
||||
return useMutation({
|
||||
mutationKey,
|
||||
mutationFn: (links: ICompanyLink[]) =>
|
||||
companiesService.addLinks({ id, links }),
|
||||
onSuccess: (response) => {
|
||||
toast.success(response.message ?? "Company links added successfully");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [API_ENDPOINTS.COMPANIES.READ_ALL, id, "details"],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteCompanyQuery = (successCallback?: () => void) => {
|
||||
const queryClient = useQueryClient();
|
||||
const mutationKey = useMemo(
|
||||
@@ -224,30 +245,33 @@ export const useDeleteCompanyCategoryQuery = (successCallback?: () => void) => {
|
||||
};
|
||||
export const useToggleCompanyCategoryPublished = () => {
|
||||
const queryClient = useQueryClient();
|
||||
const updateOptimisticCategories = useCallback((categoryId: string) => {
|
||||
queryClient.setQueriesData<TCompanyCategoryApiResponse>(
|
||||
{
|
||||
queryKey: [API_ENDPOINTS.COMPANIES.CATEGORIES.READ_ALL],
|
||||
exact: false,
|
||||
},
|
||||
(previousList) => {
|
||||
if (!previousList?.data?.categories) {
|
||||
return previousList;
|
||||
}
|
||||
return {
|
||||
...previousList,
|
||||
data: {
|
||||
...previousList.data,
|
||||
categories: previousList.data.categories.map((category) =>
|
||||
category.id === categoryId
|
||||
? { ...category, published: !category.published }
|
||||
: category,
|
||||
),
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
}, [queryClient]);
|
||||
const updateOptimisticCategories = useCallback(
|
||||
(categoryId: string) => {
|
||||
queryClient.setQueriesData<TCompanyCategoryApiResponse>(
|
||||
{
|
||||
queryKey: [API_ENDPOINTS.COMPANIES.CATEGORIES.READ_ALL],
|
||||
exact: false,
|
||||
},
|
||||
(previousList) => {
|
||||
if (!previousList?.data?.categories) {
|
||||
return previousList;
|
||||
}
|
||||
return {
|
||||
...previousList,
|
||||
data: {
|
||||
...previousList.data,
|
||||
categories: previousList.data.categories.map((category) =>
|
||||
category.id === categoryId
|
||||
? { ...category, published: !category.published }
|
||||
: category,
|
||||
),
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
},
|
||||
[queryClient],
|
||||
);
|
||||
const mutationKey = useMemo(
|
||||
() => [
|
||||
API_ENDPOINTS.COMPANIES.CATEGORIES.TOGGLE_PUBLISHED("published"),
|
||||
@@ -263,8 +287,7 @@ export const useToggleCompanyCategoryPublished = () => {
|
||||
data?: { message?: string };
|
||||
message?: string;
|
||||
};
|
||||
const toastMessage =
|
||||
responseBody.data?.message ?? responseBody.message;
|
||||
const toastMessage = responseBody.data?.message ?? responseBody.message;
|
||||
if (toastMessage) {
|
||||
toast.success(toastMessage);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user