Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import {produce} from 'immer';
  2.  
  3. export interface ValidationResult {
  4. status: 'success' | 'pending' | 'failure';
  5. resultCode?: 'valid' | 'products_limit_reached' | 'no_products';
  6. }
  7.  
  8. export interface State {
  9. validationResults: { [correlationId: string]: ValidationResult };
  10. }
  11.  
  12. const initialState: State = {
  13. validationResults: {}
  14. };
  15.  
  16. export const producer = (draft: State, action: Action) => {
  17. switch(action.type) {
  18. case 'LOAD_VALIDATION_RESULT':
  19. draft.validationResults[action.payload.correlationId] = {
  20. resultCode: null,
  21. status: 'pending'
  22. };
  23. break;
  24. case 'LOAD_VALIDATION_RESULT_SUCCESS':
  25. draft.validationResults[action.payload.correlationId] = {
  26. resultCode: action.payload.resultCode,
  27. status: 'success'
  28. };
  29. break;
  30. case 'LOAD_VALIDATION_RESULT_FAILURE':
  31. draft.validationResults[action.payload.correlationId] = {
  32. resultCode: null,
  33. status: 'failure'
  34. };
  35. break;
  36. }
  37.  
  38. return draft;
  39. };
  40.  
  41. export const reducer = produce(producer, initialState);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement