diff --git a/src/Redux/Service/apiSlice.tsx b/src/Redux/Service/apiSlice.tsx index cc8ae3a..46513e4 100644 --- a/src/Redux/Service/apiSlice.tsx +++ b/src/Redux/Service/apiSlice.tsx @@ -6,9 +6,17 @@ import { RootState } from "../Store"; const baseQuery = fetchBaseQuery({ baseUrl: `${import.meta.env.VITE_API_URL}`, prepareHeaders: (headers, { getState }) => { + const token = (getState() as RootState).auth.token; // Get token from Redux store + // Encode Basic Auth Credentials + const username = import.meta.env.VITE_USER_NAME||''; // Replace with actual username + const password = import.meta.env.VITE_PASSWORD||''; // Replace with actual password + const basicAuth = `${username} : ${password}`; // Encode to Base64 + if (token) { - headers.set("Authorization", `Bearer ${token}`); + headers.set("Authorization", `Basic ${basicAuth}`); + headers.set("access-token", `Bearer ${token}`); + } headers.set("Content-Type", "application/json"); return headers; @@ -16,7 +24,7 @@ const baseQuery = fetchBaseQuery({ }); // ✅ Handle 401 Errors (Auto Logout) -const baseQueryWithReauth: BaseQueryFn< +export const baseQueryWithReauth: BaseQueryFn< string | FetchArgs, unknown, FetchBaseQueryError @@ -30,7 +38,10 @@ const baseQueryWithReauth: BaseQueryFn< return result; }; -export const apiSlice = createApi({ + + + +export const dashboard = createApi({ reducerPath: "api", baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling endpoints: (builder) => ({ @@ -46,7 +57,7 @@ export const apiSlice = createApi({ }), }); -export const { useGetPostsQuery } = apiSlice; +export const { useGetPostsQuery } = dashboard; export type Post = { id: number; diff --git a/src/Redux/Service/deactivated.account.service.ts b/src/Redux/Service/deactivated.account.service.ts new file mode 100644 index 0000000..13b720a --- /dev/null +++ b/src/Redux/Service/deactivated.account.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const deactivatedAccounts = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = deactivatedAccounts; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/faqs.service.ts b/src/Redux/Service/faqs.service.ts new file mode 100644 index 0000000..78dd3f7 --- /dev/null +++ b/src/Redux/Service/faqs.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const faqs = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = faqs; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.aboutus.service.ts b/src/Redux/Service/manage.aboutus.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/manage.aboutus.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.contactus.service.ts b/src/Redux/Service/manage.contactus.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/manage.contactus.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.groups.service.ts b/src/Redux/Service/manage.groups.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/manage.groups.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.jobs.service.ts b/src/Redux/Service/manage.jobs.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/manage.jobs.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.posts.service.ts b/src/Redux/Service/manage.posts.service.ts new file mode 100644 index 0000000..a7b4a46 --- /dev/null +++ b/src/Redux/Service/manage.posts.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const managePosts = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = managePosts; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/manage.subadmin.service.ts b/src/Redux/Service/manage.subadmin.service.ts new file mode 100644 index 0000000..6b08cf8 --- /dev/null +++ b/src/Redux/Service/manage.subadmin.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const manageSubAdmin = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = manageSubAdmin; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/master.module.service.ts b/src/Redux/Service/master.module.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/master.module.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/myprofie.service.ts b/src/Redux/Service/myprofie.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/myprofie.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/privacy.policy.service.ts b/src/Redux/Service/privacy.policy.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/privacy.policy.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/privacy.service.ts b/src/Redux/Service/privacy.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/privacy.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/register.user.service.ts b/src/Redux/Service/register.user.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/register.user.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Service/terms.and.condition.service.ts b/src/Redux/Service/terms.and.condition.service.ts new file mode 100644 index 0000000..ccad2a2 --- /dev/null +++ b/src/Redux/Service/terms.and.condition.service.ts @@ -0,0 +1,26 @@ +import { createApi } from "@reduxjs/toolkit/query"; +import { baseQueryWithReauth } from "./apiSlice"; + +export const registerUser = createApi({ + reducerPath: "api", + baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling + endpoints: (builder) => ({ + + + + getPosts: builder.query({ query: () => "/posts" }), + + + + + + }), + }); + + export const { } = registerUser; + + export type Post = { + id: number; + title: string; + body: string; + }; \ No newline at end of file diff --git a/src/Redux/Store.tsx b/src/Redux/Store.tsx index f2d8548..5d4218b 100644 --- a/src/Redux/Store.tsx +++ b/src/Redux/Store.tsx @@ -1,14 +1,43 @@ import { configureStore } from "@reduxjs/toolkit"; -import { apiSlice } from "./Service/apiSlice"; -import authReducer from "./Service/authSlice" +import { dashboard } from "./Service/apiSlice"; +import authReducer from "./Service/authSlice"; +import { registerUser } from "./Service/register.user.service"; +import { deactivatedAccounts } from "./Service/deactivated.account.service"; +import { faqs } from "./Service/faqs.service"; +import { managePosts } from "./Service/manage.posts.service"; +import { manageSubAdmin } from "./Service/manage.subadmin.service"; export const store = configureStore({ reducer: { - [apiSlice.reducerPath]: apiSlice.reducer, + [dashboard.reducerPath]: dashboard.reducer, + [registerUser.reducerPath]: registerUser.reducer, + [deactivatedAccounts.reducerPath]: deactivatedAccounts.reducer, + [faqs.reducerPath]: faqs.reducer, + [managePosts.reducerPath]: managePosts.reducer, + [manageSubAdmin.reducerPath]: manageSubAdmin.reducer, + + + + + + + [registerUser.reducerPath]: registerUser.reducer, + [registerUser.reducerPath]: registerUser.reducer, + [registerUser.reducerPath]: registerUser.reducer, + [registerUser.reducerPath]: registerUser.reducer, + [registerUser.reducerPath]: registerUser.reducer, + [registerUser.reducerPath]: registerUser.reducer, auth: authReducer, }, middleware: (getDefaultMiddleware) => - getDefaultMiddleware().concat(apiSlice.middleware), + getDefaultMiddleware().concat( + dashboard.middleware, + registerUser.middleware, + deactivatedAccounts.middleware, + managePosts.middleware, + faqs.middleware, + manageSubAdmin.middleware, + ), }); export type RootState = ReturnType;