1
- import { api , GetUserResponse } from '@/lib/api' ;
1
+ import { api } from '@/lib/api' ;
2
2
import { EMAIL_REMINDERS_FREQUENCY , LANGUAGES } from '@/lib/constants/enums' ;
3
3
import { createSlice , PayloadAction } from '@reduxjs/toolkit' ;
4
4
import { PartnerAccesses } from './partnerAccessSlice' ;
@@ -135,23 +135,18 @@ const slice = createSlice({
135
135
136
136
extraReducers : ( builder ) => {
137
137
builder . addMatcher ( api . endpoints . addUser . matchFulfilled , ( state , { payload } ) => {
138
- const activeSubscriptions = getActiveSubscriptions ( payload ) ;
139
-
140
- return Object . assign ( { } , state , payload . user , { activeSubscriptions } ) ;
138
+ return Object . assign ( { } , state , payload . user ) ;
141
139
} ) ;
142
140
builder . addMatcher ( api . endpoints . updateUser . matchFulfilled , ( state , { payload } ) => {
143
141
return Object . assign ( { } , state , payload ) ;
144
142
} ) ;
145
143
builder . addMatcher ( api . endpoints . getUser . matchFulfilled , ( state , { payload } ) => {
146
- const activeSubscriptions = getActiveSubscriptions ( payload ) ;
147
-
148
- return Object . assign ( { } , state , payload . user , { activeSubscriptions } ) ;
144
+ return Object . assign ( { } , state , payload . user ) ;
149
145
} ) ;
150
146
builder . addMatcher ( api . endpoints . subscribeToWhatsapp . matchFulfilled , ( state , { payload } ) => {
151
147
if ( isSubscriptionActive ( payload ) ) {
152
148
state . activeSubscriptions . push ( payload ) ;
153
149
}
154
-
155
150
return state ;
156
151
} ) ;
157
152
builder . addMatcher (
@@ -163,12 +158,16 @@ const slice = createSlice({
163
158
return state ;
164
159
} ,
165
160
) ;
161
+ builder . addMatcher ( api . endpoints . getSubscriptionsUser . matchFulfilled , ( state , { payload } ) => {
162
+ state . activeSubscriptions = getActiveSubscriptions ( payload ) ;
163
+ return state ;
164
+ } ) ;
166
165
} ,
167
166
} ) ;
168
167
169
- const getActiveSubscriptions = ( payload : GetUserResponse ) : ActiveSubscription [ ] => {
170
- if ( payload . subscriptions && payload . subscriptions . length > 0 ) {
171
- return payload . subscriptions . filter ( isSubscriptionActive ) ;
168
+ const getActiveSubscriptions = ( subscriptions : Subscriptions ) : ActiveSubscription [ ] => {
169
+ if ( subscriptions && subscriptions . length > 0 ) {
170
+ return subscriptions . filter ( isSubscriptionActive ) ;
172
171
}
173
172
return [ ] ;
174
173
} ;
0 commit comments