feat(contact-us): Add delete functionality to contact us table

- 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
This commit is contained in:
AmirReza Jamali
2025-11-23 13:33:07 +03:30
parent a8d95d5f92
commit 2389ad1bbf
6 changed files with 107 additions and 9 deletions
+22 -2
View File
@@ -1,13 +1,33 @@
import { API_ENDPOINTS } from "@/lib/api";
import { contactUsService } from "@/lib/api/services/contact-us-service";
import { useQuery } from "@tanstack/react-query";
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.READ_ALL], []);
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()],
});
},
});
};