update types folder

This commit is contained in:
2025-02-12 12:27:53 +05:30
parent 4ab8daaaf8
commit 0bd8cc6434
3 changed files with 20 additions and 70 deletions

View File

@@ -3,20 +3,10 @@ import MainFrame from "../../../components/MainFrame";
import PrivacyPolicyAddModel from "./PrivacyPolicyAddModel";
import { useGetPrivacyPolicyQuery } from "../../../Redux/Service/privacy.policy.service";
// Define interfaces
interface PrivacyPolicyContent {
id: number;
content: string;
}
interface ApiResponse {
data: {data:PrivacyPolicyContent[]};
isLoading: boolean
}
const PrivacyPolicy = () => {
// Fetch data using RTK Query with type annotations
const { data, isLoading } = useGetPrivacyPolicyQuery<ApiResponse>();
const { data, isLoading } = useGetPrivacyPolicyQuery();
console.log(isLoading);

View File

@@ -1,68 +1,16 @@
import { createApi } from "@reduxjs/toolkit/query/react"; // Fix import
import { baseQueryWithReauth } from "./apiSlice";
import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithReauth } from "./apiSlice"; // Ensure this is correctly configured
import { PrivacyPolicyResponse } from "../../Types/privacyPolicyTypes";
export const privacyPolicy = createApi({
reducerPath: "privacyPolicy",
baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
baseQuery: baseQueryWithReauth, // Ensure this returns a valid `BaseQueryFn`
endpoints: (builder) => ({
// 🔹 GET: Fetch all privacy policies
getPrivacyPolicy: builder.query<PrivacyPolicy[], void>({
getPrivacyPolicy: builder.query<PrivacyPolicyResponse, void>({ // Fix types here
query: () => "/privacy-policy",
}),
// 🔹 GET: Fetch a single post by ID
// getPostById: builder.query<Post, number>({
// query: (id) => `/posts/${id}`,
// }),
// 🔹 POST: Create a new post
// createPost: builder.mutation<Post, Partial<Post>>({
// query: (newPost) => ({
// url: "/posts",
// method: "POST",
// body: newPost,
// }),
// }),
// 🔹 PUT: Update an existing post
// updatePost: builder.mutation<Post, { id: number; updatedData: Partial<Post> }>({
// query: ({ id, updatedData }) => ({
// url: `/posts/${id}`,
// method: "PUT",
// body: updatedData,
// }),
// }),
// 🔹 DELETE: Remove a post by ID
// deletePost: builder.mutation<{ success: boolean }, number>({
// query: (id) => ({
// url: `/posts/${id}`,
// method: "DELETE",
// }),
// }),
}),
});
// Export hooks for usage in components
export const {
useGetPrivacyPolicyQuery, // Export the correct hook
} = privacyPolicy;
// Define types at the top for better readability
export type Post = {
id: number;
title: string;
body: string;
};
export type PrivacyPolicy = {
id: number;
language_master_xid: number;
content: string;
is_active: boolean;
};
// Export hook
export const { useGetPrivacyPolicyQuery } = privacyPolicy;

View File

@@ -0,0 +1,12 @@
export type PrivacyPolicy<T> = {
success: boolean;
message: string;
data: T;
};
export interface PrivacyPolicyContent {
id: number;
content: string;
}
export type PrivacyPolicyResponse = PrivacyPolicy<PrivacyPolicyContent[]>; // Fix here