Created
July 30, 2021 06:26
-
-
Save tmbtech/0edd42120acf8ccfb6c8d875bf68b24f to your computer and use it in GitHub Desktop.
Revisions
-
tmbtech created this gist
Jul 30, 2021 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,106 @@ // 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 ); }, }, } );