Demo
Demo
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
function SignupForm() {
// let countryDemo={
// countryid:"1",
// countryFullName:"India"
// }
// const [countryData,setCountryData]=useState([])
// const [stateData,setStateData]=useState([]);
const form = useForm({
defaultValues: {
first_name: "",
last_name: "",
email: "",
contact: "",
user_name: "",
password: "",
country_id: "",
},
resolver: zodResolver(FormSchema),
});
const handleCustomerForm = (values) => {
console.log(values);
};
return (
<div className="w-full lg:grid lg:min-h-[600px] lg:grid-cols-2 xl:min-h-
[800px]">
<div className="flex justify-center items-center">
<img src="/public/register.jpg" alt="img" className="h-auto w-auto" />
</div>
<div className=" flex flex-col justify-center items-center">
<h1 className="text-3xl py-4 font-bold">Signup</h1>
<div className="rounded-md bg-white px-12 py-4 ">
<Form {...form}>
<form
onSubmit={form.handleSubmit(handleCustomerForm)}
className="w-96 mx-auto space-y-4"
>
<FormField
control={form.control}
name="user_name"
render={({ field }) => (
<FormItem>
<FormLabel>Username</FormLabel>
<FormControl>
<Input placeholder="Enter your username" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="first_name"
render={({ field }) => (
<FormItem>
<FormLabel>FirstName</FormLabel>
<FormControl>
<Input placeholder="Enter your first name" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="last_name"
render={({ field }) => (
<FormItem>
<FormLabel>Last Name</FormLabel>
<FormControl>
<Input placeholder="Enter your last name" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Email</FormLabel>
<FormControl>
<Input
placeholder="Enter your email address"
type="email"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="phone_number"
render={({ field }) => (
<FormItem>
<FormLabel>Contact Number</FormLabel>
<FormControl>
<Input
placeholder="Enter your contact number"
type="tel"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Password</FormLabel>
<FormControl>
<Input
placeholder="Enter your password"
type="password"
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="country_id"
render={({ field }) => (
<FormItem {...field}>
<FormLabel>Country Name</FormLabel>
<FormControl>
<Select>
<SelectTrigger className="text-gray-500">
<SelectValue placeholder="Select an Option" />
</SelectTrigger>
<SelectContent>
{countryData &&
Object.values(countryData).map((country) => (
<SelectItem key={country.countryId}
value={country.countryId}>
{country.countryFullName}
</SelectItem>
))}
</SelectContent>
</Select>
</FormControl>
<FormMessage />
</FormItem>
)}
></FormField>
<FormField
control={form.control}
name="state"
render={({ field }) => (
<FormItem {...field}>
<FormLabel>State Name</FormLabel>
<FormControl>
<Select >
<SelectTrigger className="text-gray-500">
<SelectValue placeholder="Select an Option" />
</SelectTrigger>
<SelectContent>
{stateData &&
Object.values(stateData).map((state) => (
<SelectItem key={state.countryId}
value={state.countryId}>
{state.countryFullName}
</SelectItem>
))}
</SelectContent>
</Select>
</FormControl>
<FormMessage />
</FormItem>
)}
></FormField>
<Button className="w-full" type="submit">
Submit
</Button>
</form>
</Form>
</div>
</div>
</div>
);
}
// const initialValues = {
// first_name: "",
// last_name: "",
// email: "",
// phone_number: "",
// password: "",
// confirm_password: "",
// user_name: "",
// };
// function Signup() {
// const [states, setStates] = useState([]);
// const country = Country.getAllCountries();
// const token = localStorage.getItem('authToken')
// const handleCountry = (event) => {
// const isoCode = event.target.value;
// setStates(State.getStatesOfCountry(isoCode));
// event.preventDefault();
// }
// return (
// <>
// <div className=" p-7 flex justify-center"
// style={{ backgroundColor: "#d4d4d4", minHeight: "100vh" }}>
// <div className=" text-gray-800 text-xl">
// <form className="bg-gray-100 p-6 rounded-lg shadow-md">
// <div className=" grid grid-cols-2 gap-2">
// <div className="m-3 flex items-center">
// <div className=" flex flex-col">
// <label htmlFor="name" className="m-1">
// First Name :
// </label>
// <input
// type="name"
// autoComplete="off"
// name="first_name"
// id="first_name"
// placeholder="first_name"
// // value={values.first_name}
// // onChange={handleChange}
// // onBlur={handleBlur}
// className=" bg-slate-400 flex-1 w-full rounded-xl px-4 py-2
focus:outline-none focus:shadow-outline"
// />
// {/* {errors.first_name && touched.first_name ? (
// <p className=" text-red-600 text-sm">{errors.first_name}</p>
// ) : null} */}
// </div>
// </div>
// </select>
// </div>
// </div>
// <div className="m-3 flex items-center">
// <div className="flex flex-col">
// <label htmlFor="number" className="m-1 ">
// Phone number :
// </label>
// <input
// type="numbers"
// autoComplete="off"
// name="phone_number"
// id="phone_number"
// placeholder="phone_number"
// // value={values.phone_number}
// // onChange={handleChange}
// // onBlur={handleBlur}
// className=" bg-slate-400 flex-1 rounded-xl px-4 py-2
focus:outline-none focus:shadow-outline "
// />
// {/* {errors.phone_number && touched.phone_number ? (
// <p className="text-red-600
text-sm">{errors.phone_number}</p>
// ) : null} */}
// </div>
// </div>