Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hunar #47

Merged
merged 89 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
13c1be6
Add folder for student register
hunardeep720 May 16, 2024
d66f17a
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 May 27, 2024
4efbd63
database
hunardeep720 May 28, 2024
a604a4a
- Created useContext for user (uid)
hunardeep720 May 28, 2024
8cf80bc
Merge branch 'master' into hunar
Abdelmouzahir May 28, 2024
8546781
merge master into hunar
hunardeep720 May 30, 2024
130b7ef
starting login page
hunardeep720 May 31, 2024
1c987cc
login page design
hunardeep720 Jun 1, 2024
1450ea9
Merge branch 'master' into hunar
hunardeep720 Jun 1, 2024
dfb88a9
signup page complete
hunardeep720 Jun 1, 2024
0697f9a
Merge branch 'hunar' of https://github.com/Abdelmouzahir/studentscoop…
hunardeep720 Jun 1, 2024
0b25395
adding colors
hunardeep720 Jun 1, 2024
393e812
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 1, 2024
3e1fcbc
file change
hunardeep720 Jun 1, 2024
edd54b4
forget password
hunardeep720 Jun 2, 2024
19b93f1
add modal
hunardeep720 Jun 2, 2024
f393bcb
Merge branch 'master' into hunar
hunardeep720 Jun 2, 2024
29019ae
merge from origin/master
hunardeep720 Jun 2, 2024
2a44982
add conditions
hunardeep720 Jun 2, 2024
527518c
Merge branch 'hunar' of https://github.com/Abdelmouzahir/studentscoop…
hunardeep720 Jun 2, 2024
63b866f
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 2, 2024
2d9c7f6
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 2, 2024
5bef163
login page
hunardeep720 Jun 2, 2024
e1d59cf
Merge branch 'master' into hunar
hunardeep720 Jun 2, 2024
aa37123
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 2, 2024
40dcf8c
Merge branch 'hunar' of https://github.com/Abdelmouzahir/studentscoop…
hunardeep720 Jun 2, 2024
b5cba7e
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 3, 2024
cb573dc
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 4, 2024
7d531f2
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 4, 2024
47e8ed3
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 4, 2024
ed9eaf9
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 4, 2024
b4f9723
add posst function for menu and restaurant details
hunardeep720 Jun 5, 2024
dfe8f69
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 5, 2024
2450c3c
meging with main
hunardeep720 Jun 5, 2024
101ab8d
adding restaurant information page
hunardeep720 Jun 5, 2024
f29a768
fetching and adding data for restaurants
hunardeep720 Jun 5, 2024
47c0ad7
Merge branch 'master' into hunar
hunardeep720 Jun 5, 2024
0d2cfc5
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 6, 2024
65d3839
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 8, 2024
e3bf978
merging from origin
hunardeep720 Jun 8, 2024
42ddda5
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 10, 2024
af61dcf
merge from orign
hunardeep720 Jun 10, 2024
4b43ac0
adding emails status in database
hunardeep720 Jun 11, 2024
be86cf2
add and create function for adding new email with active status
hunardeep720 Jun 11, 2024
94bdae6
Merge branch 'master' into hunar
hunardeep720 Jun 11, 2024
b77dddb
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 11, 2024
5dce3a2
chengin import sttement
hunardeep720 Jun 11, 2024
eae2c42
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 11, 2024
92fe4c8
to solve the colflicts with master branch and add new changes from ma…
hunardeep720 Jun 11, 2024
e80ed5c
adding terms condition
hunardeep720 Jun 11, 2024
ea1f24f
for merging from master
hunardeep720 Jun 11, 2024
72a8dbf
adding logos facility
hunardeep720 Jun 12, 2024
488c105
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 12, 2024
6c02f31
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 12, 2024
ca77b7f
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 13, 2024
161a4f1
merge from master
hunardeep720 Jun 13, 2024
46344ae
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 17, 2024
1c00471
update database
hunardeep720 Jun 18, 2024
3648b10
Merge branch 'master' into hunar
hunardeep720 Jun 18, 2024
a098cb2
adding search option
hunardeep720 Jun 18, 2024
a452058
commit
hunardeep720 Jun 18, 2024
b8eaa27
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 18, 2024
5c109c0
connecting sait-staff with database
hunardeep720 Jun 18, 2024
59c9a3f
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 18, 2024
985b984
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 20, 2024
1c9d654
merging form master
hunardeep720 Jun 20, 2024
5eecf46
changes on sait
hunardeep720 Jun 20, 2024
90bca74
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 22, 2024
c91c166
mege from master to origin
hunardeep720 Jun 22, 2024
e1d40d5
changing restaurant info table
hunardeep720 Jun 22, 2024
848d1de
adding data to database
hunardeep720 Jun 22, 2024
9c14400
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 23, 2024
d67e543
updating cards
hunardeep720 Jun 23, 2024
668b217
adding logc for increase and decrease arrow
hunardeep720 Jun 24, 2024
67b1db7
Merge branch 'master' into hunar
hunardeep720 Jun 24, 2024
057f92a
adding databse changes
hunardeep720 Jun 25, 2024
660f3ba
updating datasbe function to getting student information
hunardeep720 Jun 25, 2024
641b7d8
adding authentication for restaurants
hunardeep720 Jun 25, 2024
53e27e3
Merge remote-tracking branch 'origin/master' into hunar
hunardeep720 Jun 25, 2024
84b7141
changing Searching bar
hunardeep720 Jun 25, 2024
9f5f777
adding search bar in sait-staff
hunardeep720 Jun 25, 2024
09da5ee
updating restaurant login page
hunardeep720 Jun 25, 2024
f582af6
Merge branch 'master' into hunar
hunardeep720 Jun 25, 2024
3200e21
adding update,delete and change password features
hunardeep720 Jun 28, 2024
b30515c
Merge branch 'hunar' of https://github.com/Abdelmouzahir/studentscoop…
hunardeep720 Jun 28, 2024
7d5b791
Merge branch 'master' into hunar
hunardeep720 Jun 28, 2024
6be5807
adding fuctionality of deleting user's information from database incl…
hunardeep720 Jun 29, 2024
4ca06e8
Merge branch 'master' into hunar
hunardeep720 Jun 30, 2024
c6d2c64
update edit functionallity in sait-staff and add delete functionality…
hunardeep720 Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/restraunt/AddMenu/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const Page = () => {
);
return;
}
await addRestaurantMenu(user, name, price, description, image[0]).then(() => {
await addRestaurantMenu(user, name, price, description, image[0],user).then(() => {
router.push("/restraunt/home");
}
);
Expand Down
49 changes: 21 additions & 28 deletions app/restraunt/home/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useTable, useGlobalFilter } from "react-table";
import Image from "next/image";
import { MoreHorizontal } from "lucide-react";
import { useUserAuth } from "@/services/utils";
import { db } from "@/app/firebase/config";
import { deleteDoc, doc } from "firebase/firestore";
import {
getMenuInformation,
getRestaurantInformationByUser,
Expand Down Expand Up @@ -39,17 +41,14 @@ import Link from "next/link";

export default function SettingsRestaurant() {
const { user } = useUserAuth();
const [restaurantData, setRestaurantData] = useState([]);
const [menuData, setMenuData] = useState(null);
const route = useRouter();
const [selectedProduct, setSelectedProduct] = useState(null);
const [globalFilter, setGlobalFilter] = useState("");

useEffect(() => {
console.log("user: ", user);
async function gettingRestaurantMenu() {
const data = await getMenuInformation(user);
console.log("data: ", data);
if (data.length <= 0) {
}
setMenuData(data);
Expand All @@ -72,13 +71,14 @@ export default function SettingsRestaurant() {
setSelectedProduct(product);
};

const handleProductDelete = (productId) => {
setMenuData(menuData.filter((product) => product.id !== productId));
const handleProductDelete = async (productId) => {
await deleteDoc(doc(db, "restaurant_menu", productId)).then(() => {
setMenuData(menuData.filter((product) => product.id !== productId));
});
};

const columns = React.useMemo(
() => [
/*
{
Header: "Image",
accessor: "imageUrl",
Expand All @@ -87,25 +87,25 @@ export default function SettingsRestaurant() {
alt={`Product image - ${original.name}`}
className="aspect-square rounded-md object-cover"
height="64"
src={"url(/assets/images/restCover.jpg)"}
width="64"
/>
),
},
*/
{
Header: 'Image',
accessor: 'imageUrl',
Cell: ({ row: { original } }) => (
<img
alt={`Product image - ${original.name}`}
className="aspect-square rounded-md object-cover"
height="64"
src="/assets/images/food.png" // Correct path to the image
src={original.imageUrl}
width="64"
/>
),
},

// {
// Header: 'Image',
// accessor: 'imageUrl',
// Cell: ({ row: { original } }) => (
// <img
// alt={`Product image - ${original.name}`}
// className="aspect-square rounded-md object-cover"
// height="64"
// src="/assets/images/food.png" // Correct path to the image
// width="64"
// />
// ),
// },
{
Header: "Name",
accessor: "name",
Expand Down Expand Up @@ -145,13 +145,6 @@ export default function SettingsRestaurant() {
},
className: "hidden md:table-cell",
},

// {
// Header: "Total Sales",
// accessor: "totalSales",
// Cell: () => "0",
// className: "hidden md:table-cell",
// },
{
Header: "Actions",
accessor: "actions",
Expand Down
13 changes: 1 addition & 12 deletions app/restraunt/setting/page.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import { auth } from "@/app/firebase/config";
import { deleteUser } from "firebase/auth";
import { useUserAuth } from "@/services/utils";
import { useRouter } from "next/navigation";
import { getRestaurantInformationByUser } from "@/services/GetRequest/getRequest";
Expand Down Expand Up @@ -33,9 +32,7 @@ import {
Dialog,
DialogContent,
DialogFooter,
DialogClose,
} from "@/components/ui/dialog";
import { useActionData } from "react-router-dom";

export default function Component() {
const { user } = useUserAuth();
Expand All @@ -44,15 +41,9 @@ export default function Component() {
const [address, setAddress] = useState("");
const [id, setId] = useState('');
const [email, setEmail] = useState('');
const [showCurrentPassword, setShowCurrentPassword] = useState(false);
const [showNewPassword, setShowNewPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const [showPasswordResetModal, setShowPasswordResetModal] = useState(false);
const [currentUser, setCurrentUser] = useState(null);
const route = useRouter();
const handlePasswordReset = () => {
setShowPasswordResetModal(true);
};
useEffect(() => {
async function gettingUserInformation() {
const data = await getRestaurantInformationByUser(user);
Expand All @@ -61,7 +52,6 @@ export default function Component() {
if (user) {
setCurrentUser(auth.currentUser);
gettingUserInformation();
console.log(auth.currentUser);
}
if (user == false) {
route.push("/");
Expand All @@ -71,7 +61,6 @@ export default function Component() {
useEffect(() => {
if (userData) {
userData.map((information)=>{
console.log("information: ",typeof information.id)
setName(information.name);
setId(information.id);
setAddress(information.address);
Expand All @@ -86,7 +75,7 @@ export default function Component() {


async function deleteCurrentUser() {
await deleteRestaurantUser(currentUser,id).then(()=>alert("Your account has been deleted successfully!"))
await deleteRestaurantUser(currentUser,id,user);
}

async function passwordChange(){
Expand Down
5 changes: 2 additions & 3 deletions app/sait-staff/RDashboard/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ const Edit = ({ restaurants, selectedRestaurant, setRestaurants, setIsEditing, g
<input
id="email"
type="email"
name="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 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
// 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>
Expand Down
4 changes: 2 additions & 2 deletions app/sait-staff/SDashboard/Edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ const Edit = ({ selectedStudent, setIsEditing }) => {
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 focus:ring-blue-500 focus:border-blue-500 sm:text-sm"
// 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>
Expand Down
2 changes: 1 addition & 1 deletion app/sait-staff/overviewDash/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getAllStudentsInformation, getRestaurantInformation } from "@/services/

import { FaUsers, FaChartLine } from "react-icons/fa";
import { AiOutlineShop, AiOutlineTeam } from "react-icons/ai";
import {useSpring, animated} from "react-spring";
import { useSpring, animated } from "react-spring";

function NumberChange({n}){
const {number} = useSpring({
Expand Down
6 changes: 6 additions & 0 deletions merge from master
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Merge remote-tracking branch 'origin/master' into hunar
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2 changes: 0 additions & 2 deletions services/GetRequest/getRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export async function getRestaurantInformationByUser(user) {
return false;
}
}

export async function getMenuInformation(userId) {
try {
const q = query(
Expand All @@ -79,7 +78,6 @@ export async function getMenuInformation(userId) {
});
return userItems;
} catch (error) {
console.error("Error getting user information: ", error);
return [];
}
}
Expand Down
90 changes: 73 additions & 17 deletions services/PostRequest/postRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {
deleteDoc,
updateDoc,
} from "firebase/firestore";
import { ref, uploadBytesResumable, getDownloadURL } from "firebase/storage";
import {
ref,
uploadBytesResumable,
getDownloadURL,
getStorage,
listAll,
deleteObject,
} from "firebase/storage";
import { deleteUser } from "firebase/auth";

export async function addStudentInformation(userId, userInformation, email) {
Expand Down Expand Up @@ -76,8 +83,8 @@ export async function addRestaurantInformation(
);
}

export async function addRestaurantMenu(user, name, price, description, image) {
const storageRef = ref(storage, `menu/${image.name}`);
export async function addRestaurantMenu(user, name, price, description, image,userId) {
const storageRef = ref(storage, `menu/${userId}/${image.name}`);
const uploadTask = uploadBytesResumable(storageRef, image);
uploadTask.on(
"state_changed",
Expand Down Expand Up @@ -107,7 +114,7 @@ export async function addRestaurantMenu(user, name, price, description, image) {
name,
price,
description,
status: 'Available',
status: "Available",
imageUrl: downloadURL,
createdAt: new Date(),
});
Expand Down Expand Up @@ -181,14 +188,16 @@ export async function deleteRestaurantData(id) {
console.error("Error updating document: ", error);
}
}
export async function updateRestaurantData(id,name,address) {
export async function updateRestaurantData(id, name, address) {
try {
const docRef = doc(db, "restaurants", id);
await updateDoc(docRef, {
name:name,
address:address
name: name,
address: address,
});
console.log(`document has been updated where name: ${name}, id: ${id} and address is ${address}`)
console.log(
`document has been updated where name: ${name}, id: ${id} and address is ${address}`
);
} catch (error) {
console.error("Error updating document: ", error);
}
Expand Down Expand Up @@ -236,18 +245,65 @@ export async function existingRestaurantData(email) {
console.error("Error updating document: ", error);
}
}
export async function deleteRestaurantUser(currentUser, id){
// to delete restarant data from database, storage and athentication
export async function deleteRestaurantUser(currentUser, id, userId) {
const accountId = userId;
if (currentUser) {
console.log("currentUser: ", currentUser);
try {
console.log(id)
await deleteDoc(doc(db,"restaurants",id))
.then(async()=>{
// Step 1: Re-authenticate user if necessary
try {
await deleteUser(currentUser);
console.log("User delete successfully");
})
} catch (error) {
if (error.code === 'auth/requires-recent-login') {
const credential = EmailAuthProvider.credential(
currentUser.email,
prompt("Please enter your password to re-authenticate.")
);
await reauthenticateWithCredential(currentUser, credential);
await deleteUser(currentUser);
} else {
throw error;
}
}

// Step 2: Delete user document from Firestore
await deleteDoc(doc(db, "restaurants", id));

// Step 3: Delete user's data from restaurant_menu database
const userCollectionRef = collection(db, "restaurant_menu");
const q = query(userCollectionRef, where("userId", "==", accountId));
const querySnapshot = await getDocs(q);

querySnapshot.forEach(async (docSnapshot) => {
await deleteDoc(docSnapshot.ref);
});

// Step 4: Delete user's storage files
const storage = getStorage();
const folderRef = ref(storage, `menu/${accountId}`);

const deleteFolder = async (folderRef) => {
const res = await listAll(folderRef);
for (const itemRef of res.items) {
await deleteObject(itemRef);
}

for (const subfolderRef of res.prefixes) {
await deleteFolder(subfolderRef);
}
};

await deleteFolder(folderRef);
alert("Your account has been deleted successfully!");

} catch (error) {
console.error("error while deleting user: ", error);
if (error.code === 'auth/requires-recent-login') {
alert("To delete your account, please log out first and then proceed with the account deletion.");
} else {
console.error('Error while deleting user:', error);
}
}
} else {
console.log("No current user found");
}
}
}
Loading