O1SoftwareNetwork / repairs

0 stars 6 forks source link

Clean up navigation buttons on signup form #16

Open jaygabe opened 1 week ago

jaygabe commented 1 week ago

We currently have the code posted below handling the navigation from one form state to another. There has got to be a cleaner, more efficient way to do this. Feel free to think it through and give it a shot. If you have any questions, just comment below.

enum AppointmentFormState {
    DIAGNOSIS,
    SCHEDULE,
    CONTACT
}

const [appointmentFormState, setAppointmentFormState] = useState<AppointmentFormState>(AppointmentFormState.DIAGNOSIS);

    const handleForward = () => (appointmentFormState <= AppointmentFormState.SCHEDULE) && setAppointmentFormState(appointmentFormState + 1);
    const handleBack = () => (appointmentFormState >= AppointmentFormState.SCHEDULE) && setAppointmentFormState(appointmentFormState - 1);
    const backButtonRequired = appointmentFormState >= AppointmentFormState.SCHEDULE;
    const nextOrSubmit = appointmentFormState <= AppointmentFormState.SCHEDULE;
{backButtonRequired && <Button color="primary" onClick={handleBack}>Go Back</Button>}
                    {nextOrSubmit ? 
                        <Button color="primary" onClick={handleForward}>Next</Button> :
                        <Button color="primary" type="submit">Submit</Button>
                    }