update
This commit is contained in:
13
src/App.jsx
13
src/App.jsx
@@ -1,13 +1,10 @@
|
||||
import './App.css'
|
||||
|
||||
function App() {
|
||||
|
||||
import { Box } from '@chakra-ui/react'
|
||||
import React from 'react'
|
||||
|
||||
const App = () => {
|
||||
return (
|
||||
<Box>
|
||||
|
||||
</Box>
|
||||
<Box>App</Box>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
||||
export default App
|
||||
6
src/Contexts/GlobalStateContext.jsx
Normal file
6
src/Contexts/GlobalStateContext.jsx
Normal file
@@ -0,0 +1,6 @@
|
||||
// GlobalStateContext.js
|
||||
import { createContext } from 'react';
|
||||
|
||||
const GlobalStateContext = createContext();
|
||||
|
||||
export default GlobalStateContext;
|
||||
20
src/Contexts/GlobalStateProvider.jsx
Normal file
20
src/Contexts/GlobalStateProvider.jsx
Normal file
@@ -0,0 +1,20 @@
|
||||
// GlobalStateContext.js
|
||||
import React, { useState } from "react";
|
||||
import GlobalStateContext from "./GlobalStateContext";
|
||||
|
||||
|
||||
const GlobalStateProvider = ({ children }) => {
|
||||
const [isAuthenticate, setIsAuthenticate] = useState(false);
|
||||
|
||||
return (
|
||||
<GlobalStateContext.Provider
|
||||
value={{
|
||||
isAuthenticate,
|
||||
setIsAuthenticate,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</GlobalStateContext.Provider>
|
||||
);
|
||||
};
|
||||
export default GlobalStateProvider;
|
||||
72
src/Services/api.service.js
Normal file
72
src/Services/api.service.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// io.service.js
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import { baseQuery } from "./token.serivce";
|
||||
|
||||
export const ioService = createApi({
|
||||
reducerPath: "ioService",
|
||||
baseQuery: baseQuery,
|
||||
tagTypes: [
|
||||
"prePopulate",
|
||||
"getIO",
|
||||
"getKeyMerits",
|
||||
"getArtifactsVideo",
|
||||
"getInvestmentDocuments",
|
||||
"getIOById",
|
||||
"getSponser",
|
||||
"getInvestmentType",
|
||||
"getInvestmentTypeID"
|
||||
],
|
||||
endpoints: (builder) => ({
|
||||
|
||||
// =====[get prepopulate data]
|
||||
|
||||
getIOprepopulateData: builder.query({
|
||||
query: () => `/io/admin/pre-populate`,
|
||||
providesTags: ["prePopulate"],
|
||||
}),
|
||||
|
||||
|
||||
getIOById: builder.query({
|
||||
query: (id) => ({ url: `/io/admin/${id}` }),
|
||||
providesTags: ["getIOById"],
|
||||
}),
|
||||
|
||||
// =====[create]
|
||||
createIO: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/io/admin`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
invalidatesTags: ["getIO"],
|
||||
}),
|
||||
|
||||
updateIO: builder.mutation({
|
||||
query: ({ data, id }) => ({
|
||||
url: `/io/admin/${id}`,
|
||||
method: "PATCH",
|
||||
body: data,
|
||||
}),
|
||||
invalidatesTags: ["getIOById", "getIO", "prePopulate"],
|
||||
}),
|
||||
|
||||
|
||||
deleteKeyMerits: builder.mutation({
|
||||
query: (id) => ({
|
||||
url: `/io/admin/key-merits/hard-delete/${id}`,
|
||||
method: "DELETE",
|
||||
}),
|
||||
invalidatesTags: ["getIOById"],
|
||||
}),
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
// Export hooks for usage in functional components
|
||||
export const {
|
||||
useGetIOprepopulateDataQuery,
|
||||
useGetIOByIdQuery,
|
||||
useCreateIOMutation,
|
||||
useUpdateIOMutation,
|
||||
useDeleteKeyMeritsMutation,
|
||||
} = ioService;
|
||||
224
src/Services/onboard.service.js
Normal file
224
src/Services/onboard.service.js
Normal file
@@ -0,0 +1,224 @@
|
||||
// io.service.js
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import { baseQuery } from "./token.serivce";
|
||||
|
||||
export const onBoard = createApi({
|
||||
reducerPath: "onBoard",
|
||||
baseQuery: baseQuery,
|
||||
tagTypes: [
|
||||
"interest",
|
||||
"fetchComunities"
|
||||
],
|
||||
endpoints: (builder) => ({
|
||||
|
||||
|
||||
// =====[send otp]
|
||||
sendOtp: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/send_otp`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[verifiy otp]
|
||||
verifyOtp: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/verify_otp`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[add profile]
|
||||
addProfile: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/add_profile`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[get interest]
|
||||
getInterest: builder.query({
|
||||
query: () => `/fetch-interests`,
|
||||
providesTags: ["interest"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
// =====[selected Interest]
|
||||
selectedInterest: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/select-interests`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[forgot password]
|
||||
forgotPassword: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/forgot-password`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
|
||||
// =====[forgot password]
|
||||
forgotPasswordVerifyOtp: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/forgot-password/verify-otp`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[Reset password]
|
||||
resetPassword: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/reset-password`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
|
||||
// =====[fetch Comunities]
|
||||
fetchComunities: builder.query({
|
||||
query: () => `/fetch-communities`,
|
||||
providesTags: ["fetchComunities"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
|
||||
// =====[select Communnity]
|
||||
selectCommunnity: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/select-communities`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
// =====[ /tell-us-about-your-business ]
|
||||
tellUsAboutYourBussiness: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/tell-us-about-your-business`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[fetch Groups]
|
||||
fetchGroups: builder.query({
|
||||
query: () => `/fetch-groups`,
|
||||
providesTags: ["fetchGroups"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
// =====[select Groups]
|
||||
selectGroups: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/select-groups`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[ bussines-profile stepper form ]
|
||||
updateBussinessStepperForm: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/update-business-profile-step-1`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
searchGroups: builder.query({
|
||||
query: (searchData) => `search-group?search_data=${searchData}`,
|
||||
}),
|
||||
|
||||
|
||||
searchCommunity: builder.query({
|
||||
query: (searchData) => `search-community?search_data=${searchData}`,
|
||||
}),
|
||||
|
||||
|
||||
|
||||
// =====[Google Login]
|
||||
googleLogin: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/sign-in-with-google-login`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[Update user Account type]
|
||||
updateUserAccountType: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/update-user-account-type`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
// Export hooks for usage in functional components
|
||||
export const {
|
||||
|
||||
|
||||
|
||||
|
||||
useSendOtpMutation,
|
||||
useVerifyOtpMutation,
|
||||
useAddProfileMutation,
|
||||
useGetInterestQuery,
|
||||
useSelectedInterestMutation,
|
||||
useForgotPasswordMutation,
|
||||
useForgotPasswordVerifyOtpMutation,
|
||||
useResetPasswordMutation,
|
||||
useFetchComunitiesQuery,
|
||||
useSelectCommunnityMutation,
|
||||
useTellUsAboutYourBussinessMutation,
|
||||
useFetchGroupsQuery,
|
||||
useSelectGroupsMutation,
|
||||
useUpdateBussinessStepperFormMutation,
|
||||
useSearchGroupsQuery,
|
||||
useSearchCommunityQuery,
|
||||
useGoogleLoginMutation,
|
||||
useUpdateUserAccountTypeMutation
|
||||
|
||||
|
||||
|
||||
|
||||
} = onBoard;
|
||||
50
src/Services/profile.service.js
Normal file
50
src/Services/profile.service.js
Normal file
@@ -0,0 +1,50 @@
|
||||
// io.service.js
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import { baseQuery } from "./token.serivce";
|
||||
|
||||
export const profile = createApi({
|
||||
reducerPath: "profile",
|
||||
baseQuery: baseQuery,
|
||||
tagTypes: [
|
||||
"getProfile"
|
||||
],
|
||||
endpoints: (builder) => ({
|
||||
|
||||
|
||||
// =====[send otp]
|
||||
sendOtp: builder.mutation({
|
||||
query: (data) => ({
|
||||
url: `/send_otp`,
|
||||
method: "POST",
|
||||
body: data,
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
// =====[get interest]
|
||||
getProfile: builder.query({
|
||||
query: () => `/fetch-profile`,
|
||||
providesTags: ["getProfile"],
|
||||
}),
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}),
|
||||
});
|
||||
|
||||
// Export hooks for usage in functional components
|
||||
export const {
|
||||
|
||||
useSendOtpMutation,
|
||||
useGetProfileQuery,
|
||||
|
||||
} = profile;
|
||||
140
src/Services/token.serivce.js
Normal file
140
src/Services/token.serivce.js
Normal file
@@ -0,0 +1,140 @@
|
||||
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
// Define a base query function with token refresh logic
|
||||
|
||||
console.log(import.meta.env.VITE_BASE_URL);
|
||||
export const baseQuery = async (args, api, extraOptions) => {
|
||||
let result = await fetchBaseQuery({
|
||||
baseUrl: import.meta.env.VITE_BASE_URL,
|
||||
prepareHeaders: (headers) => {
|
||||
const token = localStorage.getItem("accessToken");
|
||||
const username = import.meta.env.VITE_USERNAME || 'defaultUsername';
|
||||
const password = import.meta.env.VITE_PASSWORD || 'defaultPassword';
|
||||
|
||||
// Encode credentials to Base64
|
||||
const basicAuth = btoa(`${username}:${password}`);
|
||||
|
||||
// Set the Authorization header
|
||||
headers.set('Authorization', `Basic ${basicAuth}`);
|
||||
|
||||
// Set the token if available
|
||||
if (token) {
|
||||
headers.set("access-token", token);
|
||||
}
|
||||
return headers;
|
||||
},
|
||||
})(args, api, extraOptions);
|
||||
|
||||
if (result.error && result.error.status === 401) {
|
||||
// Handle token refresh
|
||||
// const refreshToken = localStorage.getItem("refreshToken");
|
||||
// if (refreshToken) {
|
||||
// try {
|
||||
// const refreshResult = await fetchBaseQuery({
|
||||
// baseUrl: import.meta.env.VITE_BASE_URL,
|
||||
// })(
|
||||
// {
|
||||
// url: "/auth/user/regenerate-token",
|
||||
// method: "POST",
|
||||
// body: { refreshToken },
|
||||
// },
|
||||
// api,
|
||||
// extraOptions
|
||||
// );
|
||||
|
||||
// if (refreshResult.data) {
|
||||
// // Save new tokens
|
||||
// localStorage.setItem("accessToken", refreshResult.data.access.token);
|
||||
// localStorage.setItem("refreshToken", refreshResult.data.refresh.token);
|
||||
// localStorage.setItem("refreshTokenExp", refreshResult.data.refresh.expires);
|
||||
|
||||
// // Retry the original request with the new token
|
||||
// result = await fetchBaseQuery({
|
||||
// baseUrl: import.meta.env.VITE_BASE_URL,
|
||||
// prepareHeaders: (headers) => {
|
||||
// const newToken = localStorage.getItem("accessToken");
|
||||
|
||||
// // Set the Authorization header again
|
||||
// headers.set('Authorization', `Basic ${basicAuth}`);
|
||||
|
||||
// // Set the new token
|
||||
// if (newToken) {
|
||||
// headers.set("x-auth-token", newToken);
|
||||
// }
|
||||
// return headers;
|
||||
// },
|
||||
// })(args, api, extraOptions);
|
||||
// }
|
||||
// } catch (err) {
|
||||
// console.error("Failed to refresh token:", err);
|
||||
// // Handle refresh failure (e.g., redirect to login)
|
||||
// }
|
||||
// }
|
||||
const [ logout ] = useLogoutMutation()
|
||||
const res = await logout()
|
||||
console.log(res);
|
||||
// Remove token and authenticated status from storage and cookies
|
||||
localStorage.removeItem("accessToken");
|
||||
localStorage.removeItem("refreshToken");
|
||||
Cookies.remove("isAuthenticated", { path: '/login' });
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Create an RTK Query API slice
|
||||
export const apiSlice = createApi({
|
||||
reducerPath: "api",
|
||||
baseQuery: baseQuery,
|
||||
endpoints: (builder) => ({
|
||||
|
||||
login: builder.mutation({
|
||||
query: (credentials) => ({
|
||||
url: "/login",
|
||||
method: "POST",
|
||||
body: credentials,
|
||||
}),
|
||||
async onQueryStarted(arg, { dispatch, queryFulfilled }) {
|
||||
try {
|
||||
const { data } = await queryFulfilled;
|
||||
console.log(data?.data['access-token']);
|
||||
// Store tokens in local storage
|
||||
localStorage.setItem("accessToken", data?.data['access-token']);
|
||||
localStorage.setItem("refreshToken", data?.data?.refresh?.token);
|
||||
localStorage.setItem("accessTokenExp", data?.data?.access?.expires);
|
||||
} catch (error) {
|
||||
console.error("Login failed:", error);
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
logout: builder.mutation({
|
||||
query: (credentials) => ({
|
||||
url: "/logout",
|
||||
method: "POST",
|
||||
}),
|
||||
}),
|
||||
|
||||
|
||||
refreshToken: builder.mutation({
|
||||
query: (refreshToken) => ({
|
||||
url: "/auth/user/regenerate-token",
|
||||
method: "POST",
|
||||
body: { refreshToken },
|
||||
}),
|
||||
}),
|
||||
// Add more endpoints as needed
|
||||
}),
|
||||
});
|
||||
|
||||
export const { useLoginMutation, useRefreshTokenMutation, useLogoutMutation } = apiSlice;
|
||||
|
||||
export default apiSlice;
|
||||
66
src/Store/Store.js
Normal file
66
src/Store/Store.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import { setupListeners } from "@reduxjs/toolkit/query";
|
||||
// import { sponserMaster } from "../Services/sponser.service";
|
||||
// import { investmentType } from "../Services/investment.type.service";
|
||||
// import { exchangeRate } from "../Services/exchange.rate.service";
|
||||
// import { ioService } from "../Services/io.service";
|
||||
// import { investorDetails } from "../Services/investor.details.service";
|
||||
// import { investorTransaction } from "../Services/investor.transaction.service";
|
||||
// import { api } from "../Services/api.service";
|
||||
// import { keyMerits } from "../Services/Key.merits.service";
|
||||
// import { bankDetails } from "../Services/bank.details.service";
|
||||
// import { contact } from "../Services/contact.service";
|
||||
// import { depositRequest } from "../Services/deposit.request.service";
|
||||
import { apiSlice, baseQuery } from "../Services/token.serivce";
|
||||
import { onBoard } from "../Services/onboard.service";
|
||||
import { profile } from "../Services/profile.service";
|
||||
// import { drawalRequest } from "../Services/drawal.request.service";
|
||||
// import { deleteRequest } from "../Services/delete.request.service";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
[apiSlice.reducerPath]: apiSlice.reducer,
|
||||
[onBoard.reducerPath]: onBoard.reducer,
|
||||
[profile.reducerPath]: profile.reducer,
|
||||
// [sponserMaster.reducerPath]: sponserMaster.reducer,
|
||||
// [investmentType.reducerPath]: investmentType.reducer,
|
||||
// [exchangeRate.reducerPath]: exchangeRate.reducer,
|
||||
// [ioService.reducerPath]: ioService.reducer,
|
||||
// [investorDetails.reducerPath]: investorDetails.reducer,
|
||||
// [investorTransaction.reducerPath]: investorTransaction.reducer,
|
||||
// [bankDetails.reducerPath]: bankDetails.reducer,
|
||||
// [contact.reducerPath]: contact.reducer,
|
||||
// [depositRequest.reducerPath]: depositRequest.reducer,
|
||||
// [drawalRequest.reducerPath]: drawalRequest.reducer,
|
||||
// [deleteRequest.reducerPath]: deleteRequest.reducer,
|
||||
// Add other reducers as needed
|
||||
},
|
||||
middleware: (getDefaultMiddleware) =>
|
||||
getDefaultMiddleware({
|
||||
thunk: {
|
||||
extraArgument: baseQuery, // Pass Axios instance as extra argument
|
||||
},
|
||||
}).concat(
|
||||
onBoard.middleware,
|
||||
apiSlice.middleware,
|
||||
profile.middleware,
|
||||
// investmentType.middleware,
|
||||
// exchangeRate.middleware,
|
||||
// ioService.middleware,
|
||||
// investorDetails.middleware,
|
||||
// investorTransaction.middleware,
|
||||
// bankDetails.middleware,
|
||||
// contact.middleware,
|
||||
// depositRequest.middleware,
|
||||
// drawalRequest.middleware,
|
||||
// deleteRequest.middleware,
|
||||
),
|
||||
});
|
||||
|
||||
setupListeners(store.dispatch);
|
||||
|
||||
export default store;
|
||||
|
||||
|
||||
|
||||
|
||||
16
src/main.jsx
16
src/main.jsx
@@ -6,6 +6,10 @@ import { ChakraProvider } from "@chakra-ui/react";
|
||||
import { extendTheme } from "@chakra-ui/react";
|
||||
import * as ReactDOM from "react-dom/client";
|
||||
|
||||
import { Provider } from "react-redux";
|
||||
import store from "./Store/Store.js";
|
||||
import GlobalStateProvider from "./Contexts/GlobalStateProvider.jsx";
|
||||
|
||||
// 2. Extend the theme to include custom colors, fonts, etc
|
||||
const colors = {
|
||||
brand: {
|
||||
@@ -15,12 +19,14 @@ const colors = {
|
||||
},
|
||||
};
|
||||
|
||||
const theme = extendTheme({ colors });
|
||||
const customTheme = extendTheme({ colors });
|
||||
|
||||
createRoot(document.getElementById("root")).render(
|
||||
<StrictMode>
|
||||
<ChakraProvider theme={theme}>
|
||||
<App />
|
||||
<ChakraProvider theme={customTheme}>
|
||||
<Provider store={store}>
|
||||
<GlobalStateProvider>
|
||||
<App />
|
||||
</GlobalStateProvider>
|
||||
</Provider>
|
||||
</ChakraProvider>
|
||||
</StrictMode>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user