2026-07-02 14:34:19 +05:30

68 lines
1.7 KiB
TypeScript

import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { PartnerProfile, PartnerLocation } from '@app-types/index';
interface AuthState {
isAuthenticated: boolean;
hasCompletedOnboarding: boolean;
isOnline: boolean;
token: string | null;
partnerId: string | null;
partnerProfile: PartnerProfile | null;
requestId: string | null; // OTP request ID
}
const initialState: AuthState = {
isAuthenticated: false,
hasCompletedOnboarding: false,
isOnline: false,
token: null,
partnerId: null,
partnerProfile: null,
requestId: null,
};
const authSlice = createSlice({
name: 'auth',
initialState,
reducers: {
setAuthenticated: (
state,
action: PayloadAction<{ token: string; partnerId: string }>,
) => {
state.isAuthenticated = true;
state.token = action.payload.token;
state.partnerId = action.payload.partnerId;
},
setRequestId: (state, action: PayloadAction<string>) => {
state.requestId = action.payload;
},
setOnboardingComplete: (state) => {
state.hasCompletedOnboarding = true;
},
setOnlineStatus: (state, action: PayloadAction<boolean>) => {
state.isOnline = action.payload;
},
setProfile: (state, action: PayloadAction<PartnerProfile>) => {
state.partnerProfile = action.payload;
},
setLocation: (state, action: PayloadAction<PartnerLocation>) => {
if (state.partnerProfile) {
state.partnerProfile.location = action.payload;
}
},
logout: () => initialState,
},
});
export const {
setAuthenticated,
setRequestId,
setOnboardingComplete,
setOnlineStatus,
setProfile,
setLocation,
logout,
} = authSlice.actions;
export default authSlice.reducer;