Skip to content

Instantly share code, notes, and snippets.

@francescosalvi
Created March 30, 2023 10:16
Show Gist options
  • Save francescosalvi/feacb2cec50202342430cb97d8e1a6ff to your computer and use it in GitHub Desktop.
Save francescosalvi/feacb2cec50202342430cb97d8e1a6ff to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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 VideoVisitStatusMachine = Machine({
id: 'VideoVisitStatuses',
initial: RequestStatus.DRAFT,
states: {
[RequestStatus.DRAFT]: {
on: {
[RequestAction.CHANGE]: RequestStatus.PENDING_DOCTOR_APPROVAL,
[RequestAction.CANCEL]: RequestStatus.CANCELLED,
},
},
[RequestStatus.PENDING_DOCTOR_APPROVAL]: {
on: {
[RequestAction.ACCEPT]: RequestStatus.PENDING_PAYMENT,
[RequestAction.ACCEPT_FREE]: RequestStatus.ACTIVE,
[RequestAction.DECLINE]: RequestStatus.PENDING_PATIENT_APPROVAL,
[RequestAction.CANCEL]: RequestStatus.CANCELLED,
},
},
[RequestStatus.PENDING_PATIENT_APPROVAL]: {
on: {
[RequestAction.ACCEPT]: RequestStatus.PENDING_PAYMENT,
[RequestAction.ACCEPT_FREE]: RequestStatus.ACTIVE,
[RequestAction.DECLINE]: RequestStatus.PENDING_DOCTOR_APPROVAL,
[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,
[RequestAction.CANCEL]: RequestStatus.CANCELLED,
},
},
[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