Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const dismissMachine = Machine(
- {
- id: 'dismissMachine',
- initial: 'load',
- context: {
- resolutions: [],
- selectedRisksCount: 1,
- resolutionId: undefined,
- reason: undefined,
- },
- states: {
- load: {
- invoke: {
- src: 'getResolutions',
- onDone: [
- {
- cond: 'hasResponseError',
- target: 'error.serverError',
- },
- {
- cond: 'hasResolutions',
- actions: ['setResolutions'],
- target: 'form',
- },
- {
- target: 'error.emptyResolutions',
- },
- ],
- onError: 'error.serverError',
- },
- on: {
- CLICK_CANCEL: 'close',
- CLICK_OUTSIDE: 'close',
- },
- },
- form: {
- on: {
- CLICK_CANCEL: 'close',
- CLICK_OUTSIDE: 'close',
- INPUT_RESOLUTION: {
- actions: ['setResolutionId'],
- },
- INPUT_REASON: {
- actions: ['setReason'],
- },
- SUBMIT_FORM: [
- {
- cond: 'isValid',
- target: 'save',
- },
- ],
- },
- },
- save: {
- invoke: {
- src: 'dismiss',
- onDone: 'success',
- onError: 'error.saveFailed',
- },
- },
- success: {
- invoke: {
- src: 'getSelectedRisksCount',
- onDone: {
- actions: ['setSelectedRisksCount', 'handleSaveSuccess'],
- },
- },
- on: { CLICK_CONFIRM: 'close' },
- /* $FlowFixMe: Non-string literal property keys not supported. */
- after: { 3000: 'close' },
- },
- error: {
- on: {
- CLICK_CANCEL: 'close',
- CLICK_OUTSIDE: 'close',
- },
- states: {
- emptyResolutions: {
- meta: {
- message: 'There are no resolution options available.',
- },
- },
- serverError: {
- meta: {
- message: 'There was a problem loading resolutions.',
- },
- },
- saveFailed: {
- meta: {
- message: 'There was a problem dismissing the risk.',
- },
- },
- },
- },
- close: {
- entry: 'handleClose',
- type: 'final',
- },
- },
- },
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement