diff --git a/src/components/Form/Form.jsx b/src/components/Form/Form.jsx index 5b4f731..04c592a 100644 --- a/src/components/Form/Form.jsx +++ b/src/components/Form/Form.jsx @@ -14,10 +14,13 @@ const Form = () => { }; const [mode, setMode] = useState(false) + const [usnInput,setUsnInput] = useState("") + const [regInput, setRegInput] = useState("") const [display, setDisplay] = useState(false) const [inputValue, setInputValue] = useState(''); const usnRegex = /^1DS\w{7}$/ const phoneRegex = /^\d{10}$/ + const admnRegex = /^23UGDS\w{4}$/ const changeMode = (e) => { console.log(e.target.value) @@ -28,10 +31,6 @@ const Form = () => { const { register, handleSubmit,reset } = useForm() - const handleInputChange = (e) => { - setInputValue(e.target.value.toUpperCase()); - }; - const onSubmit = async (dataa) => { const {usn,whatsapp} = dataa if(!phoneRegex.test(whatsapp)){ @@ -40,6 +39,10 @@ const Form = () => { } let db,regValue,regField; if(dataa.year === '1'){ + if(!admnRegex.test(dataa.regno)){ + toast.error("Please Enter correct Admission No.", {duration:2500}) + return + } db='First'; regValue=dataa.regno; regField='RegNo' @@ -64,14 +67,20 @@ const Form = () => { regValue=dataa.usn; regField='USN'; } - toast.loading("Saving Data",{duration:1500}); + let savingToast = toast.loading("Saving Data"); const {data,error} = await supabase.from(`${db}_Years`).insert({[regField]:regValue,Name:dataa.name,Branch:dataa.branch,Bio:dataa.bio,Year:dataa.year,Email:dataa.email,WhatsApp_No:dataa.whatsapp}); - if(!error) - toast.success(`Data Saved ! Good Luck for the Test`,{duration:3000}); - else if (error.code ==="23505") toast.error("Uh-oh!! It seems you have already registered before") + toast.dismiss(savingToast) + if(!error){ + toast.success(`Data Saved ! Good Luck for the Test`,{duration:3000}); + } + else if (error.code ==="23505"){ + toast.error("Uh-oh!! It seems you have already registered before") + } else toast.error(`Uh-Oh! ${error.details}`,{duration:3000}); reset() + setUsnInput("") + setRegInput("") } return ( @@ -96,18 +105,7 @@ const Form = () => {
@@ -125,12 +123,12 @@ const Form = () => { {mode === true ? (<>
- + setUsnInput(e.target.value.toUpperCase())} value={usnInput}/>
) : (<>
- - + + setRegInput(e.target.value.toUpperCase())} value={regInput} />
)})}
diff --git a/src/components/layout/Header.js b/src/components/layout/Header.js index eccacf4..5e29c4e 100644 --- a/src/components/layout/Header.js +++ b/src/components/layout/Header.js @@ -82,9 +82,9 @@ const Header = ({ <>
-
+
We are recruiting !!  - Click here + Register here