classify web
This commit is contained in:
51
redux/reducer/authSlice.js
Normal file
51
redux/reducer/authSlice.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
import { store } from "../store"; // Ensure this import path is correct
|
||||
|
||||
const initialState = {
|
||||
data: null,
|
||||
};
|
||||
|
||||
export const authSlice = createSlice({
|
||||
name: "UserSignup",
|
||||
initialState,
|
||||
reducers: {
|
||||
|
||||
updateDataSuccess: (usersignup, action) => {
|
||||
usersignup.data = action.payload;
|
||||
},
|
||||
userUpdateData: (usersignup, action) => {
|
||||
usersignup.data.data = action.payload.data;
|
||||
},
|
||||
userLogout: (usersignup) => {
|
||||
usersignup.data = null; // Clear data when user logs out
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const { updateDataSuccess, userUpdateData, userLogout } = authSlice.actions;
|
||||
export default authSlice.reducer;
|
||||
|
||||
export const loadUpdateData = (data) => {
|
||||
store.dispatch(updateDataSuccess(data));
|
||||
};
|
||||
export const loadUpdateUserData = (data) => {
|
||||
store.dispatch(userUpdateData({ data }));
|
||||
};
|
||||
export const logoutSuccess = () => {
|
||||
store.dispatch(userLogout());
|
||||
};
|
||||
|
||||
|
||||
export const userSignUpData = createSelector(
|
||||
(state) => state.UserSignup,
|
||||
(UserSignup) => UserSignup?.data?.data
|
||||
);
|
||||
|
||||
export const getIsLoggedIn = createSelector(
|
||||
(state) => state.UserSignup,
|
||||
(UserSignup) => UserSignup?.data?.token
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
30
redux/reducer/breadCrumbSlice.js
Normal file
30
redux/reducer/breadCrumbSlice.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
|
||||
const initialState = {
|
||||
BreadcrumbPath: [],
|
||||
};
|
||||
|
||||
export const breadCrumbSlice = createSlice({
|
||||
name: "BreadcrumbPath",
|
||||
initialState,
|
||||
reducers: {
|
||||
setBreadcrumbPath: (state, action) => {
|
||||
state.BreadcrumbPath = action.payload;
|
||||
},
|
||||
resetBreadcrumb: () => {
|
||||
return initialState
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default breadCrumbSlice.reducer;
|
||||
export const { setBreadcrumbPath, resetBreadcrumb } = breadCrumbSlice.actions;
|
||||
|
||||
|
||||
export const BreadcrumbPathData = (state) => state.BreadcrumbPath.BreadcrumbPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
61
redux/reducer/categorySlice.js
Normal file
61
redux/reducer/categorySlice.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = {
|
||||
cateData: [],
|
||||
catLastPage: 1,
|
||||
catCurrentPage: 1,
|
||||
isCatLoading: false,
|
||||
isCatLoadMore: false,
|
||||
};
|
||||
|
||||
export const categorySlice = createSlice({
|
||||
name: "Category",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCateData: (state, action) => {
|
||||
state.cateData = action.payload;
|
||||
},
|
||||
setCatLastPage: (state, action) => {
|
||||
state.catLastPage = action.payload;
|
||||
},
|
||||
setCatCurrentPage: (state, action) => {
|
||||
state.catCurrentPage = action.payload;
|
||||
},
|
||||
setIsCatLoading: (state, action) => {
|
||||
state.isCatLoading = action.payload;
|
||||
},
|
||||
setIsCatLoadMore: (state, action) => {
|
||||
state.isCatLoadMore = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default categorySlice.reducer;
|
||||
export const {
|
||||
setCateData,
|
||||
setCatLastPage,
|
||||
setCatCurrentPage,
|
||||
setIsCatLoading,
|
||||
setIsCatLoadMore,
|
||||
} = categorySlice.actions;
|
||||
|
||||
export const CategoryData = createSelector(
|
||||
(state) => state.Category,
|
||||
(Category) => Category.cateData
|
||||
);
|
||||
export const getCatLastPage = createSelector(
|
||||
(state) => state.Category,
|
||||
(Category) => Category.catLastPage
|
||||
);
|
||||
export const getCatCurrentPage = createSelector(
|
||||
(state) => state.Category,
|
||||
(Category) => Category.catCurrentPage
|
||||
);
|
||||
export const getIsCatLoading = createSelector(
|
||||
(state) => state.Category,
|
||||
(Category) => Category.isCatLoading
|
||||
);
|
||||
export const getIsCatLoadMore = createSelector(
|
||||
(state) => state.Category,
|
||||
(Category) => Category.isCatLoadMore
|
||||
);
|
||||
134
redux/reducer/globalStateSlice.js
Normal file
134
redux/reducer/globalStateSlice.js
Normal file
@@ -0,0 +1,134 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
import { store } from "../store";
|
||||
|
||||
const initialState = {
|
||||
IsLoginModalOpen: false,
|
||||
IsVisitedLandingPage: false,
|
||||
IsShowBankDetails: false,
|
||||
Notification: null,
|
||||
IsUnauthorized: false,
|
||||
selectedLocation: null,
|
||||
// Add blocked users state
|
||||
blockedUsersList: [],
|
||||
blockedUsersLoading: false,
|
||||
};
|
||||
|
||||
export const globalStateSlice = createSlice({
|
||||
name: "GlobalState",
|
||||
initialState,
|
||||
reducers: {
|
||||
setIsLoginModalOpen: (state, action) => {
|
||||
state.IsLoginModalOpen = action.payload;
|
||||
},
|
||||
setIsVisitedLandingPage: (state, action) => {
|
||||
state.IsVisitedLandingPage = action.payload;
|
||||
},
|
||||
setIsShowBankDetails: (state, action) => {
|
||||
state.IsShowBankDetails = action.payload;
|
||||
},
|
||||
setNotification: (state, action) => {
|
||||
state.Notification = action.payload;
|
||||
},
|
||||
setIsUnauthorized: (state, action) => {
|
||||
state.IsUnauthorized = action.payload;
|
||||
},
|
||||
setSelectedLocation: (state, action) => {
|
||||
state.selectedLocation = action.payload;
|
||||
},
|
||||
// Add blocked users reducers
|
||||
setBlockedUsersList: (state, action) => {
|
||||
state.blockedUsersList = action.payload;
|
||||
},
|
||||
setBlockedUsersLoading: (state, action) => {
|
||||
state.blockedUsersLoading = action.payload;
|
||||
},
|
||||
addBlockedUser: (state, action) => {
|
||||
const userId = action.payload;
|
||||
if (!state.blockedUsersList.some(user => user.id === userId)) {
|
||||
state.blockedUsersList.push({ id: userId });
|
||||
}
|
||||
},
|
||||
removeBlockedUser: (state, action) => {
|
||||
const userId = action.payload;
|
||||
state.blockedUsersList = state.blockedUsersList.filter(user => user.id !== userId);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default globalStateSlice.reducer;
|
||||
export const {
|
||||
setIsLoginModalOpen,
|
||||
setIsVisitedLandingPage,
|
||||
setIsShowBankDetails,
|
||||
setNotification,
|
||||
setIsUnauthorized,
|
||||
setSelectedLocation,
|
||||
// Export blocked users actions
|
||||
setBlockedUsersList,
|
||||
setBlockedUsersLoading,
|
||||
addBlockedUser,
|
||||
removeBlockedUser,
|
||||
} = globalStateSlice.actions;
|
||||
|
||||
export const getIsVisitedLandingPage = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.IsVisitedLandingPage
|
||||
);
|
||||
|
||||
export const getIsLoginModalOpen = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.IsLoginModalOpen
|
||||
);
|
||||
|
||||
export const getIsShowBankDetails = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.IsShowBankDetails
|
||||
);
|
||||
|
||||
export const setIsLoginOpen = (value) => {
|
||||
store.dispatch(setIsLoginModalOpen(value));
|
||||
};
|
||||
|
||||
export const showBankDetails = () => {
|
||||
store.dispatch(setIsShowBankDetails(true));
|
||||
};
|
||||
|
||||
export const hideBankDetails = () => {
|
||||
store.dispatch(setIsShowBankDetails(false));
|
||||
};
|
||||
|
||||
export const getNotification = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.Notification
|
||||
);
|
||||
|
||||
export const getIsUnauthorized = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.IsUnauthorized
|
||||
);
|
||||
|
||||
export const getSelectedLocation = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState.selectedLocation
|
||||
);
|
||||
|
||||
// Add blocked users selectors with fallbacks
|
||||
export const getBlockedUsersList = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState?.blockedUsersList || []
|
||||
);
|
||||
|
||||
export const getBlockedUsersLoading = createSelector(
|
||||
(state) => state.GlobalState,
|
||||
(GlobalState) => GlobalState?.blockedUsersLoading || false
|
||||
);
|
||||
|
||||
export const getIsUserBlocked = createSelector(
|
||||
[getBlockedUsersList, (state, userId) => userId],
|
||||
(blockedUsersList, userId) => {
|
||||
if (!blockedUsersList || !Array.isArray(blockedUsersList)) {
|
||||
return false;
|
||||
}
|
||||
return blockedUsersList.some(user => user.id === userId);
|
||||
}
|
||||
);
|
||||
39
redux/reducer/languageSlice.js
Normal file
39
redux/reducer/languageSlice.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
|
||||
const initialState = {
|
||||
language: {},
|
||||
};
|
||||
|
||||
export const languageSlice = createSlice({
|
||||
name: "CurrentLanguage",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCurrentLanguage: (state, action) => {
|
||||
state.language = action.payload;
|
||||
},
|
||||
resetCurrentLanguage: (state, action) => {
|
||||
state.language = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default languageSlice.reducer;
|
||||
export const { setCurrentLanguage, resetCurrentLanguage } = languageSlice.actions;
|
||||
|
||||
export const CurrentLanguageData = createSelector(
|
||||
(state) => state.CurrentLanguage,
|
||||
(CurrentLanguage) => CurrentLanguage.language
|
||||
);
|
||||
|
||||
export const getIsRtl = createSelector(
|
||||
(state) => state.CurrentLanguage,
|
||||
(CurrentLanguage) => CurrentLanguage.language.rtl
|
||||
);
|
||||
|
||||
export const getCurrentLangCode = createSelector(
|
||||
(state) => state.CurrentLanguage,
|
||||
(CurrentLanguage) => CurrentLanguage.language.code
|
||||
);
|
||||
|
||||
|
||||
|
||||
74
redux/reducer/locationSlice.js
Normal file
74
redux/reducer/locationSlice.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
import { store } from "../store";
|
||||
|
||||
const initialState = {
|
||||
cityData: {
|
||||
area: "",
|
||||
areaId: "",
|
||||
city: "",
|
||||
state: "",
|
||||
country: "",
|
||||
lat: "",
|
||||
long: "",
|
||||
formattedAddress: "",
|
||||
},
|
||||
KilometerRange: 0,
|
||||
IsBrowserSupported: true,
|
||||
};
|
||||
export const locationSlice = createSlice({
|
||||
name: "Location",
|
||||
initialState,
|
||||
reducers: {
|
||||
setCityData: (location, action) => {
|
||||
location.cityData = action.payload.data;
|
||||
},
|
||||
setIsBrowserSupported: (location, action) => {
|
||||
location.IsBrowserSupported = action.payload;
|
||||
},
|
||||
setKilometerRange: (location, action) => {
|
||||
location.KilometerRange = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export default locationSlice.reducer;
|
||||
export const { setCityData, setIsBrowserSupported, setKilometerRange } =
|
||||
locationSlice.actions;
|
||||
|
||||
export const resetCityData = () => {
|
||||
const initialCityData = {
|
||||
area: "",
|
||||
areaId: "",
|
||||
city: "",
|
||||
state: "",
|
||||
country: "",
|
||||
lat: "",
|
||||
long: "",
|
||||
formattedAddress: "",
|
||||
};
|
||||
store.dispatch(setCityData({ data: initialCityData }));
|
||||
};
|
||||
|
||||
// Action to store location
|
||||
export const saveCity = (data) => {
|
||||
store.dispatch(setCityData({ data }));
|
||||
};
|
||||
|
||||
export const getCityData = createSelector(
|
||||
(state) => state.Location,
|
||||
(Location) => Location.cityData
|
||||
);
|
||||
export const getKilometerRange = createSelector(
|
||||
(state) => state.Location,
|
||||
(Location) => Number(Location.KilometerRange)
|
||||
);
|
||||
export const getIsBrowserSupported = createSelector(
|
||||
(state) => state.Location,
|
||||
(Location) => Location.IsBrowserSupported
|
||||
);
|
||||
|
||||
|
||||
export const getCurrentCountry = createSelector(
|
||||
(state) => state.Location,
|
||||
(Location) => Location.cityData.country
|
||||
);
|
||||
137
redux/reducer/settingSlice.js
Normal file
137
redux/reducer/settingSlice.js
Normal file
@@ -0,0 +1,137 @@
|
||||
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
||||
import { store } from "../store";
|
||||
|
||||
const initialState = {
|
||||
data: null,
|
||||
lastFetch: null,
|
||||
loading: false,
|
||||
fcmToken: null,
|
||||
};
|
||||
|
||||
export const settingsSlice = createSlice({
|
||||
name: "Settings",
|
||||
initialState,
|
||||
reducers: {
|
||||
settingsSucess: (settings, action) => {
|
||||
const { data } = action.payload;
|
||||
settings.data = data;
|
||||
},
|
||||
getToken: (settings, action) => {
|
||||
settings.fcmToken = action.payload.data;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { settingsSucess, getToken } = settingsSlice.actions;
|
||||
export default settingsSlice.reducer;
|
||||
|
||||
// Action to store token
|
||||
export const getFcmToken = (data) => {
|
||||
store.dispatch(getToken({ data }));
|
||||
};
|
||||
|
||||
// Selectors
|
||||
export const settingsData = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings.data?.data
|
||||
);
|
||||
|
||||
export const Fcmtoken = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.fcmToken
|
||||
);
|
||||
|
||||
export const getIsLandingPage = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.show_landing_page)
|
||||
);
|
||||
|
||||
export const getPlaceholderImage = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.placeholder_image
|
||||
);
|
||||
|
||||
export const getCompanyName = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.company_name
|
||||
);
|
||||
|
||||
export const getIsMaintenanceMode = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.maintenance_mode) === 1
|
||||
);
|
||||
|
||||
export const getIsFreAdListing = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.free_ad_listing) === 1
|
||||
);
|
||||
|
||||
export const getMinRange = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.min_length)
|
||||
);
|
||||
|
||||
export const getMaxRange = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.max_length)
|
||||
);
|
||||
|
||||
export const getIsDemoMode = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.demo_mode
|
||||
);
|
||||
|
||||
export const getOtpServiceProvider = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.otp_service_provider
|
||||
);
|
||||
|
||||
export const getDefaultLatitude = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.default_latitude)
|
||||
);
|
||||
export const getDefaultLongitude = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.default_longitude)
|
||||
);
|
||||
export const getIsPaidApi = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.map_provider === "google_places"
|
||||
);
|
||||
|
||||
export const getLanguages = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.languages
|
||||
);
|
||||
|
||||
export const getDefaultLanguageCode = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.default_language
|
||||
);
|
||||
|
||||
export const getShowLandingPage = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => Number(settings?.data?.data?.show_landing_page) === 1
|
||||
);
|
||||
|
||||
export const getCurrencyPosition = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.currency_symbol_position
|
||||
);
|
||||
|
||||
export const getCurrencySymbol = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.currency_symbol
|
||||
);
|
||||
|
||||
|
||||
export const getCurrencyIsoCode = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.currency_iso_code
|
||||
);
|
||||
|
||||
export const getAboutUs = createSelector(
|
||||
(state) => state.Settings,
|
||||
(settings) => settings?.data?.data?.about_us
|
||||
);
|
||||
|
||||
40
redux/store/index.js
Normal file
40
redux/store/index.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import { combineReducers, configureStore } from '@reduxjs/toolkit';
|
||||
import { persistStore, persistReducer } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import settingsReducer from "../reducer/settingSlice";
|
||||
import categoryReducer from '../reducer/categorySlice'
|
||||
import BreadcrumbPathReducer from '../reducer/breadCrumbSlice'
|
||||
import CurrentLanguageReducer from '../reducer/languageSlice'
|
||||
import locationReducer from '../reducer/locationSlice';
|
||||
import globalStateReducer from '../reducer/globalStateSlice';
|
||||
import authReducer from '../reducer/authSlice'
|
||||
|
||||
const persistConfig = {
|
||||
key: 'root',
|
||||
storage,
|
||||
manualPersisting: true,
|
||||
};
|
||||
|
||||
|
||||
const rootReducer = combineReducers({
|
||||
Settings: settingsReducer,
|
||||
Category: categoryReducer,
|
||||
UserSignup: authReducer,
|
||||
BreadcrumbPath: BreadcrumbPathReducer,
|
||||
CurrentLanguage: CurrentLanguageReducer,
|
||||
Location: locationReducer,
|
||||
GlobalState: globalStateReducer
|
||||
});
|
||||
|
||||
const persistedReducer = persistReducer(persistConfig, rootReducer);
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: persistedReducer,
|
||||
middleware: (getDefaultMiddleware) => [
|
||||
...getDefaultMiddleware({
|
||||
serializableCheck: false,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
export const persistor = persistStore(store);
|
||||
6
redux/store/providers.jsx
Normal file
6
redux/store/providers.jsx
Normal file
@@ -0,0 +1,6 @@
|
||||
"use client";
|
||||
import { Provider } from "react-redux";
|
||||
import { store } from ".";
|
||||
export function Providers({ children }) {
|
||||
return <Provider store={store}>{children}</Provider>;
|
||||
}
|
||||
Reference in New Issue
Block a user