From 6cdb17ee00e228f0e2f4b2c9f17e3e2e093fb180 Mon Sep 17 00:00:00 2001 From: Owen Olabode Date: Tue, 6 May 2025 21:31:58 +0100 Subject: [PATCH 1/2] pharmacy signup and signin feature --- Backend/controllers/pharmacyController.js | 19 +- Frontend/.gitignore | 3 + Frontend/src/App.jsx | 6 +- .../components/forms/NewPharmarcySignUp.jsx | 170 ++++++++++++++++++ .../src/components/forms/PhamarcySignUp.jsx | 27 +-- .../src/components/forms/Pharmarcysignin.jsx | 130 ++++++++++++++ Frontend/src/components/forms/SignIn.jsx | 5 +- Frontend/src/components/forms/SignUp.jsx | 4 +- .../src/styles/newpharmacysignup.module.css | 63 +++++++ Frontend/src/styles/pharmacysignin.module.css | 83 +++++++++ ...cysignup.css => pharmacysignup.module.css} | 139 +++++++------- 11 files changed, 550 insertions(+), 99 deletions(-) create mode 100644 Frontend/src/components/forms/NewPharmarcySignUp.jsx create mode 100644 Frontend/src/components/forms/Pharmarcysignin.jsx create mode 100644 Frontend/src/styles/newpharmacysignup.module.css create mode 100644 Frontend/src/styles/pharmacysignin.module.css rename Frontend/src/styles/{pharmacysignup.css => pharmacysignup.module.css} (74%) diff --git a/Backend/controllers/pharmacyController.js b/Backend/controllers/pharmacyController.js index dc89321f..0312ecc9 100644 --- a/Backend/controllers/pharmacyController.js +++ b/Backend/controllers/pharmacyController.js @@ -173,7 +173,9 @@ exports.toggleClosingStatus = async (req, res) => { // @desc post pharmacy Forgot password // @route POST /api/pharmacies/forgot-password exports.forgotPassword = async (req, res) => { - const pharmacy = await pharmacy.findOne({ email: req.body.email.trim().toLowerCase() }); + const pharmacy = await pharmacy.findOne({ + email: req.body.email.trim().toLowerCase(), + }); if (!pharmacy) { return res.status(404).json({ message: "Pharmacy not found" }); } @@ -204,8 +206,7 @@ exports.forgotPassword = async (req, res) => { message: "Error sending email. Please try again later.", }); } -} - +}; // @desc patch pharmacy reset password // @route PATCH /api/pharmacies/reset-password/:token @@ -221,17 +222,17 @@ exports.resetPassword = async (req, res) => { passwordResetToken: hashedToken, passwordResetExpires: { $gt: Date.now() }, }); - + if (!pharmacy) { return res.status(400).json({ message: "Invalid or expired token" }); } - + pharmacy.password = req.body.password; pharmacy.passwordResetToken = undefined; pharmacy.passwordResetExpires = undefined; - + await pharmacy.save(); - + res.status(200).json({ message: "Password reset successful" }); //login pharmacy const loginToken = generateToken(pharmacy); @@ -240,6 +241,6 @@ exports.resetPassword = async (req, res) => { token: loginToken, }); } catch (err) { - res.status(500).json({message: "Server error", error: err.message }); + res.status(500).json({ message: "Server error", error: err.message }); } -} \ No newline at end of file +}; diff --git a/Frontend/.gitignore b/Frontend/.gitignore index a547bf36..5c0b45a0 100644 --- a/Frontend/.gitignore +++ b/Frontend/.gitignore @@ -22,3 +22,6 @@ dist-ssr *.njsproj *.sln *.sw? + +# Ignore the .env file +.env diff --git a/Frontend/src/App.jsx b/Frontend/src/App.jsx index 1c2dbc0a..7eb1b5c8 100644 --- a/Frontend/src/App.jsx +++ b/Frontend/src/App.jsx @@ -17,11 +17,12 @@ import OrderSummary from "./pages/OrderSummary"; // import ProfileSignup from "./pages/ProfileSignup"; import FindMedsLoading from "./components/FindMedsLoading"; import UpdatedCart from "./pages/UpdatedCart"; -import PhamarcySignUp from "./components/forms/PhamarcySignUp"; +import NewPharmarcySignUp from "./components/forms/NewPharmarcySignUp"; import MedicineTable from "./components/MedicineTable"; import UploadPrescription from "./pages/UploadPrescription"; import PharmacyOtp from "./components/PharmacyOtp"; import OtpConfirmed from "./components/OtpConfirmed"; +import Pharmarcysignin from "./components/forms/Pharmarcysignin"; // Code splitted Components (Lazy Loading)... // N.B- Please do not touch if you're new to how lazy loading works.. @@ -133,7 +134,8 @@ function App() { {/* Pharmacy Routing */} } /> } /> - } /> + } /> + } /> } /> } /> } /> diff --git a/Frontend/src/components/forms/NewPharmarcySignUp.jsx b/Frontend/src/components/forms/NewPharmarcySignUp.jsx new file mode 100644 index 00000000..8ed1ad11 --- /dev/null +++ b/Frontend/src/components/forms/NewPharmarcySignUp.jsx @@ -0,0 +1,170 @@ +import React, { useState } from "react"; +import styles from "../../styles/newpharmacysignup.module.css"; +import caretleft from "../../assets/CaretLeft.png"; +import cancelicon from "../../assets/X.png"; + +const InputField = ({ id, name, type, placeholder, value, onChange }) => ( + +); + +const NewPharmarcySignUp = () => { + const [formData, setFormData] = useState({ + name: "", + email: "", + password: "", + confirmPassword: "", + phone: "", + address: "", + }); + + const [error, setError] = useState(""); + const [success, setSuccess] = useState(false); + const [loading, setLoading] = useState(false); + + const handleChange = (e) => { + const { name, value } = e.target; + setFormData({ ...formData, [name]: value }); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + setError(""); + setSuccess(false); + + // Basic validation + if ( + !formData.name || + !formData.email || + !formData.password || + !formData.confirmPassword || + !formData.phone || + !formData.address + ) { + setError("All fields are required."); + return; + } + + if (formData.password !== formData.confirmPassword) { + setError("Passwords do not match."); + return; + } + + setLoading(true); + + try { + const response = await fetch( + `${import.meta.env.VITE_API_URL}/pharmacies/signup`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(formData), + } + ); + + if (!response.ok) { + throw new Error("Failed to sign up. Please try again."); + } + + const data = await response.json(); + setSuccess(true); + setFormData({ + name: "", + email: "", + password: "", + confirmPassword: "", + phone: "", + address: "", + }); + } catch (err) { + setError(err.message); + } finally { + setLoading(false); + } + }; + + return ( +
+
+
+ go back +

Create Account

+ close +
+
+ + + + + + + + {error &&

{error}

} + {success &&

Sign up successful!

} + + + +
+

Already have an account?

+ Log in +
+
+
+ ); +}; + +export default NewPharmarcySignUp; diff --git a/Frontend/src/components/forms/PhamarcySignUp.jsx b/Frontend/src/components/forms/PhamarcySignUp.jsx index f9360ab5..b0ecfe8d 100644 --- a/Frontend/src/components/forms/PhamarcySignUp.jsx +++ b/Frontend/src/components/forms/PhamarcySignUp.jsx @@ -1,33 +1,34 @@ import React from "react"; -import "../../styles/pharmacysignup.css"; +import styles from "../../styles/pharmacysignup.module.css"; import caretleft from "../../assets/CaretLeft.png"; -import cancelicon from "../../assets/X.png" +import cancelicon from "../../assets/X.png"; const PhamarcySignUp = () => { return ( -
-
- caretleft - caretleft -
+
+
+ caretleft + caretleft +
-