Skip to content

Commit

Permalink
Hunar (#51)
Browse files Browse the repository at this point in the history
* Add folder for student register

issue: There was a router problem for student register
resolve: always make page.js for route just separate them by making different folders.

* database

* - Created useContext for user (uid)
- Added service folder with functions to read and write data from the database
- Added authentication for student/homepage and student/information
- Updated student/login page to fix email and password authentication issues

* starting login page

* login page design

* signup page complete

* adding colors

* file change

* forget password

* add modal

* add conditions

* login page

* add posst function for menu and restaurant details

* meging with main

* adding restaurant information page

* fetching and adding data for restaurants

* merging from origin

* merge from orign

* adding emails status in database

* add and create function for adding new email with active status
add and create function for getting email names where active status is true
make changes in register page to check that email is in database for register

* chengin import sttement

* adding terms condition

* adding logos facility

* merge from master

* update database
sait-staff

* adding search option

* commit

* connecting sait-staff with database

* merging form master

* changes on sait

* mege from master to origin

* changing restaurant info table

* adding data to database

* updating cards

* adding logc for increase and decrease arrow

* adding databse changes

* updating datasbe function to getting student information

* adding authentication for restaurants

* changing Searching bar

* adding search bar in sait-staff

* updating restaurant login page

* adding update,delete and change password features

* adding fuctionality of deleting user's information from database including user data and restaurant menu, delete data from storage and from authentication

* update edit functionallity in sait-staff and add delete functionality in restaurant

* add add functionality for admins

* Hunar (#46)

* Add folder for student register

issue: There was a router problem for student register
resolve: always make page.js for route just separate them by making different folders.

* database

* - Created useContext for user (uid)
- Added service folder with functions to read and write data from the database
- Added authentication for student/homepage and student/information
- Updated student/login page to fix email and password authentication issues

* starting login page

* login page design

* signup page complete

* adding colors

* file change

* forget password

* add modal

* add conditions

* login page

* add posst function for menu and restaurant details

* meging with main

* adding restaurant information page

* fetching and adding data for restaurants

* merging from origin

* merge from orign

* adding emails status in database

* add and create function for adding new email with active status
add and create function for getting email names where active status is true
make changes in register page to check that email is in database for register

* chengin import sttement

* adding terms condition

* adding logos facility

* merge from master

* update database
sait-staff

* adding search option

* commit

* connecting sait-staff with database

* merging form master

* changes on sait

* mege from master to origin

* changing restaurant info table

* adding data to database

* updating cards

* adding logc for increase and decrease arrow

* adding databse changes

* updating datasbe function to getting student information

* adding authentication for restaurants

* changing Searching bar

* adding search bar in sait-staff

* updating restaurant login page

* adding update,delete and change password features

* adding fuctionality of deleting user's information from database including user data and restaurant menu, delete data from storage and from authentication

---------

Co-authored-by: Abdel Mouzahir <[email protected]>

* trying to show username in saitstaff

* console log

* small change

* remove azure

* adding loading animation

* loading in all login pages

* trying to fetch the name

* fetch data in login

* comment to hunar

* problem solved mentioned by abdel

* updatinf sait-login

* add feature of edit and update active state

---------

Co-authored-by: Abdel Mouzahir <[email protected]>
Co-authored-by: abdel mouzahir <[email protected]>
  • Loading branch information
3 people authored Jul 5, 2024
1 parent c88150f commit 8ff8834
Show file tree
Hide file tree
Showing 7 changed files with 406 additions and 80 deletions.
8 changes: 2 additions & 6 deletions app/sait-staff/login/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ const SignIn = () => {
const user = auth.currentUser;
if (user) {
const uid = user.uid;
console.log('user ',uid)
const q = query(collection(db, "saitStaff"), where("uid", "==", uid));
const querySnapshot = await getDocs(q);
const employeeData = querySnapshot.docs.map((doc) => doc.data().name);
console.log('name: ',employeeData);

if (!employeeData.empty) {
const saitStaffData = employeeData[0];
const name = saitStaffData || "SAIT Staff"; // Use default name if 'name' is not available
setSaitStaffName(name);
console.log("user name: ",name)
} else {
console.log("No SAIT Staff data found for current user");
setSaitStaffName("SAIT Staff"); // Set default name
Expand All @@ -58,7 +57,6 @@ const SignIn = () => {
try {
const userCredential = await signInWithEmailAndPassword(email, password);
const user = userCredential.user;
console.log(user);

// Update display name with SAIT Staff name
await updateProfile(user, { displayName: saitStaffName });
Expand All @@ -67,12 +65,10 @@ const SignIn = () => {
sessionStorage.setItem("name", saitStaffName);
sessionStorage.setItem("email", user.email || ""); // Store the user's email
sessionStorage.setItem("uid", user.uid || ""); // Store the user's UID
console.log(saitStaffName);
router.push("/sait-staff"); // Redirect after successful sign-in
setEmail("");
setPassword("");
setLoginError("");
//setLoading(false);
router.push("/sait-staff"); // Redirect after successful sign-in
} catch (error) {
setLoading(false);
setLoginError("Invalid email or password");
Expand Down
17 changes: 5 additions & 12 deletions app/sait-staff/overviewDash/Add.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ const Add = ({ admin, setAdmins, setIsAdding }) => {
const [email, setEmail] = useState("");
const [phoneNumber, setPhoneNumber] = useState("");
const [address, setAddress] = useState("");

const currentDate = new Date();

const day = currentDate.getDate();
const month = currentDate.getMonth(); // Remember, month is zero-indexed
const year = currentDate.getFullYear();

const newDate = [day, month, year];
let firstWord = name.split(" ");

//generic password will be first name of student or restaurant + last three digits of mobile number + "!"
Expand Down Expand Up @@ -54,6 +46,7 @@ const Add = ({ admin, setAdmins, setIsAdding }) => {
genericPassword
);
const user = userCredential.user;
const date = new Date();

// Add restaurant to Firestore
const newAdmin = {
Expand All @@ -63,7 +56,7 @@ const Add = ({ admin, setAdmins, setIsAdding }) => {
phoneNumber,
address,
uid: user.uid,
acountCreated: newDate, // link with user ID
accountCreated: date, // link with user ID
active: true,
};

Expand Down Expand Up @@ -168,9 +161,9 @@ const Add = ({ admin, setAdmins, setIsAdding }) => {
value={role}
>
<option value="">Select a role</option>
<option value="admin">Admin</option>
<option value="editor">Editor</option>
<option value="viewer">Viewer</option>
<option value="Admin">Admin</option>
<option value="Editor">Editor</option>
<option value="Viewer">Viewer</option>
</select>
</div>
<div>
Expand Down
174 changes: 174 additions & 0 deletions app/sait-staff/overviewDash/Edit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React, { useState } from "react";
import { formatPhoneNumber } from "@/Constant/formated";
import Swal from "sweetalert2";

import { doc, setDoc, updateDoc } from "firebase/firestore";
import { db } from "@/app/firebase/config";

const Edit = ({ employeeData, setIsEditing, getData, userData }) => {
const [name, setName] = useState(employeeData.name);
const [email, setEmail] = useState(employeeData.email);
const [mobileNumber, setMobileNumber] = useState(employeeData.phoneNumber);
const id = employeeData.id;
const [role, setRole] = useState(employeeData.role);
const [userRole, setUserRole] = useState(userData[0].role);
const [address, setAddress] = useState(employeeData.address);

const handleChangeRole = (e) => {
setRole(e.target.value);
};

const handleUpdate = async (e) => {
e.preventDefault();

if (!name || !email || !mobileNumber) {
return Swal.fire({
icon: "error",
title: "Error!",
text: "All fields are required.",
showConfirmButton: true,
});
}

const employee = {
id,
name,
email,
mobileNumber,
role,
address
};

const dataForUpdate = doc(db, "saitStaff", id);
await updateDoc(dataForUpdate, employee);
getData();
setIsEditing(false);

Swal.fire({
icon: "success",
title: "Updated!",
text: `${employeeData.name}'s data has been updated.`,
showConfirmButton: false,
timer: 1500,
});
};

return (
<div className="container mx-auto mt-8 p-6 bg-gray-100 rounded-lg shadow-lg max-w-lg">
<form onSubmit={handleUpdate} className="space-y-6">
<h1 className="text-2xl font-bold mb-4 text-center text-gray-700">
Edit Employee
</h1>
<div>
<label
htmlFor="firstName"
className="block text-sm font-medium text-gray-700"
>
Employee Name
</label>
<input
id="firstName"
type="text"
name="firstName"
value={name}
onChange={(e) => setName(e.target.value)}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
/>
</div>

<div>
<label
htmlFor="email"
className="block text-sm font-medium text-gray-700"
>
Email
</label>
<input
id="email"
type="email"
value={email}
// onChange={(e) => setEmail(e.target.value)}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none sm:text-sm cursor-not-allowed bg-black/20"
/>
</div>
<div>
<label
htmlFor="salary"
className="block text-sm font-medium text-gray-700"
>
Phone Number
</label>
<input
id="phone"
type="text"
name="phone"
value={mobileNumber}
onChange={(e) => setMobileNumber(formatPhoneNumber(e.target.value))}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
/>
</div>
<div>
<label id="role" className="block text-sm font-medium text-gray-700">
Role
</label>
{userRole == "Admin" && (
<select
id="role"
value={role}
onChange={(e) => handleChangeRole(e)}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm bg-white"
>
<option>Change the Role</option>
<option value="Admin">Admin</option>
<option value="Editor">Editor</option>
<option value="Viewer">Viewer</option>
</select>
)}
{userRole !== "Admin" && (
<select
id="role"
value={role}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm bg-white"
>
<option value={role}>{role}</option>
</select>
)}
</div>
<div>
<label
htmlFor="address"
className="block text-sm font-medium text-gray-700"
>
Address
</label>
<input
id="address"
type="text"
name="address"
value={address}
onChange={(e) => setAddress(e.target.value)}
className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
/>
</div>

<div className="flex justify-end space-x-3">
<button
type="submit"
className="bg-blue-600 text-white px-4 py-2 rounded shadow hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500"
>
Update
</button>
<button
type="button"
className="bg-gray-600 text-white px-4 py-2 rounded shadow hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
onClick={() => setIsEditing(false)}
>
Cancel
</button>
</div>
</form>
</div>
);
};

export default Edit;
Loading

0 comments on commit 8ff8834

Please sign in to comment.