Skip to content

Instantly share code, notes, and snippets.

@tmbtech
Created July 30, 2021 06:26
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 tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.
Save tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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