index.ts 820 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { createReducer } from '@reduxjs/toolkit';
  2. import { IAuthorizationState } from '../../../typescript/redux/authorization/interfaces';
  3. import {
  4. actionLogInSuccess,
  5. actionLogInReject,
  6. actionLogOutSuccess,
  7. actionLogOutReject,
  8. } from '../action';
  9. const initialState:IAuthorizationState = {
  10. token: '',
  11. number: '',
  12. name: '',
  13. lastName: '',
  14. country:'',
  15. avatarUrl: '',
  16. };
  17. const reducerAuthorization = createReducer(initialState, {
  18. [actionLogInSuccess.type]: (state, { payload:token }: {payload: string}) => {
  19. return {...state,token};
  20. },
  21. [actionLogInReject.type]: (state, _) => {
  22. return state;
  23. },
  24. [actionLogOutSuccess.type]: (_state, _) => {
  25. return initialState;
  26. },
  27. [actionLogOutReject.type]: (state, _) => {
  28. return state;
  29. },
  30. });
  31. export default reducerAuthorization;