Created
March 30, 2023 10:18
-
-
Save francescosalvi/46ea6223a25dc44f84b79cd3d60245bc to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const RequestAction = { | |
ACCEPT: 'accept', | |
ACCEPT_FREE: 'accept_free', | |
DECLINE: 'decline', | |
CHANGE: 'change', | |
PAY: 'pay', | |
WRITE: 'write', | |
SEND: 'send', | |
CLOSE: 'close', | |
CANCEL: 'cancel', | |
FAIL_PAYMENT: 'fail_payment', | |
CANCEL_PAYMENT: 'cancel_payment', | |
GET_VIDEO_VISIT_LINK: 'get_video_visit_link', | |
} | |
const RequestStatus = { | |
DRAFT: 'draft', | |
PENDING_DOCTOR_APPROVAL: 'pending_doctor_approval', | |
PENDING_PATIENT_APPROVAL: 'pending_patient_approval', | |
PENDING_PAYMENT: 'pending_payment', | |
ACTIVE: 'active', | |
CLOSED: 'closed', | |
CANCELLED: 'cancelled', | |
PAYMENT_CANCELLED: 'payment_cancelled', | |
PAYMENT_FAILED: 'payment_failed', | |
} | |
const FINAL_TYPE = 'final'; | |
const ConsultationStatusMachine = Machine({ | |
id: 'ConsultationStatuses', | |
initial: RequestStatus.DRAFT, | |
states: { | |
[RequestStatus.DRAFT]: { | |
on: { | |
[RequestAction.CHANGE]: RequestStatus.PENDING_PAYMENT, | |
[RequestAction.CANCEL]: RequestStatus.CANCELLED, | |
}, | |
}, | |
[RequestStatus.PENDING_PAYMENT]: { | |
on: { | |
[RequestAction.PAY]: RequestStatus.ACTIVE, | |
[RequestAction.CANCEL]: RequestStatus.CANCELLED, | |
[RequestAction.CANCEL_PAYMENT]: RequestStatus.PAYMENT_CANCELLED, | |
[RequestAction.FAIL_PAYMENT]: RequestStatus.PAYMENT_FAILED, | |
}, | |
}, | |
[RequestStatus.PAYMENT_FAILED]: { | |
on: { | |
[RequestAction.PAY]: RequestStatus.ACTIVE, | |
[RequestAction.CANCEL]: RequestStatus.CANCELLED, | |
}, | |
}, | |
[RequestStatus.ACTIVE]: { | |
on: { | |
[RequestAction.CLOSE]: RequestStatus.CLOSED, | |
}, | |
}, | |
[RequestStatus.CLOSED]: { | |
type: FINAL_TYPE, | |
}, | |
[RequestStatus.CANCELLED]: { | |
type: FINAL_TYPE, | |
}, | |
[RequestStatus.PAYMENT_CANCELLED]: { | |
type: FINAL_TYPE, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment