Skip to content

Commit

Permalink
Hunar (#60)
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

* add search functionality in sait-staff

* add feature of updating password and delete account

* small change

* add profil picture in saitadmin

* approuval

* add profile page for sait-staff and resolve the problem related sait-staff login

* connect profile part with database

* update sait-staff components

* resolve the issue related to change address in sait-staff for user

* resolve issues related to delete account

* tryto implement realtime database

---------

Co-authored-by: Abdel Mouzahir <[email protected]>
Co-authored-by: abdel mouzahir <[email protected]>
  • Loading branch information
3 people authored Jul 10, 2024
1 parent d5e4b05 commit 92aa40b
Show file tree
Hide file tree
Showing 20 changed files with 3,728 additions and 513 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=studentscoops-20914.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=587068742076
NEXT_PUBLIC_FIREBASE_APP_ID=1:587068742076:web:eae4086eb66079b2a1b3b9
NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID=G-726MZHCFPY
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=AIzaSyBzDTIl8e9KhdhTA1qN6dOc9rPhLRjJAVA
NEXT_PUBLIC_FIREBASE_DATABASE_URL=https://studentscoops-20914-default-rtdb.firebaseio.com
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY=AIzaSyBzDTIl8e9KhdhTA1qN6dOc9rPhLRjJAVA
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
6 changes: 3 additions & 3 deletions Components/UserGreeting.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useState } from "react";

const UserGreeting = ({ setActiveTab, data }) => {
const [userName, setUserName] = useState(data[0].name);
const [email, setEmail] = useState(data[0].email);
const [userImage, setUserImage] = useState(data[0].imageUrl);
const [userName, setUserName] = useState('');
const [email, setEmail] = useState('');
const [userImage, setUserImage] = useState('');

useEffect(() => {
if(data){
Expand Down
5 changes: 3 additions & 2 deletions app/auth/loginRestaurant/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { auth } from "@/app/firebase/config";
import { useRouter } from "next/navigation";
import Link from "next/link";
import { sendPasswordResetEmail } from "firebase/auth";
import Modal from "@/components/Modal";
import Modal from "@/Components/Modal";
import { BiSolidCommentError } from "react-icons/bi";
import { getRestaurantInformationByUser } from "@/services/GetRequest/getRequest";
import Loading from "@/app/loading";
import { getRestaurantDataForOwner } from "@/services/RealTimeDatabase/getData/getData";

const sign_in = () => {
const [email, setEmail] = useState("");
Expand All @@ -28,7 +29,7 @@ const sign_in = () => {
return user.uid
}})
.then(async (uid) => {
const login = await getRestaurantInformationByUser(uid);
const login = await getRestaurantDataForOwner(uid);
if (login.length <= 0) {
setLoginError("You are not authorized to access this website.");
return;
Expand Down
25 changes: 15 additions & 10 deletions app/firebase/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Import the functions you need from the SDKs you need
import { initializeApp, getApps, getApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import {getAuth} from 'firebase/auth';
import { getAuth } from "firebase/auth";
import { getAnalytics, isSupported } from "firebase/analytics";
import { getStorage } from "firebase/storage";
import { getDatabase } from "firebase/database";

// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

Expand All @@ -15,8 +17,9 @@ const firebaseConfig = {
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID ,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID,
measurementId: process.env.NEXT_PUBLIC_FIREBASE_MEASUREMENT_ID,
databaseURL: process.env.NEXT_PUBLIC_FIREBASE_DATABASE_URL,
};

// Initialize Firebase
Expand All @@ -25,15 +28,17 @@ const auth = getAuth(app);
const storage = getStorage(app);
let analytics;
const db = getFirestore(app);

const database = getDatabase(app);

// Initialize Firebase Analytics only if supported and in the client-side environment
if (typeof window !== "undefined") {
isSupported().then((supported) => {
if (supported) {
analytics = getAnalytics(app);
}
}).catch(console.error);
isSupported()
.then((supported) => {
if (supported) {
analytics = getAnalytics(app);
}
})
.catch(console.error);
}

export { app , auth, db, analytics, storage}
export { app, auth, db, analytics, storage, database };
3 changes: 2 additions & 1 deletion app/restraunt/AddMenu/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState } from "react";
import { useUserAuth } from "@/services/utils";
import { useRouter } from "next/navigation";
import { addRestaurantMenu } from "@/services/PostRequest/postRequest";
import { addMenu } from "@/services/RealTimeDatabase/postData/postData";
import {
Card,
CardHeader,
Expand Down Expand Up @@ -36,7 +37,7 @@ const Page = () => {
);
return;
}
await addRestaurantMenu(user, name, price, description, image[0],user).then(() => {
await addMenu(user, name, price, description, image[0],user).then(() => {
router.push("/restraunt/home");
}
);
Expand Down
75 changes: 36 additions & 39 deletions app/restraunt/home/page.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
"use client";
import React, { useState, useEffect } from "react";
import { ref, onValue, off } from "firebase/database";
import { database } from "@/app/firebase/config";
import React, { useState, useEffect, useCallback } from "react";
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,
} from "@/services/GetRequest/getRequest";
import { getRestaurantMenu } from "@/services/RealTimeDatabase/getData/getData";
import { useRouter } from "next/navigation";
import { Input } from "@/components/ui/input";
import { Badge } from "@/components/ui/badge";
Expand Down Expand Up @@ -41,27 +40,37 @@ import Link from "next/link";

export default function SettingsRestaurant() {
const { user } = useUserAuth();
const [menuData, setMenuData] = useState(null);
const [menuData, setMenuData] = useState([]);
const route = useRouter();
const [selectedProduct, setSelectedProduct] = useState(null);
const [globalFilter, setGlobalFilter] = useState("");
const restaurantRef = ref(database, "restaurants/" + user + "/menu");

const getRestaurantMenuCallback = useCallback(getRestaurantMenu, [user]);

useEffect(() => {
async function gettingRestaurantMenu() {
const data = await getMenuInformation(user);
if (data.length <= 0) {
}
setMenuData(data);
}
async function userIsActive() {
const data = await getRestaurantInformationByUser(user);
if (!data.length == 0) {
gettingRestaurantMenu();
}
}
if (user) {
userIsActive();
}
function gettingMenu(){
try {
const unsubscribe = onValue(restaurantRef, (snapshot) => {
const data = snapshot.val();
if (data) {
const formattedData = Object.entries(data).map(([key, value]) => ({
id: key,
...value,
}));
setMenuData(formattedData);
} else {
setMenuData([]);
}
});
} catch (error) {
console.log(error);
}}

return gettingMenu();
}, [restaurantRef]);
useEffect(() => {
// restaurantMenu();
if (user == false) {
route.push("/");
}
Expand All @@ -73,7 +82,9 @@ export default function SettingsRestaurant() {

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

Expand All @@ -92,20 +103,6 @@ export default function SettingsRestaurant() {
/>
),
},

// {
// 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 All @@ -125,7 +122,7 @@ export default function SettingsRestaurant() {
Header: "Date",
accessor: "createdAt",
Cell: ({ cell: { value } }) => {
const date = new Date(value.seconds * 1000); // Assuming the value is a Firestore timestamp
const date = new Date(value);
const day = date.getDate().toString().padStart(2, "0");
const month = (date.getMonth() + 1).toString().padStart(2, "0"); // Months are zero-indexed
const year = date.getFullYear();
Expand Down Expand Up @@ -175,7 +172,7 @@ export default function SettingsRestaurant() {
[menuData]
);

const data = React.useMemo(() => menuData || [], [menuData]);
const data = React.useMemo(() => menuData, [menuData]);

const {
getTableProps,
Expand All @@ -192,7 +189,7 @@ export default function SettingsRestaurant() {

return (
<div>
{menuData === null ? (
{menuData.length === 0 ? (
<div className="flex flex-col items-center justify-center h-screen ">
<h3 className="text-2xl font-bold tracking-tight text-primary">
You have no products
Expand Down
1 change: 1 addition & 0 deletions app/restraunt/setting/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { auth } from "@/app/firebase/config";
import { useUserAuth } from "@/services/utils";
import { useRouter } from "next/navigation";
import { getRestaurantInformationByUser } from "@/services/GetRequest/getRequest";
import { getRestaurantDataForOwner } from "@/services/RealTimeDatabase/getData/getData";
import { sendPasswordResetEmail } from "firebase/auth";
import { updateRestaurantData, deleteRestaurantUser } from "@/services/PostRequest/postRequest";
import {
Expand Down
Loading

0 comments on commit 92aa40b

Please sign in to comment.