2389ad1bbf
- Add delete button with trash icon to contact us table rows - Implement confirmation modal for delete action - Create useDeleteContactUs mutation hook with success callback - Add deleteContactUs method to contact-us service - Update API endpoints to support BASE() function for dynamic ID routing - Add state management for modal open/close and current contact selection - Integrate toast notifications for delete success feedback - Add tooltip component to delete button for better UX - Update query key to use BASE() endpoint for consistency
34 lines
1015 B
TypeScript
34 lines
1015 B
TypeScript
import { API_ENDPOINTS } from "@/lib/api";
|
|
import { contactUsService } from "@/lib/api/services/contact-us-service";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
import { useMemo } from "react";
|
|
import { toast } from "react-toastify";
|
|
|
|
export const useReadAllContactUs = () => {
|
|
const queryKey = useMemo(() => [API_ENDPOINTS.CONTACT_US.BASE()], []);
|
|
|
|
return useQuery({
|
|
queryKey,
|
|
queryFn: () => contactUsService.getAllContactUs(),
|
|
});
|
|
};
|
|
export const useDeleteContactUs = (successCallback?: () => void) => {
|
|
const queryClient = useQueryClient();
|
|
const mutationKey = useMemo(
|
|
() => [API_ENDPOINTS.CONTACT_US.BASE(), "DELETE CONTACT US"],
|
|
[],
|
|
);
|
|
return useMutation({
|
|
mutationKey,
|
|
mutationFn: contactUsService.deleteContactUs,
|
|
onSuccess: (response) => {
|
|
toast.success(response.data.message);
|
|
|
|
successCallback?.();
|
|
queryClient.invalidateQueries({
|
|
queryKey: [API_ENDPOINTS.CONTACT_US.BASE()],
|
|
});
|
|
},
|
|
});
|
|
};
|