I am trying to implement a multi-step wizard using a state machine and am unsure how to handle some configurations. To illustrate this I put together an example of a wizard that helps you prepare a dish. Assuming the following example what would be the appropriate way to model this form/wizard behavior as a state machine?
Step 1 - Dish
- pick a dish from ["Salad", "Pasta", "Pizza"]
Step 2 - Preparation Method
- pick a preparation method from ["Oven", "Microwave"]
Step 3 - Ingredients
- add and select ingredients in a form, depending on the dish and the preparation method the form will look different
// ingredients based on previous selections
("Pizza", "Oven") => ["tomato", "cheese", "pepperoni"]
("Pizza", "Microwave") => ["cheese", "pepperoni", "mushrooms"]
("Pasta", "Oven") => ["parmesan", "butter", "creme fraiche"]
("Pasta", "Microwave") => ["parmesan", "creme fraiche"]
("Salad") => ["cucumber", "feta cheese", "lettuce"]
I tried to simplify the problem as much as possible. Here are my questions:
In step 3 I want to show a form with various fields of different types. The selections in step 1 and 2 define which fields will be shown in the form in step 3. What is the appropriate way to specify this form configuration?
Step 2 should be skipped if the selected dish from step 1 is "Salad". What is the appropriate way to declare this?
I plan to implement this using xstate as the project I'm working on is written in react.
Edit: I updated the example in reaction to Martins answer. (see my comment on his answer)
Edit 2: I updated the example in reaction to Davids answer. (see my comment on his answer)