feat(cms): Add CMS table with delete and edit functionality
- Implement CMS table with row listing and pagination - Add delete functionality for CMS entries with confirmation modal - Introduce edit button to navigate to edit page for specific CMS entry - Update page type form to include new 'key' field for CMS entries - Modify CMS service and types to support new data structure - Enhance table presenter with additional actions and state management Resolves data management and user interaction improvements for CMS module
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { API_ENDPOINTS } from "@/lib/api";
|
||||
import { cmsService } from "@/lib/api/services/cms-service";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useMemo } from "react";
|
||||
import { toast } from "react-toastify";
|
||||
|
||||
export const useGetCmsList = () => {
|
||||
const queryKey = useMemo(() => [API_ENDPOINTS.CMS.BASE()], []);
|
||||
@@ -18,6 +20,8 @@ export const useGetCmsDetails = (id: string) => {
|
||||
});
|
||||
};
|
||||
export const useCreateCms = () => {
|
||||
const router = useRouter();
|
||||
const queryClient = useQueryClient();
|
||||
const mutationKey = useMemo(
|
||||
() => [API_ENDPOINTS.CMS.BASE(), "Create cms"],
|
||||
[],
|
||||
@@ -25,5 +29,30 @@ export const useCreateCms = () => {
|
||||
return useMutation({
|
||||
mutationKey,
|
||||
mutationFn: cmsService.createCms,
|
||||
onSuccess: ({ data }: { data: { message: string } }) => {
|
||||
toast.success(data.message);
|
||||
router.push("/marketing");
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [API_ENDPOINTS.CMS.BASE()],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
export const useDeleteCms = (successCallback?: () => void) => {
|
||||
const queryClient = useQueryClient();
|
||||
const mutationKey = useMemo(
|
||||
() => [API_ENDPOINTS.CMS.BASE(), "Delete CMS"],
|
||||
[],
|
||||
);
|
||||
return useMutation({
|
||||
mutationKey,
|
||||
mutationFn: cmsService.deleteCms,
|
||||
onSuccess: ({ data }: { data: { message: string } }) => {
|
||||
toast.success(data.message);
|
||||
successCallback?.();
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: [API_ENDPOINTS.CMS.BASE()],
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user