user.js 798 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { Map } from "immutable";
  2. import {
  3. BAN,
  4. AUTHENTICATE,
  5. } from "actions/app";
  6. const initialState = Map({
  7. loggedIn: false,
  8. authProcessed: false,
  9. role: "default",
  10. username: "",
  11. userId: "",
  12. banned: {
  13. status: false,
  14. reason: "",
  15. },
  16. });
  17. const actionsMap = {
  18. [BAN]: (state, action) => {
  19. return Object.assign({}, state.toObject(), {
  20. banned: {
  21. status: true,
  22. reason: action.reason,
  23. },
  24. });
  25. },
  26. [AUTHENTICATE]: (state, action) => {
  27. return state.merge({
  28. loggedIn: action.data.loggedIn,
  29. authProcessed: true,
  30. role: action.data.role,
  31. username: action.data.username,
  32. userId: action.data.userId,
  33. });
  34. },
  35. };
  36. export default function reducer(state = initialState, action = {}) {
  37. const fn = actionsMap[action.type];
  38. return fn ? fn(state, action) : state;
  39. }