選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

candidateReducer.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import createReducer from "../../utils/createReducer";
  2. import {
  3. CANDIDATE_ERROR,
  4. CANDIDATE_SUCCESS,
  5. CANDIDATE_COMMENTS_SUCCESS,
  6. CANDIDATE_COMMENTS_ERROR,
  7. DELETE_CANDIDATE_SUCCESS,
  8. DELETE_CANDIDATE_ERROR
  9. } from "../../actions/candidate/candidateActionConstants";
  10. const initialState = {
  11. candidate: {},
  12. errorMessage: "",
  13. };
  14. export default createReducer(
  15. {
  16. [CANDIDATE_SUCCESS]: setCandidate,
  17. [CANDIDATE_ERROR]: setError,
  18. [CANDIDATE_COMMENTS_SUCCESS]: setComments,
  19. [CANDIDATE_COMMENTS_ERROR]: setCommentsError,
  20. [DELETE_CANDIDATE_SUCCESS]:deleteCandidate,
  21. [DELETE_CANDIDATE_ERROR]:deleteCandidateError
  22. },
  23. initialState
  24. );
  25. function setCandidate(state, action) {
  26. return {
  27. ...state,
  28. candidate: action.payload,
  29. };
  30. }
  31. function setError(state, action) {
  32. return {
  33. ...state,
  34. errorMessage: action.payload,
  35. };
  36. }
  37. function setComments(state, action) {
  38. const currentDate = new Date();
  39. console.log("Ovde smo" + currentDate);
  40. var datetime =
  41. currentDate.getFullYear() +
  42. "-" +
  43. (currentDate.getMonth() <= 9 ? "0" + (currentDate.getMonth() + 1) : currentDate.getMonth() + 1) +
  44. "-" +
  45. (currentDate.getDate() <= 9
  46. ? "0" + currentDate.getDate()
  47. : currentDate.getDate()) +
  48. "T" +
  49. currentDate.getHours() +
  50. ":" +
  51. (currentDate.getMinutes() <= 9
  52. ? "0" + currentDate.getMinutes()
  53. : currentDate.getMinutes()) +
  54. ":" +
  55. (currentDate.getSeconds() <= 9
  56. ? "0" + currentDate.getSeconds()
  57. : currentDate.getSeconds());
  58. const obj = {
  59. content: action.payload.myObj.content,
  60. dateOfSending: datetime,
  61. user: action.payload.user,
  62. };
  63. return {
  64. ...state,
  65. candidate: {
  66. ...state.candidate,
  67. comments: [...state.candidate.comments, obj],
  68. },
  69. };
  70. }
  71. function setCommentsError(state, action) {
  72. return {
  73. ...state,
  74. errorMessage: action.payload,
  75. };
  76. }
  77. function deleteCandidate(state) {
  78. return {
  79. ...state,
  80. candidate: {},
  81. };
  82. }
  83. function deleteCandidateError(state, action) {
  84. return {
  85. ...state,
  86. errorMessage: action.payload,
  87. };
  88. }