diff --git a/backend/.env.example b/backend/.env.example index 863c16c..670660c 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1 +1,5 @@ -MONGOURI= \ No newline at end of file +MONGO_URI= +CLOUD_NAME= +API_KEY= +API_SECRET= +CLIENT_URL= \ No newline at end of file diff --git a/backend/controller/member_controller.js b/backend/controller/member_controller.js index 3e1f99e..7069234 100644 --- a/backend/controller/member_controller.js +++ b/backend/controller/member_controller.js @@ -1,6 +1,5 @@ import Member from "../model/Member_model.js"; - -cloudinary.uploader.upload(); +import { v2 as cloudinary } from "cloudinary"; export const handleCreateMember = async (req, res) => { try { diff --git a/backend/package-lock.json b/backend/package-lock.json index fbb1ddf..98e7501 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -17,9 +17,9 @@ } }, "node_modules/@types/node": { - "version": "20.4.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.5.tgz", - "integrity": "sha512-rt40Nk13II9JwQBdeYqmbn2Q6IVTA5uPhvSO+JVqdXw/6/4glI6oR9ezty/A9Hg5u7JH4OmYmuQ+XvjKm0Datg==" + "version": "20.4.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.9.tgz", + "integrity": "sha512-8e2HYcg7ohnTUbHk8focoklEQYvemQmu9M/f43DZVx43kHn0tE3BY/6gSDxS7k0SprtS0NHvj+L80cGLnoOUcQ==" }, "node_modules/@types/webidl-conversions": { "version": "7.0.0", @@ -531,9 +531,9 @@ } }, "node_modules/mongoose": { - "version": "7.4.1", - "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-7.4.1.tgz", - "integrity": "sha512-o3E5KHHiHdaiwCJG3+9r70sncRKki71Ktf/TfXdW6myu+53rtZ56uLl5ylkQiCf60V3COJuOeekcxXVsjQ7cBA==", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-7.4.2.tgz", + "integrity": "sha512-sNolW2hyncwvWmZjIEIwAckjaSKtC1SE86zE1v2TKm3vPTRogZfBQf+3zLYYdrgrVTzoaoICieVpct9hjcn3EQ==", "dependencies": { "bson": "^5.4.0", "kareem": "2.5.1", diff --git a/backend/server.js b/backend/server.js index 97d2fd7..52890a2 100644 --- a/backend/server.js +++ b/backend/server.js @@ -5,14 +5,14 @@ import dotenv from "dotenv"; import { memberRoute } from "./routes/route.js"; import { v2 as cloudinary } from "cloudinary"; +dotenv.config(); + cloudinary.config({ cloud_name: process.env.CLOUD_NAME, api_key: process.env.API_KEY, api_secret: process.env.API_SECRET, - secure: true, }); -dotenv.config(); connectDB(); const app = express(); @@ -26,7 +26,7 @@ const port = 5000 || process.env.PORT; app.use( cors({ - origin: "http://localhost:3000", + origin: process.env.CLIENT_URL, }) ); diff --git a/client/.env.example b/client/.env.example new file mode 100644 index 0000000..421216e --- /dev/null +++ b/client/.env.example @@ -0,0 +1 @@ +BASE_URL= \ No newline at end of file diff --git a/client/.gitignore b/client/.gitignore index 8b19452..f849df7 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -32,6 +32,8 @@ yarn-error.log* # vercel .vercel +.env + # typescript *.tsbuildinfo next-env.d.ts diff --git a/client/app/register/layout.js b/client/app/register/layout.js index 2da76b7..ed668b8 100644 --- a/client/app/register/layout.js +++ b/client/app/register/layout.js @@ -1,6 +1,6 @@ import '../../styles/globals.css'; export const metadata = { - title: 'Register', + title: "Student's Chapter CSE", description: 'Register to become a Member', }; diff --git a/client/app/register/page.js b/client/app/register/page.js index a6472c2..487df3b 100644 --- a/client/app/register/page.js +++ b/client/app/register/page.js @@ -1,35 +1,39 @@ 'use client'; import { useState } from 'react'; import { useForm } from 'react-hook-form'; -import axios from 'axios'; import { useRouter } from 'next/navigation'; import styles from '../../styles/RegistrationForm.module.css'; import { ArrowLeft } from '@phosphor-icons/react'; +import Preloader from '../../component/Preloader'; +import { axios_instance } from '../../axios/axios'; const index = () => { const { register, handleSubmit } = useForm(); + const [Isloading, SetIsLoading] = useState(false); const [image_base64, setImage_base64] = useState(); const onSubmit = async (form_data) => { + SetIsLoading(true); try { - const { data } = await axios.post( - 'http://localhost:5000/api/v1/member', - { - name: form_data?.name, - email: form_data?.email, - rollno: form_data?.rollno, - memberOf: form_data?.memberOf, - picture: image_base64, - courseCompletionYear: form_data?.courseCompletionYear, - section: form_data?.section, - phonenumber: form_data?.phonenumber, - paymentDone: form_data?.paymentDone, - } - ); + const { data } = await axios_instance.post('/api/v1/member', { + name: form_data?.name, + email: form_data?.email, + rollno: form_data?.rollno, + memberOf: form_data?.memberOf, + picture: image_base64, + courseCompletionYear: form_data?.courseCompletionYear, + section: form_data?.section, + phonenumber: form_data?.phonenumber, + paymentDone: form_data?.paymentDone, + }); + alert('Registered successfully'); console.log(data); } catch (err) { + alert('Registration failed'); throw new Error(err); + } finally { + SetIsLoading(false); } }; const handleFileRead = async (e) => { @@ -55,154 +59,171 @@ const index = () => { }; //const getBase64; - - return ( -
-
-
- -
-

-
Register
-
Student's Chapter
-

-
- -
-
- - + if (Isloading) { + return ; + } else + return ( +
+
+
+ +
+

+
Register
+
Student's Chapter
+

+ + +
+
+ + +
+
+ + +
-
- - +
+
+ + +
+
+ + +
-
-
-
- + +
+ handleFileRead(e)} />
-
-
+ -
- - handleFileRead(e)} - /> -
- - - -
- - -
-
- - -
-
- - + +
+
+ + +
+
+ + +
-
-
-
+ - -
- - +
+ +
- - -
- - -
- + +
-
- ); + ); }; export default index; diff --git a/client/axios/axios.js b/client/axios/axios.js new file mode 100644 index 0000000..d480e06 --- /dev/null +++ b/client/axios/axios.js @@ -0,0 +1,5 @@ +import axios from 'axios'; + +export const axios_instance = axios.create({ + baseURL: process.env.BASE_URL, +});