๋ณต์กํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์ํดzod ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํ๋ค.
SignupPage.jsx ,css ๋ฅผ ์์ฑํ๋ค.
import { useForm } from "react-hook-form";
import "./SignupPage.css";
import user from "../../assets/user.webp";
const SignupPage = () => {
// const [profilePic, setProfilePic] = useState(null);
const {
register,
handleSubmit,
formState: { errors },
watch,
} = useForm();
const submitData = (formData) => console.log(formData);
//console.log(profilePic);
return (
<section className="align_center form_page">
<form
className="authentication_form signup_form"
onSubmit={handleSubmit(submitData)}
>
<h2>ํ์๊ฐ์
ํผ</h2>
<div className="image_input_section">
<div className="image_preview">
<img src={user} id="file-ip-1-preview" />
</div>
<label htmlFor="file-ip-1" className="image_label">
์ด๋ฏธ์ง ์
๋ก๋
</label>
<input type="file" id="file-ip-1" className="image_input" />
</div>
{/* Form Inputs */}
<div className="form_inputs signup_form_input">
<div>
<label htmlFor="name">Name</label>
<input
id="name"
className="form_text_input"
type="text"
placeholder="์ด๋ฆ ์
๋ ฅ..."
{...register("name", {
required: "์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์.",
minLength: { value: 2, message: "์ด๋ฆ์ ์ต์ 2์ ์ด์" },
maxLength: { value: 10, message: "์ด๋ฆ์ ์ต๋ 10์ ์ดํ" },
})}
/>
{errors.name && (
<em className="form_error">{errors.name.message}</em>
)}
</div>
<div>
<label htmlFor="email">Email</label>
<input
id="email"
className="form_text_input"
type="email"
placeholder="์ด๋ฉ์ผ ์
๋ ฅ..."
{...register("email", {
required: "์ด๋ฉ์ผ์ ์
๋ ฅํด์ฃผ์ธ์.",
pattern: {
value: /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/,
message: "์ฌ๋ฐ๋ฅธ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํ์ธ์.",
},
})}
/>
{errors.email && (
<em className="form_error">{errors.email.message}</em>
)}
</div>
<div>
<label htmlFor="password">Password</label>
<input
id="password"
className="form_text_input"
type="password"
placeholder="ํจ์ค์๋ ์
๋ ฅ..."
{...register("password", {
required: "ํจ์ค์๋๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.",
minLength: { value: 4, message: "ํจ์ค์๋๋ ์ต์ 4์ ์ด์." },
})}
/>
{errors.password && (
<em className="form_error">{errors.password.message}</em>
)}
</div>
<div>
<label htmlFor="cpassword">Confirm Password</label>
<input
id="cpassword"
className="form_text_input"
type="password"
placeholder="ํจ์ค์๋ ํ์ธ ์
๋ ฅ..."
{...register("confirmPassword", {
required: true,
validate: (value) => {
if (watch("password") != value) {
return "ํจ์ค์๋๊ฐ ๋ง์ง ์์ต๋๋ค.";
}
},
})}
/>
{errors.confirmPassword && (
<em className="form_error">{errors.confirmPassword.message}</em>
)}
</div>
<div className="signup_textares_section">
<label htmlFor="address">Delivery Address</label>
<textarea
id="address"
className="input_textarea"
placeholder="๋ฐฐ์ก์ฃผ์ ์
๋ ฅ..."
{...register("deliveryAddress", {
required: "๋ฐฐ์ก์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.",
minLength: { value: 10, message: "๋ฐฐ์ก์ฃผ์๋ ์ต์ 10์ ์ด์." },
})}
/>
{errors.deliveryAddress && (
<em className="form_error">{errors.deliveryAddress.message}</em>
)}
</div>
</div>
<button className="search_button form_submit" type="submit">
Submit
</button>
</form>
</section>
);
};
export default SignupPage;