Created
July 30, 2021 06:26
-
-
Save tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// TODO: this needs to be refactored to a better location | |
const brandNames = { | |
botox: 'BOTOX®', | |
juvederm: 'JUVÉDERM®', | |
cool_sculpting: 'CoolSculpting® and CoolSculpting® Elite', | |
cool_tone: 'CoolTone®', | |
diamond_glow: 'DiamondGlow®', | |
kybella: 'KYBELLA®', | |
latisse: 'LATISSE®', | |
natrelle: 'Natrelle®', | |
skin_medica: 'SkinMedica®', | |
}; | |
const ImportantSafetyInformationMachine = Machine( | |
{ | |
id: 'isi-builder', | |
initial: 'start', | |
context: { | |
brands: [''], | |
codeIds: [], | |
}, | |
states: { | |
start: { | |
on: { | |
'': [ | |
{ target: 'containsBotox', cond: 'containsBotox' }, | |
{ | |
target: 'singleSafetyAndPrescribingInfo', | |
cond: 'hasKybellaOrLatisse', | |
actions: 'setSingleSafetyInformationOnly', | |
}, | |
{ | |
target: 'importantSafetyInformationOnly', | |
actions: 'setImportantSafetyInformationOnly', | |
}, | |
], | |
}, | |
}, | |
containsBotox: { | |
on: { | |
'': [ | |
{ | |
target: 'botoxOnly', | |
cond: 'hasOnlyOneCondition', | |
actions: 'setBotoxOnly', | |
}, | |
{ | |
target: 'botoxSafetyAndPrescribingInfo', | |
cond: 'hasKybellaOrLatisse', | |
actions: ['setBotoxOnly', 'setSafetyAndPrescribingInfo'], | |
}, | |
{ | |
target: 'botoxOnlyImportantSafetyInformationOnly', | |
actions: ['setBotoxOnly', 'setImportantSafetyInformationOnly'], | |
}, | |
], | |
}, | |
}, | |
singleSafetyAndPrescribingInfo: {}, | |
importantSafetyInformationOnly: {}, | |
doesNotContainBotox: {}, | |
hasOnlyOneCondition: {}, | |
botoxOnly: {}, | |
botoxSafetyAndPrescribingInfo: {}, | |
botoxOnlyImportantSafetyInformationOnly: {}, | |
}, | |
}, | |
{ | |
actions: { | |
setBotoxOnly: assign({ | |
codeIds: (context) => { | |
return [...context.codeIds, 'BotoxOnly']; | |
}, | |
}), | |
setImportantSafetyInformationOnly: assign({ | |
codeIds: (context) => [ | |
...context.codeIds, | |
'ImportantSafetyInformationOnly', | |
], | |
}), | |
setSingleSafetyInformationOnly: assign({ | |
codeIds: (context) => [ | |
...context.codeIds, | |
'SingleSafetyAndPrescribingInfo', | |
], | |
}), | |
setSafetyAndPrescribingInfo: assign({ | |
codeIds: (context) => { | |
return [...context.codeIds, 'SafetyAndPrescribingInfo']; | |
}, | |
}), | |
}, | |
guards: { | |
doesNotContainBotox: (context) => | |
!context.brands.includes(brandNames.botox), | |
containsBotox: (context) => context.brands.includes(brandNames.botox), | |
hasOnlyOneCondition: (context) => context.brands.length === 1, | |
hasKybellaOrLatisse: (context) => { | |
return context.brands.some( | |
(brand) => | |
brand === brandNames.kybella || brand === brandNames.latisse | |
); | |
}, | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment