Skip to content

Instantly share code, notes, and snippets.

@unglud
Created January 11, 2023 11:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unglud/202a1b7588c1a9cccc0f81fd8276668e to your computer and use it in GitHub Desktop.
Save unglud/202a1b7588c1a9cccc0f81fd8276668e to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
var EmailType;
(function (EmailType) {
EmailType["APPLICATION_SUBMISSION"] = "APPLICATION_SUBMISSION";
EmailType["ACCEPT_OFFER_REMINDER_1"] = "ACCEPT_OFFER_REMINDER_1";
EmailType["ACCEPT_OFFER_REMINDER_2"] = "ACCEPT_OFFER_REMINDER_2";
EmailType["ACCEPT_OFFER_REMINDER_3"] = "ACCEPT_OFFER_REMINDER_3";
EmailType["ACCEPT_OFFER_REMINDER_4"] = "ACCEPT_OFFER_REMINDER_4";
EmailType["APPROVAL"] = "APPROVAL";
EmailType["CANCELLATION"] = "CANCELLATION";
EmailType["COMPANY_INFORMATION_REMINDER_1"] = "COMPANY_INFORMATION_REMINDER_1";
EmailType["COMPANY_INFORMATION_REMINDER_2"] = "COMPANY_INFORMATION_REMINDER_2";
EmailType["COMPANY_INFORMATION_REMINDER_3"] = "COMPANY_INFORMATION_REMINDER_3";
EmailType["CONTRACT_SIGNED"] = "CONTRACT_SIGNED";
EmailType["OFFER_ACCEPTED"] = "OFFER_ACCEPTED";
EmailType["PAID_OUT"] = "PAID_OUT";
EmailType["SUBMIT_APPLICATION_REMINDER_1"] = "SUBMIT_APPLICATION_REMINDER_1";
EmailType["SUBMIT_APPLICATION_REMINDER_2"] = "SUBMIT_APPLICATION_REMINDER_2";
EmailType["SUBMIT_APPLICATION_REMINDER_3"] = "SUBMIT_APPLICATION_REMINDER_3";
EmailType["SUBMIT_APPLICATION_REMINDER_4"] = "SUBMIT_APPLICATION_REMINDER_4";
EmailType["SUBMIT_APPLICATION_REMINDER_5"] = "SUBMIT_APPLICATION_REMINDER_5";
})(EmailType || (EmailType = {}));
var ReminderFlowTypes;
(function (ReminderFlowTypes) {
ReminderFlowTypes["COMPANY_INFORMATION_REMINDER"] = "COMPANY_INFORMATION_REMINDER";
ReminderFlowTypes["SUBMIT_APPLICATION_REMINDER"] = "SUBMIT_APPLICATION_REMINDER";
ReminderFlowTypes["ACCEPT_OFFER_REMINDER"] = "ACCEPT_OFFER_REMINDER";
})(ReminderFlowTypes || (ReminderFlowTypes = {}));
var ApplicationState;
(function (ApplicationState) {
ApplicationState["start"] = "start";
ApplicationState["register"] = "register";
ApplicationState["new_application"] = "new_application";
ApplicationState["submitted"] = "submitted";
ApplicationState["submitted_declined"] = "submitted_declined";
ApplicationState["approved"] = "approved";
ApplicationState["accepted"] = "accepted";
ApplicationState["paidout"] = "paidout";
ApplicationState["declined"] = "declined";
ApplicationState["complete"] = "complete";
})(ApplicationState || (ApplicationState = {}));
const setResolved = (resolved) => assign({ resolved: (context) => (context.resolved = resolved) });
const machine = Machine({
context: {
applicationId: 12,
customerId: 34,
resolved: true,
},
id: "application",
initial: "start",
predictableActionArguments: true,
states: {
[ApplicationState.start]: {
on: {
next: ApplicationState.register,
[ApplicationState.register]: ApplicationState.register,
[ApplicationState.new_application]: ApplicationState.new_application,
},
},
[ApplicationState.register]: {
entry: setResolved(false),
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: null,
reminderFlow: [
{
reminderFlowAction: "start",
reminderFlowType: ReminderFlowTypes.COMPANY_INFORMATION_REMINDER,
},
],
type: "email",
},
},
],
on: {
next: ApplicationState.new_application,
[ApplicationState.submitted]: ApplicationState.submitted,
[ApplicationState.new_application]: ApplicationState.new_application,
[ApplicationState.declined]: ApplicationState.declined,
},
},
[ApplicationState.new_application]: {
entry: setResolved(false),
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: null,
reminderFlow: [
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.COMPANY_INFORMATION_REMINDER,
},
{
reminderFlowAction: "start",
reminderFlowType: ReminderFlowTypes.SUBMIT_APPLICATION_REMINDER,
},
],
type: "email",
},
},
],
on: {
next: ApplicationState.submitted,
[ApplicationState.submitted]: ApplicationState.submitted,
[ApplicationState.declined]: ApplicationState.declined,
},
},
[ApplicationState.submitted]: {
entry: setResolved(false),
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: EmailType.APPLICATION_SUBMISSION,
reminderFlow: [
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.SUBMIT_APPLICATION_REMINDER,
},
],
type: "email",
},
},
],
on: {
next: ApplicationState.approved,
[ApplicationState.approved]: ApplicationState.approved,
[ApplicationState.declined]: ApplicationState.submitted_declined,
},
},
[ApplicationState.approved]: {
entry: setResolved(false),
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: EmailType.APPROVAL,
reminderFlow: [
{
reminderFlowAction: "start",
reminderFlowType: ReminderFlowTypes.ACCEPT_OFFER_REMINDER,
},
],
type: "email",
},
},
],
on: {
next: ApplicationState.accepted,
[ApplicationState.accepted]: ApplicationState.accepted,
[ApplicationState.declined]: ApplicationState.declined,
},
},
[ApplicationState.accepted]: {
entry: setResolved(false),
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: EmailType.OFFER_ACCEPTED,
reminderFlow: [
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.ACCEPT_OFFER_REMINDER,
},
],
type: "email",
},
},
],
on: {
next: ApplicationState.paidout,
[ApplicationState.paidout]: ApplicationState.paidout,
[ApplicationState.declined]: ApplicationState.declined,
},
},
[ApplicationState.paidout]: {
entry: setResolved(false),
// @ts-ignore
invoke: {
onDone: {
actions: setResolved(true),
target: ApplicationState.complete,
},
src: {
emailType: EmailType.PAID_OUT,
type: "email",
},
},
},
[ApplicationState.declined]: {
invoke: [
{
// @ts-ignore
onDone: {
actions: setResolved(true),
},
src: {
emailType: null,
reminderFlow: [
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.COMPANY_INFORMATION_REMINDER,
},
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.SUBMIT_APPLICATION_REMINDER,
},
{
reminderFlowAction: "stop",
reminderFlowType: ReminderFlowTypes.ACCEPT_OFFER_REMINDER,
},
],
type: "email",
},
},
],
type: "final",
},
[ApplicationState.submitted_declined]: {
entry: setResolved(false),
// @ts-ignore
invoke: {
onDone: {
actions: setResolved(true),
target: ApplicationState.declined,
},
src: {
emailType: EmailType.CANCELLATION,
type: "email",
},
},
},
[ApplicationState.complete]: {
type: "final",
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment