App.jsx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
import React, { useState } from "react"; import StepWizard from "react-step-wizard"; import { Form, Button, Container } from "react-bootstrap"; const BasicInfo = ({ nextStep }) => { const [name, setName] = useState(""); const [age, setAge] = useState(""); const handleNext = () => { if (name && age) nextStep(); else alert("Please fill all fields!"); }; return ( <Container> <h2>Basic Information</h2> <Form> <Form.Group className="mb-3"> <Form.Label>Name</Form.Label> <Form.Control type="text" placeholder="Enter your name" value={name} onChange={(e) => setName(e.target.value)} /> </Form.Group> <Form.Group className="mb-3"> <Form.Label>Age</Form.Label> <Form.Control type="number" placeholder="Enter your age" value={age} onChange={(e) => setAge(e.target.value)} /> </Form.Group> <Button variant="primary" onClick={handleNext}> Next </Button> </Form> </Container> ); }; const ContactInfo = ({ previousStep, nextStep }) => { const [email, setEmail] = useState(""); const [phone, setPhone] = useState(""); const handleNext = () => { if (email && phone) nextStep(); else alert("Please fill all fields!"); }; return ( <Container> <h2>Contact Information</h2> <Form> <Form.Group className="mb-3"> <Form.Label>Email</Form.Label> <Form.Control type="email" placeholder="Enter your email" value={email} onChange={(e) => setEmail(e.target.value)} /> </Form.Group> <Form.Group className="mb-3"> <Form.Label>Phone</Form.Label> <Form.Control type="text" placeholder="Enter your phone number" value={phone} onChange={(e) => setPhone(e.target.value)} /> </Form.Group> <Button variant="secondary" onClick={previousStep} className="me-2"> Back </Button> <Button variant="primary" onClick={handleNext}> Next </Button> </Form> </Container> ); }; const TermsConditions = ({ previousStep, goToStep }) => { const [agreed, setAgreed] = useState(false); const handleFinish = () => { if (agreed) { alert("Registration Completed!"); goToStep(1); // Restart to the first step } else { alert("Please agree to the terms and conditions!"); } }; return ( <Container> <h2>Terms and Conditions</h2> <Form> <Form.Group className="mb-3"> <Form.Check type="checkbox" label="I agree to the terms and conditions" checked={agreed} onChange={(e) => setAgreed(e.target.checked)} /> </Form.Group> <Button variant="secondary" onClick={previousStep} className="me-2"> Back </Button> <Button variant="success" onClick={handleFinish}> Finish </Button> </Form> </Container> ); }; export default function RegistrationForm() { return ( <Container className="mt-4"> <h1 className="text-center mb-4">Registration Form</h1> <StepWizard> <BasicInfo /> <ContactInfo /> <TermsConditions /> </StepWizard> </Container> ); } |