Skip to content

Instantly share code, notes, and snippets.

@aceslick911
Created April 19, 2023 05:47
Show Gist options
  • Save aceslick911/d2a9e9813adb7f207c09c1dd85f2a17f to your computer and use it in GitHub Desktop.
Save aceslick911/d2a9e9813adb7f207c09c1dd85f2a17f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const fetchMachine = Machine({
"id": "WebAssessment",
"description": "This is a demo statechart that shows WebAssessment's screen flow.\n\nSince statecharts can be generated to and from JSON / Typescript / Javascript, I just used \n\n`src/config/nerva/NervaConfig3.ts` \n\nto help me make this with mostly copy/pasting.",
"states": {
"Navigation": {
"description": "This parallel state (can be active in parallel to others) represents the Navigation aspects of the app",
"states": {
"Screen": {
"description": "This is a compound state meaning it can have children.\n\nThe path for this state is\n*WebAssessment.Navigation.Screen*",
"initial": "Gender",
"states": {
"Gender": {
"description": "type: ScreenType.SingleSelect,\n\n choices: [\n 'Male',\n 'Female',\n 'Non-binary',\n 'Other',\n 'Prefer not to say',",
"on": {
"next": {
"target": "Age",
"description": "click this to execute a \"next\" transition"
}
}
},
"Age": {
"description": "type: ScreenType.SingleNumericInput,\n\n content: 'What’s your age?',",
"on": {
"next": {
"target": "HealthIssues"
},
"getStuck": {
"target": "stuck",
"description": "demo only"
}
}
},
"HealthIssues": {
"description": "type: ScreenType.MultiSelect,\n\n body: [\n 'Do you have any other health issues?',\n 'It’s common for people with IBS to have multiple related conditions.',\n ],\n\n choices: [\n 'Anxiety/Stress',\n 'Depression',\n 'Smoking',\n 'Menopause',\n 'Chronic pain',\n 'Sleep problems',\n 'Skin Issues',\n 'Obesity',\n 'More/Other',\n 'None',",
"on": {
"next": {
"target": "EducationGutBrain"
}
}
},
"EducationGutBrain": {
"description": "type: ScreenType.Presentation,\n\n\n content: [\n\n {\n type: 'text',\n content: 'Nerva helps you manage your IBS with hypnotherapy by ‘fixing’ the miscommunication between your gut and brain, without restrictive diets like Low FODMAP.',\n },\n\n { type: 'image', src: images.chartHypnoVsFodmapSimplified },\n \n{\n type: 'text',\n content: 'Let’s start by learning more about you, so we can assess whether Nerva might help you, too.',\n },\n\n ],",
"on": {
"next": {
"target": "Doctor"
}
}
},
"Doctor": {
"description": "type: ScreenType.SingleSelect,\n\n body: ['A growing number of healthcare professionals are recommending Nerva.',\n 'Were you recommended by a healthcare professional (a doctor, a nutritionist, etc.)?'],\n\n choices: [\n 'Yes',\n 'No',\n ],",
"on": {
"next": [
{
"target": "NoDoctorReferral",
"cond": "no"
},
{
"target": "HowLong"
}
]
}
},
"NoDoctorReferral": {
"description": "type: ScreenType.Presentation,\n\n content: [\n\n { type: 'heading', content: 'That’s okay!' },\n\n { type: 'image', src: images.doctor, altText: 'doctor' },\n\n {\n type: 'coloredBox',\n body: 'While you don’t need a referral to use Nerva, it’s important not to self-diagnose IBS. Other conditions can have similar symptoms.',\n backgroundColor: 'surface.muted',\n },\n\n ],",
"on": {
"next": {
"target": "HowLong"
}
}
},
"HowLong": {
"description": "type: ScreenType.SingleSelect,\n\n body: ['How long have you had IBS and wanted to feel better?'],\n\n choices: [\n '0-6 months',\n '6-12 months',\n '1-5 years',\n '5+ years',\n ],",
"on": {
"next": {
"target": "WhyNerva"
}
}
},
"WhyNerva": {
"description": "type: ScreenType.SingleSelect,\n \n\n body: ['Why are you interested in feeling better with Nerva right now?'],\n\n choices: [\n 'My symptoms have become worse',\n 'My current solutions aren’t working',\n 'I’m sick of being restricted',\n 'I’m ready to start now',\n ],",
"on": {
"next": {
"target": "Triggers"
}
}
},
"Triggers": {
"description": "type: ScreenType.MultiSelect,\n\n body: ['It’s great to have you starting with us. We know everyone’s triggers are unique. What are yours?'],\n\n choices: [\n 'Food',\n 'Anxiety/Stress',\n 'Medication',\n 'Exercise',\n 'Other',\n 'I’m not sure',\n ],",
"on": {
"next": {
"target": "EducationSignals"
}
}
},
"EducationSignals": {
"description": "type: ScreenType.Presentation,\n\n\n footnotes: ['[1] https://link.springer.com/article/10.1007%2Fs11894-014-0379-z'],\n \ncontent: [\n\n {\n type: 'text',\n content: 'Although people have different triggers, one of the key underlying reasons for the triggers is a miscommunication between the gut and the brain.',\n },\n\n {\n type: 'text',\n content: 'If you’ve ever experienced ‘butterflies in your stomach’ when nervous, then you have felt the effects of the gut-brain connection.',\n },\n\n { type: 'image', src: images.gutBrainConnection, altText: 'Diagram of the Gut-Brain Connection' },\n {\n type: 'text',\n content: 'For people with IBS, this miscommunication can lead to diarrhea, constipation and pain when reacting to common triggers like stress and food.',\n },\n\n ],",
"on": {
"next": {
"target": "Symptoms"
}
}
},
"Symptoms": {
"description": "type: ScreenType.MultiSelect,\n\n body: ['What physical symptoms do you normally experience during a flare-up?'],\n \n\n choices: [\n 'Diarrhea',\n 'Constipation',\n 'Abdominal pain',\n 'Bloating',\n { label: 'Gas/Wind', value: 'Wind' },\n 'Nausea',\n 'More/Other',\n ],",
"on": {
"next": [
{
"target": "Classify",
"cond": "Diarrhea"
},
{
"target": "Classify",
"cond": "Constipation"
},
{
"target": "ImpactLife"
}
]
}
},
"ImpactLife": {
"description": "type: ScreenType.MultiSelect,\n\n\n body: ['How do these symptoms impact your life?'],\n\n\n choices: [\n { label: 'Physically uncomfortable', value: 'Feeling physically uncomfortable' },\n 'Can’t eat foods I love',\n 'Nervous to socialize',\n 'Worrying about travel',\n 'Struggle with work',\n 'More/Other',\n ],",
"on": {
"next": {
"target": "HowOften"
}
}
},
"Classify": {
"description": "type: ScreenType.Classify,\n l\n\n body: [\n 'Does that mean you would classify yourself as having ',\n ' or do you have another subtype of IBS?',\n ],\n\n choices: [\n IbsClassification.IBS_D,\n IbsClassification.IBS_M,\n IbsClassification.IBS_C,\n 'I’m not sure',\n ],",
"on": {
"next": {
"target": "ImpactLife"
}
}
},
"HowOften": {
"description": "type: ScreenType.SingleSelect,\n\n\n body: ['How often does this happen?'],\n\n choices: [\n 'Multiple times a day',\n 'Daily',\n 'Multiple times a week',\n 'Weekly',\n 'Monthly',\n ],",
"on": {
"next": {
"target": "IbsCosts"
}
}
},
"IbsCosts": {
"description": "type: ScreenType.MultiSelect,\n\n\n body: ['What financial costs have you had to deal with?'],\n \n\n choices: [\n {\n label: 'Many doctor visits',\n value: 'Multiple doctor visits',\n },\n 'Expensive food',\n {\n label: 'Higher insurance premiums',\n value: 'Increased insurance premiums',\n },\n 'Missing work',\n 'Ineffective treatments',\n 'More/Other',\n 'None',\n ],",
"on": {
"next": {
"target": "Treatments"
}
}
},
"Treatments": {
"description": "type: ScreenType.MultiSelect,\n\n\n body: ['Finding the right solution can be difficult; some people end up feeling like they\\'ve tried everything. What options have you tried?'],\n\n choices: [\n 'Avoiding certain foods',\n {\n label: 'Medication',\n value: 'Drugs',\n },\n 'Peppermint',\n 'Probiotics',\n 'Hypnotherapy',\n 'Supplements',\n 'More/Other',\n ],",
"on": {
"next": {
"target": "DidTreatmentsWork"
}
}
},
"DidTreatmentsWork": {
"description": "type: ScreenType.SingleSelect,\n\n body: ['Did they work?'],\n choices: [\n 'Yes',\n 'Sort of',\n 'No',\n ],",
"on": {
"next": {
"target": "EducationUnderlyingReason"
}
}
},
"EducationUnderlyingReason": {
"description": "type: ScreenType.Presentation,\n\n content: [\n {\n type: 'text',\n content: 'Most IBS solutions don’t target underlying IBS triggers, such as the miscommunication between the gut and the brain.',\n },\n {\n type: 'text',\n content: 'Hypnotherapy is different.',\n },\n { type: 'image', src: images.chartHypnoVsFodmap },\n {\n type: 'text',\n content: 'Clinical studies have shown that hypnotherapy helps you to \\'fix\\' this miscommunication, and manage symptoms without having to change what you eat.',\n },\n ],",
"on": {
"next": {
"target": "DoCertainFoodsTrigger"
}
}
},
"DoCertainFoodsTrigger": {
"description": "type: ScreenType.SingleSelect,\n\n\n body: ['Many IBS patients have flare-ups after eating certain foods. Do you know why this happens?'],\n\n choices: [\n 'Yes',\n { value: 'Sort of', label: 'Somewhat' },\n { value: 'Not sure', label: 'No' },\n ],",
"on": {
"next": {
"target": "EducationCertainFoods"
}
}
},
"EducationCertainFoods": {
"description": "type: ScreenType.Presentation,\n\n\n content: [\n {\n type: 'text',\n content: `This is because high FODMAP foods rapidly ferment in the gut which causes the intestines to expand.\n This process actually happens to everyone who digests FODMAPs, not just IBS sufferers.`,\n },\n {\n type: 'text',\n content: `The difference is that people with IBS often have oversensitive nerves in their gut,\n which react far earlier to this expansion and tell the brain to cause symptoms like pain, diarrhea, constipation and more.`,\n },\n { type: 'image', src: images.bowlMixed },\n {\n type: 'text',\n content: `So you can either try to avoid eating foods which trigger these nerves,\n or change how the brain responds to the messages from the nerves via hypnotherapy.`,\n },\n ],",
"on": {
"next": {
"target": "DoesStress"
}
}
},
"DoesStress": {
"description": "type: ScreenType.SingleSelect,\n \n\n body: ['Another common IBS trigger is stress and worry. Do you know why this happens?'],\n\n choices: [\n 'Yes',\n { value: 'Sort of', label: 'Somewhat' },\n { value: 'Not sure', label: 'No' },\n ],",
"on": {
"next": {
"target": "EducationStressCycle"
}
}
},
"EducationStressCycle": {
"description": "type: ScreenType.Presentation,\n\n\n content: [\n {\n type: 'text',\n content: `Stress and anxiety is a clear example of the gut-brain connection stuck in an unhelpful\n loop that is hard to break without help.`,\n },\n { type: 'image', src: images.stressCycle },\n {\n type: 'text',\n content: `It’s why we include relaxation, education readings, and breathing tools in Nerva\n to help you break the cycle and return to a calm & worry free state.`,\n },\n ],",
"on": {
"next": {
"target": "HowLikeToFeel"
}
}
},
"HowLikeToFeel": {
"description": "type: ScreenType.MultiSelect,\n\n\n body: ['Great - now we know a little bit about your current experience with IBS and how it’s impacting your life.',\n 'Imagine yourself in 6 weeks time, how would you like to feel?'],\n\n choices: [\n 'Physically comfortable',\n 'In control of my life',\n 'Calm & worry free',\n 'Healthier in my body',\n 'Confident in myself',\n 'More/Other',\n ],",
"on": {
"next": {
"target": "IfFreeFromIbs"
}
}
},
"IfFreeFromIbs": {
"description": "type: ScreenType.MultiSelect,\n\n\n body: ['What would you want to do if you were free from the control of IBS?'],\n\n\n choices: [\n 'Eat the foods I love',\n { label: 'Enjoy social life/relationships', value: 'Enjoy my social life and relationships' },\n 'Sleep better',\n 'Travel with confidence',\n 'Be more present at work',\n 'More/Other',\n ],",
"on": {
"next": {
"target": "AreYouConfident"
}
}
},
"AreYouConfident": {
"description": "type: ScreenType.SingleSelect,\n\n body: ['How confident are you in achieving this with your current approach?'],\n\n choices: [\n 'Confident',\n { value: 'Not confident', label: 'Somewhat confident' },\n 'Not at all',\n ],",
"on": {
"next": {
"target": "LiveFreeNow"
}
}
},
"LiveFreeNow": {
"description": "type: ScreenType.SingleSelect,\n \n\n body: ['How important is achieving this to you?'],\n choices: [\n 'Very important',\n 'Important',\n 'Not important',\n ],",
"on": {
"next": {
"target": "Auth"
}
}
},
"Auth": {
"description": "type: ScreenType.Auth,",
"on": {
"next": [
{
"target": "AlreadyPaidDownloadApp",
"cond": "loginAndAlreadyPaid"
},
{
"target": "Results",
"cond": "login"
},
{
"target": "LoadingResults",
"cond": "signup"
},
{
"target": "Results"
}
]
}
},
"Results": {
"description": "type: ScreenType.Results,\n\n title: 'The results are in',\n\n summaryBoxHeading: 'Nerva is likely to work\\nfor you!',\n\n summaryBoxBody: '89% of people similar to you had calmed their IBS after finishing the program.',\n\n body: [\n 'Your survey results suggest that you are a great candidate for gut-directed hypnotherapy. Congratulations!',\n 'While Nerva isn\\'t a cure for IBS, it is a life-changing management tool for a lot of people.',\n 'We\\'ve helped over 80,000 people better manage IBS with Nerva.',\n ],",
"on": {
"next": {
"target": "ProgramStructure"
}
}
},
"LoadingResults": {
"description": "type: ScreenType.LoadingResults,\n\n\n reviewer: {\n name: 'Allie',\n image: images.pattyG,\n testimonial: `“I thought I had tried everything to manage my IBS symptoms but then I found Nerva.\n Now, my mind and gut feel calmer than ever and I finally feel in control of my own health. I am so so grateful.”`,\n date: 'February 23, 2022',\n },",
"on": {
"next": {
"target": "Results"
}
}
},
"AlreadyPaidDownloadApp": {
"description": "type: ScreenType.DownloadApp,\n\n\n title: ['You already have access!'],\n\n body: ['Use the same email and password you signed up with:'],\n\n\n```",
"type": "final"
},
"ProgramStructure": {
"description": "type: ScreenType.ProgramStructure,\n\n\n title: 'Here’s your\\nNerva program',\n\n coreProgramWeekTitles: [\n 'Starting your Nerva Journey',\n 'GDH & and how it works',\n 'Gut, Brain, & Nervous System',\n 'Breaking the Symptom Cycle',\n 'The Science Behind Gut Functions',\n '“Normal” gut function',\n ],\n\n postProgramTitle: 'Post 6-week program',\n\n postProgramContent: 'Unlock your ongoing IBS management plan',",
"on": {
"next": {
"target": "ProgramBenefits"
}
}
},
"ProgramBenefits": {
"description": "type: ScreenType.ProgramBenefits,\n\n\n title: 'You’ll start with a\\n6-week IBS course',\n\n content: [\n {\n type: 'text',\n content: `In the first six weeks of the Nerva program, you’ll focus on learning techniques that can \n help you manage your symptoms and live well with IBS.`,\n },\n { type: 'image', src: images.coreProgram },\n {\n type: 'text',\n content: `Our structured course of gut-directed hypnotherapy and psychoeducation will help you \n learn to self-manage your IBS and improve communications between your gut and brain.`,\n },\n {\n type: 'text',\n content: `You might notice some sessions repeat - this is deliberate and designed to help the \n suggestions and learnings sink in.`,\n },\n ],\n\n highlightCard: 'On average, people who complete six-weeks of Nerva report improving their IBS management skills by 50%.',",
"on": {
"next": {
"target": "CoreProgramExperience"
}
}
},
"CoreProgramExperience": {
"description": "type: ScreenType.Screenshot,\n\n image: images.nervaScreenshotNew,\n\n imageAltText: 'Nerva core program experience',\n\n listTitle: 'During the first 6 weeks you’ll:',\n\n listItems: [\n { image: icons.volume, desc: 'Listen to daily hypnotherapy' },\n { image: icons.books, desc: 'Read IBS psychoeducation' },\n { image: icons.air, desc: 'Follow breathing exercises' },\n { image: icons.graph, desc: 'Track your progress' },\n ],",
"on": {
"next": {
"target": "ProgramSupport"
}
}
},
"ProgramSupport": {
"description": "type: ScreenType.Presentation,\n\n title: 'Unlock long-term\\nIBS support',\n\n content: [\n {\n type: 'text',\n content: `After the first six weeks of Nerva, you’ll have full access to our ongoing support program to \n help you maintain and improve your learnings long-term.`,\n },\n { type: 'image', src: images.ongoingSupport },\n {\n type: 'text',\n content: `At this stage of your journey, you will unlock your customizable IBS support tools,\n have access to new hypnotherapy sessions as they’re released,\n and access an on-demand IBS flare-up toolkit.`,\n },\n ],",
"on": {
"next": {
"target": "MaintenanceExperience"
}
}
},
"MaintenanceExperience": {
"description": "type: ScreenType.Screenshot,\n\n image: images.maintenanceScreenshot,\n\n imageAltText: 'Nerva maintenance program experience',\n\n listTitle: 'After the first 6 weeks you’ll:',\n\n listItems: [\n { image: icons.graph, desc: 'Maintain and/or improve results' },\n { image: icons.wheel, desc: 'Customize your program' },\n { image: icons.lockUnlocked, desc: 'Unlock your flare-up toolkit' },\n { image: icons.refresh, desc: 'Access ongoing support' },\n ],",
"on": {
"next": {
"target": "TrialExplanation"
}
}
},
"TrialExplanation": {
"description": "type: ScreenType.TrialExplanation,\n\n title: 'What to expect',\n\n body: ['New to hypnotherapy? Our trial lets you experience the program before you commit.'],\n\n image: images.nervaProgramNew7DayTrial,\n\n imageAltText: 'Nerva payment timeline',",
"on": {
"next": {
"target": "WorksBest"
}
}
},
"WorksBest": {
"description": "type: ScreenType.WorksBest,\n\n title: 'What works best for you?',\n\n body: [\n 'We know that trying something new can be scary.',\n 'Your health is our priority and money shouldn’t stop you from exploring something that could change your life!',\n ],\n\n description: ['It costs us {{trialPrice}} to provide a {{trialPeriod}}-day trial.',\n 'Please choose the amount below that best supports your circumstance.'],\n\n primaryButtonTitle: 'Continue',\n },",
"on": {
"next": {
"target": "Payment"
}
}
},
"Payment": {
"description": "type: ScreenType.Payment,",
"on": {
"next": [
{
"target": "FinishAccount",
"cond": "newUser"
},
{
"target": "DownloadApp",
"cond": "existingUser"
},
{
"target": "DownloadApp"
}
]
}
},
"DownloadApp": {
"description": "type: ScreenType.DownloadApp,\n\n title: ['You’re all set!', 'Access your program now'],",
"type": "final"
},
"FinishAccount": {
"description": "type: ScreenType.FinishAccount,\n \n subtitle: 'Fill in these last few details and you’re ready to go!',\n\n primaryButtonTitle: 'Continue',",
"on": {
"next": {
"target": "DownloadApp"
}
}
},
"stuck": {
"description": "- notice that this state only has a line pointing into it (enter) \n- and no arrow pointing out of it (exit). \n- If you end up in this state, you can never escape!"
},
"impossible state": {
"description": "there is no way this state can ever happen"
}
},
"on": {
"reset": {
"target": ".Gender"
}
}
}
},
"type": "parallel"
},
"Automatic Flow": {
"description": "**ignore this for now** - it's here to make testing easier. Transitions triggered here will also be triggered in other actors.",
"initial": "keep clicking",
"states": {
"keep clicking": {
"on": {
"next": {
"target": "keep clicking",
"internal": false
}
}
}
},
"on": {
"reset": {
"target": ".keep clicking"
}
}
}
},
"type": "parallel"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment