Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. const dismissMachine = Machine(
  2. {
  3. id: 'dismissMachine',
  4. initial: 'load',
  5. context: {
  6. resolutions: [],
  7. selectedRisksCount: 1,
  8. resolutionId: undefined,
  9. reason: undefined,
  10. },
  11. states: {
  12. load: {
  13. invoke: {
  14. src: 'getResolutions',
  15. onDone: [
  16. {
  17. cond: 'hasResponseError',
  18. target: 'error.serverError',
  19. },
  20. {
  21. cond: 'hasResolutions',
  22. actions: ['setResolutions'],
  23. target: 'form',
  24. },
  25. {
  26. target: 'error.emptyResolutions',
  27. },
  28. ],
  29. onError: 'error.serverError',
  30. },
  31. on: {
  32. CLICK_CANCEL: 'close',
  33. CLICK_OUTSIDE: 'close',
  34. },
  35. },
  36. form: {
  37. on: {
  38. CLICK_CANCEL: 'close',
  39. CLICK_OUTSIDE: 'close',
  40. INPUT_RESOLUTION: {
  41. actions: ['setResolutionId'],
  42. },
  43. INPUT_REASON: {
  44. actions: ['setReason'],
  45. },
  46. SUBMIT_FORM: [
  47. {
  48. cond: 'isValid',
  49. target: 'save',
  50. },
  51. ],
  52. },
  53. },
  54. save: {
  55. invoke: {
  56. src: 'dismiss',
  57. onDone: 'success',
  58. onError: 'error.saveFailed',
  59. },
  60. },
  61. success: {
  62. invoke: {
  63. src: 'getSelectedRisksCount',
  64. onDone: {
  65. actions: ['setSelectedRisksCount', 'handleSaveSuccess'],
  66. },
  67. },
  68. on: { CLICK_CONFIRM: 'close' },
  69. /* $FlowFixMe: Non-string literal property keys not supported. */
  70. after: { 3000: 'close' },
  71. },
  72. error: {
  73. on: {
  74. CLICK_CANCEL: 'close',
  75. CLICK_OUTSIDE: 'close',
  76. },
  77. states: {
  78. emptyResolutions: {
  79. meta: {
  80. message: 'There are no resolution options available.',
  81. },
  82. },
  83. serverError: {
  84. meta: {
  85. message: 'There was a problem loading resolutions.',
  86. },
  87. },
  88. saveFailed: {
  89. meta: {
  90. message: 'There was a problem dismissing the risk.',
  91. },
  92. },
  93. },
  94. },
  95. close: {
  96. entry: 'handleClose',
  97. type: 'final',
  98. },
  99. },
  100. },
  101. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement