Could you please advise a solution for the following:
e.g. we have a checkout form with many delivery options, each requires different details, such as:
- in store - requires only
storeId - delivery office - requires
cityIdandofficeId - courier - requires
addressfields (street, building)
example of state:
...,
delivery: {
type: 'inStore',
details: { storeId: 1 }
}
or
...,
delivery: {
type: 'courier',
details: {
address: {
street: '12 Ave',
...,
}
}
}
As soon as only one of the above options could be checked I tried to use a radio button component to define a delivery type
Also, it is possible to render different components based on delivery type (e.g. via switch-case) and fill different delivery.___ fields.
But if we fill the form for the inStore option and then switch to e.g. courier option the storeId property still is in the state. So how could this switch be properly handled (to left only required properties based on the selected delivery type)