-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cart-customer): set cart to mutating when the user is logged in (#…
…2508) this is to track customer cart merging/resolving
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
ActionReducer, | ||
ActionReducerMap, | ||
} from '@ngrx/store'; | ||
|
||
import { | ||
DaffAuthLoginActionTypes, | ||
DaffAuthLoginActions, | ||
DaffAuthRegisterActionTypes, | ||
DaffAuthRegisterActions, | ||
DaffAuthResetPasswordActionTypes, | ||
DaffAuthResetPasswordActions, | ||
} from '@daffodil/auth/state'; | ||
import { | ||
DaffCartOperationType, | ||
DaffCartReducerState, | ||
DaffCartReducersState, | ||
daffCartReducerInitialState, | ||
} from '@daffodil/cart/state'; | ||
import { | ||
DaffState, | ||
daffIdentityReducer, | ||
} from '@daffodil/core/state'; | ||
|
||
/** | ||
* Sets cart to mutating when the user logs in. | ||
* This is to correctly represent the cart merge operation that is performed after a login. | ||
*/ | ||
export const daffCartCustomerLoginMutatingReducer: ActionReducer<DaffCartReducerState> = ( | ||
state = daffCartReducerInitialState, | ||
action: DaffAuthLoginActions | DaffAuthRegisterActions | DaffAuthResetPasswordActions, | ||
) => { | ||
switch (action.type) { | ||
case DaffAuthLoginActionTypes.LoginSuccessAction: | ||
case DaffAuthRegisterActionTypes.RegisterSuccessAction: | ||
case DaffAuthResetPasswordActionTypes.ResetPasswordSuccessAction: | ||
if ((action.type === DaffAuthRegisterActionTypes.RegisterSuccessAction || action.type === DaffAuthResetPasswordActionTypes.ResetPasswordSuccessAction) && !action.token) { | ||
return state; | ||
} | ||
return { | ||
...state, | ||
loading: { | ||
...state.loading, | ||
[DaffCartOperationType.Cart]: DaffState.Mutating, | ||
}, | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
}; | ||
|
||
export const daffCartCustomerLoginMutatingReducerMap: ActionReducerMap<DaffCartReducersState> = { | ||
cart: daffCartCustomerLoginMutatingReducer, | ||
cartItems: daffIdentityReducer, | ||
order: daffIdentityReducer, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters