diff --git a/src/components/Form/Form.jsx b/src/components/Form/Form.jsx
index e4cd3a5..656d323 100644
--- a/src/components/Form/Form.jsx
+++ b/src/components/Form/Form.jsx
@@ -3,8 +3,8 @@ import Hero2 from '../sections/Hero2';
import SectionHeader from '../sections/partials/SectionHeader';
import { useForm } from 'react-hook-form';
-import {supabase} from '../../utils/supabase';
-import toast , {Toaster} from 'react-hot-toast';
+import { supabase } from '../../utils/supabase';
+import toast, { Toaster } from 'react-hot-toast';
import branches from "../../branches.json"
const Form = () => {
@@ -14,10 +14,9 @@ const Form = () => {
};
const [mode, setMode] = useState(false)
- const [usnInput,setUsnInput] = useState("")
+ 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}$/
@@ -25,102 +24,99 @@ const Form = () => {
const changeMode = (e) => {
console.log(e.target.value)
if (e.target.value === "1") setMode(false)
+ else if (e.target.value === "Select year") {
+ console.log("Select Year")
+ setDisplay(false)
+ }
else setMode(true)
setDisplay(true)
}
- const { register, handleSubmit,reset } = useForm()
+ const { register, handleSubmit, reset } = useForm()
const onSubmit = async (dataa) => {
- const {usn,whatsapp,branch, year} = dataa
- if(branch === "Select Branch") {
- toast.error("Enter Your Branch",{duration:2500})
+ const { usn, whatsapp, branch, year } = dataa
+ if (branch === "Select Branch") {
+ toast.error("Enter Your Branch", { duration: 2500 })
return
}
- if(year === "Select year") {
- toast.error("Enter Your Year",{duration:2500})
+ if (year === "Select year") {
+ toast.error("Enter Your Year", { duration: 2500 })
return
}
- if(!phoneRegex.test(whatsapp)){
- toast.error("Please enter a valid 10 digit phone no.",{duration:3000})
+ if (!phoneRegex.test(whatsapp)) {
+ toast.error("Please enter a valid 10 digit phone no.", { duration: 3000 })
return
}
- 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'
- }
- else if(dataa.year === '2')
- {
- if(!usnRegex.test(usn)){
- toast.error("Please enter a valid USN",{duration:2500})
+ if (dataa.year === '1') {
+ if (!admnRegex.test(dataa.regno)) {
+ toast.error("Please Enter correct Admission No.", { duration: 2500 })
return
}
- db='Second';
- regValue=dataa.usn;
- regField='USN';
}
- else{
- if(!usnRegex.test(usn)){
- toast.error("Please enter a valid USN",{duration:3500})
+ else {
+ if (!usnRegex.test(usn)) {
+ toast.error("Please enter a valid USN", { duration: 3500 })
return
}
- db='Third'
- regValue=dataa.usn;
- regField='USN';
+
}
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});
+ const data = await fetch("https://h1so0s7f9i.execute-api.us-east-1.amazonaws.com/Prod/", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify(dataa)
+ })
+ const res = await data.json()
+ console.log(res)
toast.dismiss(savingToast)
- if(!error){
- toast.success(`Data Saved ! Good Luck for the Test`,{duration:3000});
+ if (!res) {
+ toast.success(`Data Saved ! Good Luck for the Test`, { duration: 3000 });
}
- else if (error.code ==="23505"){
+ else if (res?.code === "23505") {
toast.error("Uh-oh!! It seems you have already registered before")
}
else
- toast.error(`Uh-Oh! ${error.details}`,{duration:3000});
- reset()
- setDisplay(false);
+ toast.error(`Uh-Oh! ${res?.details}`, { duration: 3000 });
setUsnInput("")
setRegInput("")
+ reset()
+ setDisplay(false);
+
}
return (
<>
-
+