Skip to content

Commit 92c1e60

Browse files
Akash(tiy-form): Form completed. (#16)
* akash(tiy-form): Halfway Done * akash(tiy-form): Clear Button Added * akash(tiy-form): Tailwind issues faced. * suvajit(tiy-form): tailwindcss fixed * akash(tiy-form):Form Completed --------- Co-authored-by: SUVAJITKARMAKAR <suvajit2001k@gmail.com>
1 parent e566517 commit 92c1e60

File tree

4 files changed

+203
-4
lines changed

4 files changed

+203
-4
lines changed

src/App.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// COMPONENTS
22
import Greeting from "./components/Basics/Greeting";
3-
// import CounterEffect from "./components/Hooks/useEffectHook/Counter1";
43
import Counter from "./components/Hooks/useStateHook/Counter";
4+
//import CounterEffect from "./components/Hooks/useEffectHook/Counter1";
55
import Form from "./project/Form";
66
import ThemeToggler from "./project/ThemeToggler";
77
import HandlingForm from "./components/Hooks/useRefHook/HandlingForm";
88

99
// TRY IT YOURSELF COMPONENTS
10-
// import ModifiedCounter from "./tryityourself/tushit/ModifiedCounter";
10+
import FormDetails from "./tryityourself/Akash/FormDetails";
1111

1212
const App = () => {
13-
return <HandlingForm />;
13+
return <FormDetails />;
1414
};
1515

16-
export default App;
16+
export default App;

src/index.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
@import "tailwindcss";
22
@import "./components/Hooks/useRefHook/HandlingForm.style.css";
3+
@import "./tryityourself/Akash/FormDetails.style.css";
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
import React, { useState, useRef, useEffect } from "react";
2+
3+
const FormDetails = () => {
4+
const [formVal, setFormVal] = useState({
5+
name: "",
6+
email: "",
7+
phone: "",
8+
password: "",
9+
confirmPassword: "",
10+
});
11+
12+
//CLEAR FORM DATA
13+
const clearForm = () => {
14+
setFormVal({
15+
name: "",
16+
email: "",
17+
phone: "",
18+
password: "",
19+
confirmPassword: "",
20+
});
21+
};
22+
23+
//useRef HOOKS BLOCK
24+
const guideMeName = useRef();
25+
const guideMeEmail = useRef();
26+
const guideMePhone = useRef();
27+
const guideMePassword = useRef();
28+
const guideMeConfirmPassword = useRef();
29+
30+
//OnClick GUIDER BLOCK
31+
const handleGuideMeName = () => {
32+
guideMeName.current.focus();
33+
console.log(guideMeName.current);
34+
};
35+
const handleGuideMeEmail = () => {
36+
guideMeEmail.current.focus();
37+
console.log(guideMeEmail.current);
38+
};
39+
const handleGuideMePhone = () => {
40+
guideMePhone.current.focus();
41+
console.log(guideMePhone.current);
42+
};
43+
const handleGuideMePassword = () => {
44+
guideMePassword.current.focus();
45+
console.log(guideMePassword.current);
46+
};
47+
const handleGuideMeConfirmPassword = () => {
48+
guideMeConfirmPassword.current.focus();
49+
console.log(guideMeConfirmPassword.current);
50+
};
51+
52+
//STATE HANDLER FUNCTION
53+
const handleChange = (e) => {
54+
setFormVal({
55+
...formVal,
56+
[e.target.name]: e.target.value,
57+
});
58+
console.log(formVal.name);
59+
console.log(formVal.email);
60+
console.log(formVal.phone);
61+
console.log(formVal.password);
62+
};
63+
64+
//SUBMISSION HANDLER FUNCTION
65+
const [isLoading, setIsLoading] = useState(false);
66+
const [isDisabled, setIsDisabled] = useState(false);
67+
68+
// PERFORM PASSWORD VGALIDATION FIRST : TOOK HELP OF AI
69+
const handleSubmit = (e) => {
70+
e.preventDefault();
71+
if (formVal.password !== formVal.confirmPassword) {
72+
alert("PASSWORD IS CRYING IN THE CORNER!");
73+
return clearForm(); // Stop submission if validation fails
74+
}
75+
76+
// Proceed with form submission
77+
console.log(formVal.name);
78+
console.log(formVal.email);
79+
console.log(formVal.phone);
80+
console.log(formVal.password);
81+
setIsLoading(true);
82+
setIsDisabled(true);
83+
setTimeout(() => {
84+
setIsLoading(false);
85+
setIsDisabled(false);
86+
}, 1000);
87+
clearForm();
88+
};
89+
90+
return (
91+
<>
92+
<div className="background">
93+
<form className="form">
94+
<h1 className="text-3xl text-[#B3FF00] font-semibold tracking-[.125em] pb-5 text-center relative">
95+
Register<span className="text-purple-500">!</span>
96+
</h1>
97+
<label className="labell" onClick={handleGuideMeName}>
98+
Full Name :
99+
</label>
100+
<input
101+
ref={guideMeName}
102+
type="text"
103+
placeholder="Name Here"
104+
name="name"
105+
value={formVal.name}
106+
onChange={handleChange}
107+
className="field"
108+
/>
109+
<br />
110+
<label className="labell" onClick={handleGuideMeEmail}>
111+
Email :
112+
</label>
113+
<input
114+
ref={guideMeEmail}
115+
type="text"
116+
placeholder="Email Here"
117+
name="email"
118+
value={formVal.email}
119+
onChange={handleChange}
120+
className="field"
121+
/>
122+
<br />
123+
<label className="labell" onClick={handleGuideMePhone}>
124+
Phone :
125+
</label>
126+
<input
127+
ref={guideMePhone}
128+
type="tel"
129+
placeholder="Phone Here"
130+
name="phone"
131+
value={formVal.phone}
132+
onChange={handleChange}
133+
className="field"
134+
/>
135+
<br />
136+
<label className="labell" onClick={handleGuideMePassword}>
137+
Password :
138+
</label>
139+
<input
140+
ref={guideMePassword}
141+
type="password"
142+
placeholder="Password Here"
143+
name="password"
144+
value={formVal.password}
145+
onChange={handleChange}
146+
className="field"
147+
/>
148+
<br />
149+
<label className="labell" onClick={handleGuideMeConfirmPassword}>
150+
Confirm Password :
151+
</label>
152+
<input
153+
ref={guideMeConfirmPassword}
154+
type="password"
155+
placeholder="Confirm Password"
156+
name="confirmPassword"
157+
value={formVal.confirmPassword}
158+
onChange={handleChange}
159+
className="field"
160+
/>
161+
<br />
162+
<div className="btnrow">
163+
<button
164+
className="btn"
165+
disabled={isDisabled}
166+
onClick={handleSubmit}
167+
>
168+
{isLoading ? "Submitting" : "Submit"}
169+
</button>
170+
<button className="btn" onClick={clearForm}>
171+
Clear
172+
</button>
173+
</div>
174+
</form>
175+
</div>
176+
</>
177+
);
178+
};
179+
180+
export default FormDetails;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.field {
2+
@apply border border-purple-500 text-white p-1 rounded-md;
3+
}
4+
.labell {
5+
@apply text-white hover:cursor-pointer;
6+
}
7+
.btn {
8+
@apply flex justify-center items-center border-1 rounded-md bg-white text-black hover:cursor-pointer hover:bg-[#B3FF00] hover:text-purple-500 font-semibold p-2 w-full;
9+
}
10+
.form {
11+
@apply flex flex-col gap-0.25 max-w-80 max-h-screen bg-black p-10 rounded-3xl border-x border-[#B3FF00];
12+
}
13+
.background {
14+
@apply flex justify-center items-center h-screen bg-[#101010];
15+
}
16+
.btnrow {
17+
@apply flex gap-1;
18+
}

0 commit comments

Comments
 (0)