Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Last active July 20, 2022 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ryanflorence/065962a600fcbc76d0968fec75e0b57a to your computer and use it in GitHub Desktop.
Save ryanflorence/065962a600fcbc76d0968fec75e0b57a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetch',
initial: 'home',
states: {
home: {
on: {
LOGIN: {
target: 'dashboard',
actions: 'recordLoginTime'
},
VIEW_COURSE: 'courseMarketingPage',
SIGN_UP_FOR_NEWSLETTER: 'home'
}
},
dashboard: {
on: {
START_COURSE: 'course',
VIEW_COURSE: 'courseMarketingPage',
VIEW_ACCOUNT: 'account'
}
},
courseMarketingPage: {
on: {
ADD_TO_CART: 'cart',
PREVIEW_CHAPTER: 'chapterPreview',
VIEW_OTHER_COURSE: 'courseMarketingPage'
}
},
cart: {
on: {
CHECKOUT: 'checkout'
}
},
checkout: {
on: {
PURCHASE: {
target: 'dashboard',
actions: 'enrollUser'
}
}
},
course: {
entry: ['markCourseStarted', 'markLastViewedCourse'],
on: {
START_CHAPTER: 'chapter'
}
},
chapterPreview: {
on: {
ADD_TO_CART: 'cart',
BACK: 'courseMarketingPage'
}
},
chapter: {
entry: ['markChapterViewed', 'markMostRecentViewed'],
on: {
NEXT_CHAPTER: {
target: 'chapter',
actions: 'markChapterComplete'
},
PREV_CHAPTER: 'chapter',
FINISH_COURSE: {
target: 'finishCourse',
actions: ['markChapterComplete', 'markCourseComplete']
}
}
},
finishCourse: {
on: {
NEXT_COURSE: 'course',
UPSELL: 'courseMarketingPage',
END: 'dashboard'
}
},
account: {
on: {
LOG_OUT: 'home',
GET_REFUND: {
target: 'account',
cond: 'under 30 days',
actions: 'refundTheirMoney'
},
EMAIL_SUPPORT: 'account'
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment