diff --git a/client/package-lock.json b/client/package-lock.json index f264be2..8acedd3 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -19,7 +19,8 @@ "react-icons": "^5.3.0", "react-phone-number-input": "^3.4.5", "react-router-dom": "^6.26.1", - "react-toastify": "^10.0.5" + "react-toastify": "^10.0.5", + "socket.io-client": "^4.7.5" }, "devDependencies": { "@eslint/js": "^9.9.0", @@ -2019,6 +2020,11 @@ "win32" ] }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==" + }, "node_modules/@swc/helpers": { "version": "0.5.12", "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.12.tgz", @@ -2988,7 +2994,6 @@ "version": "4.3.6", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", - "dev": true, "license": "MIT", "dependencies": { "ms": "2.1.2" @@ -3157,6 +3162,26 @@ "node": ">= 0.8" } }, + "node_modules/engine.io-client": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.4.tgz", + "integrity": "sha512-GeZeeRjpD2qf49cZQ0Wvh/8NJNfeXkXXcoGh+F77oEAgo9gUHwT1fCRxSNU+YEEaysOJTnsFHmM5oAcPy4ntvQ==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.17.1", + "xmlhttprequest-ssl": "~2.0.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/es-abstract": { "version": "1.23.3", "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.23.3.tgz", @@ -5179,7 +5204,6 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true, "license": "MIT" }, "node_modules/mz": { @@ -6481,6 +6505,32 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/socket.io-client": { + "version": "4.7.5", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.5.tgz", + "integrity": "sha512-sJ/tqHOCe7Z50JCBCXrsY3I2k03iOiUe+tj1OmKeD2lXPiGH/RUCdTZFoqVyN7l1MnpIzPrGtLcijffmeouNlQ==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.2", + "engine.io-client": "~6.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -7444,6 +7494,34 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xmlhttprequest-ssl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz", + "integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/client/package.json b/client/package.json index 2d5ad33..b8cdafb 100644 --- a/client/package.json +++ b/client/package.json @@ -25,7 +25,8 @@ "react-icons": "^5.3.0", "react-phone-number-input": "^3.4.5", "react-router-dom": "^6.26.1", - "react-toastify": "^10.0.5" + "react-toastify": "^10.0.5", + "socket.io-client": "^4.7.5" }, "devDependencies": { "@eslint/js": "^9.9.0", diff --git a/client/src/assets/bgimg.jpeg b/client/src/assets/bgimg.jpeg new file mode 100644 index 0000000..847179b Binary files /dev/null and b/client/src/assets/bgimg.jpeg differ diff --git a/client/src/components/Buyer/Login.jsx b/client/src/components/Buyer/Login.jsx index 78abf41..40e073b 100644 --- a/client/src/components/Buyer/Login.jsx +++ b/client/src/components/Buyer/Login.jsx @@ -3,6 +3,9 @@ import { getAuth, signInWithEmailAndPassword } from 'firebase/auth'; import { app } from '../../../firebase'; import { useNavigate } from 'react-router-dom'; import styles from './signup.module.css'; // Import the CSS Module +import Navi from './Navi' +import { toast, ToastContainer } from 'react-toastify'; +import img from '../../assets/bgimg.jpeg'; const auth = getAuth(app); @@ -15,12 +18,12 @@ const Login = () => { e.preventDefault(); try { await signInWithEmailAndPassword(auth, email, password).then(() => { - alert('success'); + toast.success('Welcome'); navigate('/buyer'); }); } catch (error) { // Handle errors here - alert(`Error: ${error.message}`); + toast.error('Error Loging in:', error); } }; @@ -30,8 +33,9 @@ const Login = () => { <>
+
-
{/* Header content */}
+
@@ -64,6 +68,7 @@ const Login = () => {
+
); diff --git a/client/src/components/Buyer/Navi.jsx b/client/src/components/Buyer/Navi.jsx new file mode 100644 index 0000000..38e9dc9 --- /dev/null +++ b/client/src/components/Buyer/Navi.jsx @@ -0,0 +1,26 @@ +import React from 'react' +import styles from './signup.module.css'; +import { FaHome } from "react-icons/fa"; +import { useNavigate } from 'react-router-dom'; + +export default function Navi() { + const navigate = useNavigate(); + return( +
+
navigate('/')}> +
+

Agri

+
+
+

Connect

+
+
+
+ +
+
+ ) +} diff --git a/client/src/components/Buyer/Signup.jsx b/client/src/components/Buyer/Signup.jsx index 0009fa8..ce78633 100644 --- a/client/src/components/Buyer/Signup.jsx +++ b/client/src/components/Buyer/Signup.jsx @@ -1,13 +1,17 @@ import { useState } from 'react'; import { auth } from '../../../firebase'; -import { useNavigate } from 'react-router-dom'; +import { Navigate, useNavigate } from 'react-router-dom'; +import Navi from './Navi' import styles from './signup.module.css'; // Import the CSS Module +import { FcGoogle } from "react-icons/fc"; +import { toast, ToastContainer } from 'react-toastify'; +import img from '../../assets/bgimg.jpeg'; import { createUserWithEmailAndPassword, GoogleAuthProvider, signInWithPopup, } from 'firebase/auth'; -import Navbar from '../LandingPage/Navbar'; + const googleProvider = new GoogleAuthProvider(); @@ -17,20 +21,23 @@ export default function Signup() { const navigate = useNavigate(); const signupWithGoogle = () => { - signInWithPopup(auth, googleProvider).then(() => alert('success')); + signInWithPopup(auth, googleProvider).then((e) => { + toast.success('Welcome') + navigate('/buyer'); + }); }; const create = async (e) => { e.preventDefault(); try { await createUserWithEmailAndPassword(auth, email, password).then(() => { - alert('success'); + toast.success('Welcome'); navigate('/buyer'); const user = auth.currentUser; console.log(user); }); } catch (error) { - alert(`Error: ${error.message}`); + toast.error('Error signing in:', error); } }; @@ -38,9 +45,10 @@ export default function Signup() { return (
+
- +
@@ -64,7 +72,8 @@ export default function Signup() { />
@@ -72,13 +81,16 @@ export default function Signup() {

Already have an account?{' '} - navigate('/login')} className={styles.a1}>Login + navigate('/login')} className={styles.a1}>Login

+ Are you a Farmer?{' '} + navigate('/fsignup')} className={styles.a1}>Click Here

+
); } diff --git a/client/src/components/Buyer/signup.module.css b/client/src/components/Buyer/signup.module.css index 565c338..285362f 100644 --- a/client/src/components/Buyer/signup.module.css +++ b/client/src/components/Buyer/signup.module.css @@ -6,6 +6,7 @@ width: 100%; height: 100vh; color: white; + overflow: hidden; } .headervg{ margin: 0; @@ -17,18 +18,22 @@ .heading h1{ font-size: 35px; } -.bgimg{ +.bgimg>img{ margin: 0px; padding: 0px; - height: inherit; - background-image: url("https://th.bing.com/th/id/R.77dfcc4d3db9d58d263ddfb9424aa74d?rik=9dwG7dUFc8aI9A&riu=http%3a%2f%2fs.wsj.net%2fpublic%2fresources%2fimages%2fBN-BB446_ifarm_P_20140111221144.jpg&ehk=fcYS84qt1uyS6xk2qf7no1vx09cNSjswk8cR4%2bLOSs4%3d&risl=&pid=ImgRaw&r=0"); - background-repeat: no-repeat; + height: 98.5vh; + width: 100%; + /* background-image: url("https://th.bing.com/th/id/R.77dfcc4d3db9d58d263ddfb9424aa74d?rik=9dwG7dUFc8aI9A&riu=http%3a%2f%2fs.wsj.net%2fpublic%2fresources%2fimages%2fBN-BB446_ifarm_P_20140111221144.jpg&ehk=fcYS84qt1uyS6xk2qf7no1vx09cNSjswk8cR4%2bLOSs4%3d&risl=&pid=ImgRaw&r=0"); */ + /* background-repeat: no-repeat; background-size: cover; - background-position:center; + background-position:center; */ + position:absolute; + z-index: -1; + overflow: hidden; } .fade{ - height: 100%; - background-color: rgba(0, 0, 0, 0.5); + height: 98.5vh; + background-color: rgba(0, 0, 0, 0.329); } .boxvg{ margin:5rem; @@ -105,18 +110,77 @@ select>option{ box-shadow:none ; border: none; font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; - font-size: 22px; + font-size: 25px; cursor: pointer; text-decoration: underline; + display: flex; + gap: 10px; + position: relative; + left: 2vw; } -#recaptcha-container{ +.google>button>span{ + font-size: 20px; + position: relative; + bottom: 5px; +} +.captcha{ position: relative; left: 2vw; + bottom: 3vh; } .i2{ width: 22vw; color: black; - + +} +.navi{ + display: flex; + color: white; + margin: 10px; + padding: 10px; + gap:70vw; +} +.first{ + color: chartreuse; +} +.second{ + color: white; +} +.brand{ + display: flex; + cursor: pointer; + font-size: 40px; +} +.su>select{ + background-color: transparent; + color: white; + outline: none; + font-size: 20px; +} +.bt3{ + margin: 10px; + font-size: 30px; + display: flex; + gap: 10px; + color:white; +} +.bt3:hover{ + color: chartreuse; + scale: 1.04; +} +.bt3>h2{ + position: relative; + bottom: 7px; +} +.i3{ + width: 22vw; + margin-right: 10px; + color: black; +} +.i4{ + width: 22vw; + margin-left: 2vw; + color: black; + background-color: transparent; } - diff --git a/client/src/components/Farmer/FLogin.jsx b/client/src/components/Farmer/FLogin.jsx index 9098a9b..b86204b 100644 --- a/client/src/components/Farmer/FLogin.jsx +++ b/client/src/components/Farmer/FLogin.jsx @@ -3,17 +3,37 @@ import 'react-phone-number-input/style.css'; import PhoneInput from 'react-phone-number-input'; import { useNavigate } from 'react-router-dom'; import styles from '../Buyer/signup.module.css'; // Import the CSS Module +import Navi from '../Buyer/Navi' +import { toast, ToastContainer } from 'react-toastify'; +import img from '../../assets/bgimg.jpeg'; +import { getAuth } from 'firebase/auth'; +import { app } from '../../../firebase'; +const auth =getAuth(app) const FLogin = () => { const [phno, setphno] = useState(''); const navigate = useNavigate(); + const loginUser = async (e) => { + e.preventDefault(); + try { + await signInWithPhoneNumber(auth,phno).then(() => { + toast.success('Welcome'); + navigate('/farmerdashboard'); + }); + } catch (error) { + // Handle errors here + toast.error('Error Loging in:', error); + } + }; + return ( <>
+
-
{/* Header content */}
+
@@ -25,12 +45,11 @@ const FLogin = () => { value={phno} onChange={setphno} placeholder="Phone Number" - className={styles.i2} - style={{ backgroundColor: 'transparent' }} + className={styles.i3} />
- +

Don't have an account?{' '} @@ -40,6 +59,7 @@ const FLogin = () => {

+
); diff --git a/client/src/components/Farmer/FSignup.jsx b/client/src/components/Farmer/FSignup.jsx index 264a71f..4e9cbbe 100644 --- a/client/src/components/Farmer/FSignup.jsx +++ b/client/src/components/Farmer/FSignup.jsx @@ -1,6 +1,7 @@ import { useState } from 'react'; import 'react-phone-number-input/style.css'; import PhoneInput from 'react-phone-number-input'; +import { toast, ToastContainer } from 'react-toastify'; import { getAuth, signInWithPhoneNumber, @@ -9,28 +10,40 @@ import { import { app } from '../../../firebase'; import { useNavigate } from 'react-router-dom'; import styles from '../Buyer/signup.module.css'; // Import the CSS Module +import Navi from '../Buyer/Navi'; +import img from '../../assets/bgimg.jpeg'; const auth = getAuth(app); const FSignup = () => { const [phno, setphno] = useState(''); const navigate = useNavigate(); + const [otp,setOtp]=useState(""); + const [flag,setflag]=useState(false) + const [flagg,setflagg]=useState(false) + const [confirmobj,setconfirmobj]=useState(""); const getOtp = async (e) => { e.preventDefault(); if (phno === '' || phno === undefined) { - alert('INVALID PHONE NUMBER'); + toast.error('INVALID PHONE NUMBER'); } - try { - const response = await Recaptcha(phno); - console.log(response); - } catch (error) { - alert(`Error: ${error.message}`); + else{ + try { + const response = await Recaptcha(phno); + console.log(response); + setconfirmobj(response) + setflag(true) + } catch (error) { + setflagg(false) + toast.error(`Error: ${error.message}`); + } + console.log(phno); } - console.log(phno); }; function Recaptcha(phno) { + setflagg(true) const recaptchaVerifier = new RecaptchaVerifier( auth, 'recaptcha-container', @@ -40,39 +53,66 @@ const FSignup = () => { return signInWithPhoneNumber(auth, phno, recaptchaVerifier); } + const verifyotp=async(e)=>{ + e.preventDefault(); + console.log(otp); + if(otp ==="" || opt===null) return; + try{ + await confirmobj.confirm(otp) + //navigate here + }catch (error) { + toast.error(`Error: ${error.message}`); + } + } + return ( <>
+
-
{/* Header content */}
+

Create Account

-
+
-
+ className={styles.i4} + />

+
+
+ setOtp(e.target.value)} + placeholder="Enter Otp" + className={styles.i2} + style={{ backgroundColor: 'transparent',borderBottom:'2px solid gray'}} + />



+
+ +
+

Already have an account?{' '} - navigate('/FLogin')} className={styles.a1}>Login + navigate('/FLogin')} className={styles.a1}>Login

+ Are you a Buyer?{' '} + navigate('/signup')} className={styles.a1}>Click Here

-
+
+
); diff --git a/client/src/components/LandingPage/AgriConnect.jsx b/client/src/components/LandingPage/AgriConnect.jsx index 361774c..fa028d7 100644 --- a/client/src/components/LandingPage/AgriConnect.jsx +++ b/client/src/components/LandingPage/AgriConnect.jsx @@ -1,4 +1,4 @@ -import 'bootstrap/dist/css/bootstrap.min.css'; +// import 'bootstrap/dist/css/bootstrap.min.css'; import './Landing.css' import img from '../../assets/buyerPic2.jpeg' import img1 from '../../assets/farmerPic.jpeg' diff --git a/client/src/components/Negotiate/Chat.jsx b/client/src/components/Negotiate/Chat.jsx index 3b14c88..5429e7c 100644 --- a/client/src/components/Negotiate/Chat.jsx +++ b/client/src/components/Negotiate/Chat.jsx @@ -1,7 +1,42 @@ import './chat.css'; -import { useState, useRef, useEffect } from 'react'; +import io from 'socket.io-client' +import { useState, useRef, useEffect, useContext } from 'react'; +import { addDoc, collection, doc, getDoc } from 'firebase/firestore'; +import {db} from '../../../firebase' +import { AuthContext } from '../context/Authcontext'; export default function Chat() { + //current user context + const { currentUser } = useContext(AuthContext); + const [userType, setUserType] = useState("buyers"); //change depending upon the type of user(buyer or farmer) + const [contacts, setContacts] = useState({}); + // console.log(currentUser); + console.log(contacts); + //testing values, to be removed later + const roomID = 'room1'; + const SERVER_PORT = import.meta.env.VITE_SERVER_PORT; + + const [socket, setSocket]= useState(null); + + useEffect(()=>{ + //establish new socket connection + const newSocket = io.connect(`http://localhost:${SERVER_PORT}`); + setSocket(newSocket); + + //monitor messages + newSocket.on("recieve-message", (recieved_message)=>{ + setMessages(prevMessages => [...prevMessages, recieved_message]); + }) + + //get all contacts when u load the page + getContacts(currentUser.uid, userType).then((result)=>{ + setContacts(result); + }); + return () => { + newSocket.disconnect(); + }; + },[]) + // State for the input text and messages const [text, setText] = useState(''); const [messages, setMessages] = useState([]); @@ -15,8 +50,25 @@ export default function Chat() { }, [messages]); // Handle the click event to add a new message - const handleClick = () => { + const handleClick = async () => { + //send message to server through websocket if (text.trim()) { + + if (socket) { + socket.emit("send-message", { message: text}); + } + + //add message to database + try { + await addDoc(collection(db, 'chats', roomID, 'messages'), { + message: text, + timeStamp: new Date(), + user: currentUser.uid, + }); + } catch (error) { + console.error("Error uploading message:", error); + } + setMessages([...messages, text]); setText(''); } @@ -56,3 +108,24 @@ export default function Chat() {
); } + +const getContacts = async (userID, userType)=>{ + try { + const userDocRef = doc(db, userType, userID); + const userDoc = await getDoc(userDocRef); + if (userDoc.exists()) { + const userData = userDoc.data(); + return userData.Contacts + // const contacts = userData.contacts || []; + + // console.log("Contacts:", contacts); + // return contacts; + } else { + console.log("No such user!"); + return []; + } + } catch (error) { + console.error("Error fetching contacts:", error); + return []; + } +} diff --git a/client/src/components/ProfileSetup/Profilesetup.jsx b/client/src/components/ProfileSetup/Profilesetup.jsx index 64a5be1..e9fbab9 100644 --- a/client/src/components/ProfileSetup/Profilesetup.jsx +++ b/client/src/components/ProfileSetup/Profilesetup.jsx @@ -1,11 +1,11 @@ -import { useState,useEffect } from 'react'; -import './profilesetup.css'; +import { useState, useEffect } from 'react'; +import styles from './profilesetup.module.css'; // Import the CSS module import { db } from '../../../firebase'; import { addDoc, collection } from 'firebase/firestore'; export default function Profilesetup() { - const port = import.meta.env.VITE_PORT + const port = import.meta.env.VITE_PORT; const [imagePreview1, setImagePreview1] = useState(null); const [imagePreview2, setImagePreview2] = useState(null); @@ -34,16 +34,16 @@ export default function Profilesetup() { useEffect(() => { fetch(`http://localhost:${port}/states`) - .then(response => response.json()) - .then(data => setStates(data)); + .then((response) => response.json()) + .then((data) => setStates(data)); }, [port]); const handleStateChange = (e) => { const state = e.target.value; setSelectedState(state); fetch(`http://localhost:${port}/districts/${state}`) - .then(response => response.json()) - .then(data => { + .then((response) => response.json()) + .then((data) => { setDistricts(data); setSubdistricts([]); setAreas([]); @@ -54,8 +54,8 @@ export default function Profilesetup() { const district = e.target.value; setSelectedDistrict(district); fetch(`http://localhost:${port}/subdistricts/${selectedState}/${district}`) - .then(response => response.json()) - .then(data => { + .then((response) => response.json()) + .then((data) => { setSubdistricts(data); setAreas([]); }); @@ -64,9 +64,11 @@ export default function Profilesetup() { const handleSubdistrictChange = (e) => { const subdistrict = e.target.value; setSelectedSubdistrict(subdistrict); - fetch(`http://localhost:${port}/areas/${selectedState}/${selectedDistrict}/${subdistrict}`) - .then(response => response.json()) - .then(data => setAreas(data)); + fetch( + `http://localhost:${port}/areas/${selectedState}/${selectedDistrict}/${subdistrict}` + ) + .then((response) => response.json()) + .then((data) => setAreas(data)); }; const userCollectionRef = collection(db, 'farmerdata'); @@ -115,19 +117,24 @@ export default function Profilesetup() { // Validate form fields const validateForm = () => { let tempErrors = {}; - if (!firstname) tempErrors.firstname = "First name is required."; - if (!lastname) tempErrors.lastname = "Last name is required."; - if (!gender) tempErrors.gender = "Gender is required."; - if (!dob || new Date(dob) >= new Date('2003-01-01')) tempErrors.dob = "DOB must be before 2002."; - if (!address) tempErrors.address = "Address is required."; - if (!pincode || pincode.length !== 6) tempErrors.pincode = "Pincode must be 6 digits."; - if (!photoidtype) tempErrors.photoidtype = "Photo ID type is required."; - if (!photoidnumber) tempErrors.photoidnumber = "Photo ID number is required."; - if (!ifsc) tempErrors.ifsc = "IFSC code is required."; - if (!accountnumber) tempErrors.accountnumber = "Account number is required."; - if (!bankname) tempErrors.bankname = "Bank name is required."; - if (!branchname) tempErrors.branchname = "Branch name is required."; - if (!branchaddress) tempErrors.branchaddress = "Branch address is required."; + if (!firstname) tempErrors.firstname = 'First name is required.'; + if (!lastname) tempErrors.lastname = 'Last name is required.'; + if (!gender) tempErrors.gender = 'Gender is required.'; + if (!dob || new Date(dob) >= new Date('2003-01-01')) + tempErrors.dob = 'DOB must be before 2002.'; + if (!address) tempErrors.address = 'Address is required.'; + if (!pincode || pincode.length !== 6) + tempErrors.pincode = 'Pincode must be 6 digits.'; + if (!photoidtype) tempErrors.photoidtype = 'Photo ID type is required.'; + if (!photoidnumber) + tempErrors.photoidnumber = 'Photo ID number is required.'; + if (!ifsc) tempErrors.ifsc = 'IFSC code is required.'; + if (!accountnumber) + tempErrors.accountnumber = 'Account number is required.'; + if (!bankname) tempErrors.bankname = 'Bank name is required.'; + if (!branchname) tempErrors.branchname = 'Branch name is required.'; + if (!branchaddress) + tempErrors.branchaddress = 'Branch address is required.'; return Object.keys(tempErrors).length === 0; }; @@ -135,9 +142,9 @@ export default function Profilesetup() { // Handle form submission const handleSubmit = async (e) => { e.preventDefault(); - + if (!validateForm()) { - alert("Please fill all required fields correctly."); + alert('Please fill all required fields correctly.'); return; } @@ -172,191 +179,466 @@ export default function Profilesetup() { }; return ( - <> -
-
-
-
-
+
+ {/* */} +
+
-

Personal Details

-
-
-
- - setFirstname(e.target.value)} /> -
- -
- - setLastname(e.target.value)} /> -
- -
- - -
- -
- - setDob(e.target.value)} /> -
- -
- - -
- -
- - - {districts.length > 0 && ( - - )} - - {subdistricts.length > 0 && ( - - )} - - {areas.length > 0 && ( - - )} -
- -
- - setPincode(e.target.value)} /> -
- -
- - -
+

Personal Details

+ +
+
+
+
+
+ +
+ setFirstname(e.target.value)} + /> +
+ +
+
+ +
+ setLastname(e.target.value)} + /> +
+
-
- - setPhotoidnumber(e.target.value)} /> -
+
+
+
+ +
+ +
+ +
+
+ +
+ setDob(e.target.value)} + /> +
+
-

Bank Details

+
+
+ +
+ +
-
- - setIfsc(e.target.value)} /> -
+
+ + + {districts.length > 0 && ( +
+ +
+ )} + + {subdistricts.length > 0 && ( +
+ +
+ )} + + {areas.length > 0 && ( +
+ +
+ )} +
-
- - setAccountname(e.target.value)} /> -
+
+
+ +
+ setPincode(e.target.value)} + /> +
-
- - setBankname(e.target.value)} /> +
+
+
+ +
+ +
+ +
+
+ +
+ setPhotoidnumber(e.target.value)} + /> +
+
-
- - setAccountnumber(e.target.value)} /> -
+

Bank Details

+ +
+
+
+
+ +
+ setIfsc(e.target.value)} + /> +
+ +
+
+ +
+ setAccountname(e.target.value)} + /> +
+
-
- - setBranchname(e.target.value)} /> -
+
+
+
+ +
+ setBankname(e.target.value)} + /> +
+ +
+
+ +
+ setAccountnumber(e.target.value)} + /> +
+
-
- - setBranchaddress(e.target.value)} /> +
+
+
+ +
+ setBranchname(e.target.value)} + /> +
+ +
+
+ +
+ setBranchaddress(e.target.value)} + /> +
+
-

Upload Documents

- -
- - -
+

Upload Documents

+ +
+
+
+ +
+ +
- {imagePreview1 && ( -
- Preview - + {imagePreview1 && ( +
+ Preview + +
+ )} + +
+
+ +
+
- )} -
- - + {imagePreview2 && ( +
+ Preview + +
+ )}
- {imagePreview2 && ( -
- Preview - -
- )} - - +
- +
); } diff --git a/client/src/components/ProfileSetup/profilesetup.css b/client/src/components/ProfileSetup/profilesetup.css deleted file mode 100644 index 1c0378a..0000000 --- a/client/src/components/ProfileSetup/profilesetup.css +++ /dev/null @@ -1,94 +0,0 @@ -/* src/PersonalDetailsForm.css */ -.form-container { - max-width: 900px; - margin: 0 auto; - padding: 20px; - background-color: #f1f1f1; - border-radius: 8px; - } - - .form-container h2 { - text-align: center; - color: #4CAF50; - } - - .form-group { - display: flex; - justify-content: space-between; - margin-bottom: 15px; - } - - .form-group label { - flex-basis: 30%; - font-weight: bold; - color: #333; - margin-right: 10px; - } - - .form-group input, - .form-group select, - .form-group textarea { - flex-basis: 70%; - padding: 8px; - font-size: 14px; - border: 1px solid #ccc; - border-radius: 4px; - } - - .form-group textarea { - height: 80px; - } - - .form-group select { - padding: 7px; - } - - button[type="submit"] { - width: 100%; - background-color: #4CAF50; - color: white; - padding: 10px; - border: none; - border-radius: 4px; - font-size: 16px; - cursor: pointer; - } - - button[type="submit"]:hover { - background-color: #45a049; - } - - .required:after { - content: " *"; - color: red; - } - - @media (max-width: 768px) { - .form-group { - flex-direction: column; - } - - .form-group label { - margin-bottom: 5px; - } - } - - - .asads{ - display:flex; - - } - - .asa{ - display:flex; - } - - - *{ - font-family: "Teko", sans-serif; - font-optical-sizing: auto; - font-weight: 300; - font-style: normal; - } - - \ No newline at end of file diff --git a/client/src/components/ProfileSetup/profilesetup.module.css b/client/src/components/ProfileSetup/profilesetup.module.css new file mode 100644 index 0000000..c0b7c76 --- /dev/null +++ b/client/src/components/ProfileSetup/profilesetup.module.css @@ -0,0 +1,392 @@ +.form-container { + max-width: 60%; + margin: 0 auto; + padding: 20px; + background-color: #f1f1f1; + border-radius: 8px; +} +.pfp{ + display: flex; + gap: 3vw; +} +.form-container h2 { + text-align: center; + color: #4CAF50; +} + +.needs-validation{ + width:60%; +} + +.form-group { + display: flex; + justify-content: space-between; + margin-bottom: 15px; +} + +.form-group label { + flex-basis: 30%; + font-weight: bold; + color: #333; + margin-right: 10px; +} + +.form-group input, +.form-group select, +.form-group textarea { + flex-basis: 70%; + padding: 8px; + font-size: 14px; + border: 1px solid #ccc; + border-radius: 4px; +} + +.form-group textarea { + height: 80px; +} + +.form-group select { + padding: 7px; +} + +button[type="submit"] { + width: 80%; + background-color: #4CAF50; + color: white; + padding: 10px; + border: none; + border-radius: 4px; + font-size: 16px; + cursor: pointer; + +} + +button[type="submit"]:hover { + background-color: #45a049; +} + +.required:after { + content: " *"; + color: red; +} + +@media (max-width: 768px) { + .form-group { + flex-direction: column; + } + + .form-group label { + margin-bottom: 5px; + } +} + + +.asads{ + display:flex; + +} + +.asa{ + display:flex; +} + + +*{ + /* font-family: "Teko", sans-serif; +font-optical-sizing: auto; +font-weight: 300; +font-style: normal; */ +} + +.pdtext{ + font-size: xx-large; + text-decoration: underline; + margin-bottom: 20px; + margin-top:10px; +} +.litem>nav{ + height:10vh; + width: 200px; + background-color:#45a049; + margin-top:10px; + padding: 20px; + text-align: center; + border-radius: 15px; + font-weight: 650; +} + +.cc{ + display:flex; + justify-content: space-around; + +} + +.Firstline{ + width:75%; + display:flex; + justify-content: flex-start; + + +} + +.secondline{ + display:flex; + justify-content: flex-start; +} + +.pln{ + display:flex; + justify-content: flex-start; +} + +.bfl1{ +display:flex; +justify-content: flex-start; +} + +.bfl2{ +display:flex; +justify-content: flex-start; + +} + +.bfl3{ +display:flex; +justify-content: flex-start; +} + +.ss{ +display:flex; +} + +.pd{ +width:1200px; + +margin-left:80px; +} + +.fname111 input{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; + +} + +.lname111 input{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; + +} + +.lname111{ +margin-left:10%; +} + +.dob{ +margin-left:10%; +} + +.gender select{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.dob input{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.selst{ +width: 200px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.seld{ +width: 200px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} +.selsd{ +width: 200px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} +.sela{ + +width: 200px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.pincode input{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.pit select{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} +.pinn{ +padding-left:8%; +} +.pinn input{ +width: 400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.add textarea{ +width: 75%; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.sa{ +display:flex; +} + +.sa111{ +margin-left:3%; +} +.sd111{ +margin-left:3%; +} +.sss111{ +margin-left:3%; +} + +.bs{ +margin-left:6%; + +} + +.ifsc input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} +.accname input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.bn input{ +width:400px;padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.accname{ +margin-left:8%; +} + +.bba{ +margin-left:8%; +} + +.baccn{ +margin-left:8%; +} + +.baccn input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; + +} + +.bbn input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.bba input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.img111 input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.img112 input{ +width:400px; +padding: 12px 20px; +margin: 8px 0; +box-sizing: border-box; +border: 2px solid green; +border-radius: 4px; +} + +.pig{ + +margin-left:6%; +} \ No newline at end of file diff --git a/client/src/main.jsx b/client/src/main.jsx index fd4b8b1..b840120 100644 --- a/client/src/main.jsx +++ b/client/src/main.jsx @@ -11,9 +11,9 @@ import FSignup from "./components/Farmer/FSignup"; import Chat from "./components/Negotiate/Chat"; import NotFoundPage from './components/NotFoundPage'; import FDashboard from './components/Farmer/FDashboard'; +import Profilesetup from './components/ProfileSetup/Profilesetup'; ReactDOM.createRoot(document.getElementById('root')).render( - @@ -26,9 +26,9 @@ ReactDOM.createRoot(document.getElementById('root')).render( }/> }/> }/> + }/> - ); diff --git a/server/package-lock.json b/server/package-lock.json index e1320b8..1e67da7 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -15,7 +15,8 @@ "express": "^4.19.2", "firebase-admin": "^12.3.1", "node": "^20.17.0", - "nodemon": "^3.1.4" + "nodemon": "^3.1.4", + "socket.io": "^4.7.5" } }, "node_modules/@fastify/busboy": { @@ -327,6 +328,11 @@ "license": "BSD-3-Clause", "optional": true }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==" + }, "node_modules/@tootallnate/once": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", @@ -363,6 +369,19 @@ "@types/node": "*" } }, + "node_modules/@types/cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==" + }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/express": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.21.tgz", @@ -638,6 +657,14 @@ "license": "MIT", "optional": true }, + "node_modules/base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "engines": { + "node": "^4.5.0 || >= 5.9" + } + }, "node_modules/bignumber.js": { "version": "9.1.2", "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.1.2.tgz", @@ -975,6 +1002,63 @@ "once": "^1.4.0" } }, + "node_modules/engine.io": { + "version": "6.5.5", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.5.tgz", + "integrity": "sha512-C5Pn8Wk+1vKBoHghJODM63yk8MvrO9EWZUfkAt5HAqIgPE4/8FF0PEGHXtEd40l223+cE5ABWuPzm38PHFXfMA==", + "dependencies": { + "@types/cookie": "^0.4.1", + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.4.1", + "cors": "~2.8.5", + "debug": "~4.3.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.17.1" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/engine.io/node_modules/cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/engine.io/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/engine.io/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/es-define-property": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", @@ -2465,6 +2549,107 @@ "node": ">=10" } }, + "node_modules/socket.io": { + "version": "4.7.5", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz", + "integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==", + "dependencies": { + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.3.2", + "engine.io": "~6.5.2", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/socket.io-adapter": { + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", + "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", + "dependencies": { + "debug": "~4.3.4", + "ws": "~8.17.1" + } + }, + "node_modules/socket.io-adapter/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/socket.io-adapter/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/socket.io-parser": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io-parser/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/socket.io-parser/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/socket.io/node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/socket.io/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, "node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", @@ -2813,6 +2998,26 @@ "license": "ISC", "optional": true }, + "node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/server/package.json b/server/package.json index 870804d..dc251fe 100644 --- a/server/package.json +++ b/server/package.json @@ -4,7 +4,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start" : "node server.js" + "start": "node server.js" }, "keywords": [], "author": "", @@ -17,6 +17,7 @@ "express": "^4.19.2", "firebase-admin": "^12.3.1", "node": "^20.17.0", - "nodemon": "^3.1.4" + "nodemon": "^3.1.4", + "socket.io": "^4.7.5" } } diff --git a/server/server.js b/server/server.js index d253ebf..af7efe9 100644 --- a/server/server.js +++ b/server/server.js @@ -1,14 +1,21 @@ require("dotenv").config({ path: './.env.local' }); const express = require('express'); +const http = require('http'); const cors = require('cors'); const app = express(); -const port = process.env.PORT; - -app.use(cors()); +const {Server} = require('socket.io'); +const SERVER_PORT = process.env.SERVER_PORT; +const CLIENT_PORT = process.env.CLIENT_PORT; const states = require('./states.json'); +const server = http.createServer(app); + +//middleware +app.use(cors()); + +//routings app.get('/states', (req, res) => { res.json(Object.keys(states)); }); @@ -34,6 +41,23 @@ app.get('/areas/:state/:district/:subdistrict', (req, res) => { res.json(areas); }); -app.listen(port, () => { - console.log(`Server is running on http://localhost:${port}`); +//socket.io connections +const io = new Server(server, { + cors:{ + origin : `http://localhost:${CLIENT_PORT}`, + methods : ['GET', 'POST'] + } + +}) +io.on("connection", (socket)=>{ + console.log(socket.id); + + socket.on("send-message", (data)=>{ + console.log('sending message'); + socket.broadcast.emit("recieve-message", data.message); + }) +}) + +server.listen(SERVER_PORT, () => { + console.log(`Server is running on http://localhost:${SERVER_PORT}`); });