dylan10293

Untitled

Mar 2nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import {
  2. HOSPITAL_CODE_CHANGED,
  3. CLEAR_HOSPITAL_CODE,
  4. AUTH_UPDATE,
  5. LOGIN_USER,
  6. LOGIN_USER_FAIL,
  7. LOGIN_USER_SUCCESS,
  8. UPDATE_HOSPITAL_SERVER,
  9. RESET_USER
  10. } from '../actions/types';
  11.  
  12. const INITIAL_STATE = {
  13. mainServer: {
  14. url: '172.29.189.130/getServer',
  15. port: 80,
  16. protocol: 'http'
  17. },
  18. hospitalCode: null,
  19. hospitalServer: {
  20. mqtt: {
  21. url: null,
  22. port: null,
  23. protocol: null
  24. },
  25. rest: {
  26. url: null,
  27. port: null,
  28. protocol: null
  29. }
  30. },
  31. hospitalName: 'Default',
  32. username: 'Nursing6C',
  33. password: 'nursing6c',
  34. token: '',
  35. rememberMe: false,
  36. loading: false,
  37. error: '',
  38. user: null
  39. };
  40.  
  41. export default (state = INITIAL_STATE, action) => {
  42.  
  43. switch (action.type) {
  44. case CLEAR_HOSPITAL_CODE:
  45. return {
  46. ...state,
  47. hospitalCode: null
  48. }
  49. case RESET_USER:
  50. return {
  51. ...state,
  52. token: '',
  53. user: null,
  54. loading: false,
  55. error: ''
  56. }
  57. case HOSPITAL_CODE_CHANGED:
  58. return {
  59. ...state,
  60. hospitalCode: action.payload
  61. }
  62. case UPDATE_HOSPITAL_SERVER:
  63. return {
  64. ...state,
  65. hospitalServer: action.payload.server,
  66. hospitalCode: action.payload.hospitalCode,
  67. hospitalName: action.payload.hospitalName
  68. }
  69. case AUTH_UPDATE:
  70. return {
  71. ...state,
  72. [action.payload.prop]: action.payload.value
  73. }
  74. case LOGIN_USER:
  75. return {
  76. ...state,
  77. loading: true,
  78. error: '',
  79. user: action.payload
  80. }
  81. case LOGIN_USER_SUCCESS:
  82. return {
  83. ...state,
  84. token: action.payload,
  85. loading: false,
  86. error: ''
  87. }
  88. case LOGIN_USER_FAIL:
  89. return {
  90. ...state,
  91. loading: false,
  92. error: 'Authentication Failed.' + action.payload,
  93. password: ''
  94. }
  95. default:
  96. return state
  97. }
  98. }
Add Comment
Please, Sign In to add comment