Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/InternAcademy/CookingApp int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
ImSk1 committed Aug 2, 2024
2 parents 92d2771 + 23d4983 commit 47b0c39
Show file tree
Hide file tree
Showing 25 changed files with 917 additions and 166 deletions.
4 changes: 4 additions & 0 deletions src/client/CookingAppReact/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Layout from "./pages/layout/Layout";
import Recipe from "./pages/recipe/Recipe";
import Admin from "./pages/admin/Admin";
import Subscribtion from "./pages/subscribtion/Subscribtion";
import Success from "./pages/subscribtion/Succes";
import Settings from "./components/userMenu/settings/Settings";
const router = createBrowserRouter([
{
path: "/",
Expand All @@ -24,6 +26,8 @@ const router = createBrowserRouter([
{ path: "r/:recipeId", element: <Recipe /> },
{ path: "admin/dashboard", element: <Admin /> },
{ path: "subscribtion", element: <Subscribtion /> },
{ path: "success", element: <Success /> },
{ path: "settings", element: <Settings /> },
],
},
]);
Expand Down
28 changes: 24 additions & 4 deletions src/client/CookingAppReact/src/components/auth/SignOutButton.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { handleLogout } from "../../msal/msal";
"use client";
import { handleLogout } from "@/msal/msal";
import { FaSignOutAlt } from "react-icons/fa";
// import { useTheme } from "next-themes";

const SignOutButton = () => {
// const { theme } = useTheme();
// const isDarkTheme = theme === 'dark';

return (
<button className="flex items-center" title="Sign Out" onClick={() => handleLogout("redirect")}>
<span className={`text-lg text-black`}>Sign Out</span>
</button>
<FaSignOutAlt
className="w-6 h-6 mr-4
smallPhone:w-4
phone:w-4
tablet:w-6
web:w-6"
// color={isDarkTheme ? "white" : "black"}
/>
<span
className={`
smallPhone:text-base
phone:text-base
tablet:text-lg
web:text-lg`}>Sign Out</span>
</button>
);
};
export default SignOutButton;

export default SignOutButton;
38 changes: 33 additions & 5 deletions src/client/CookingAppReact/src/components/navbar/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import React, { useState } from "react";
import { Bars3BottomLeftIcon } from "@heroicons/react/24/outline";
import { ChatBubbleOvalLeftEllipsisIcon } from "@heroicons/react/24/outline";
import { UserIcon } from "@heroicons/react/24/outline";
import { ClipboardDocumentCheckIcon } from "@heroicons/react/24/outline";
import { useDispatch } from "react-redux";
import { useSelector } from "react-redux";
import { useDispatch, useSelector } from "react-redux";
import { useNavigate } from "react-router-dom";
import { uiActions } from "../../store/uiSlice";
import { userActions } from "@/store/userSlice";
import Unlimited from "../../assets/unlimited.png";
import SignOutButton from "../auth/SignOutButton";
import UserMenu from "../userMenu/UserMenu";

export default function Navbar() {
const dispatch = useDispatch();
const navigate = useNavigate();
const sidebarOpen = useSelector((state) => state.ui.sidebarOpen);
const recipesOpen = useSelector((state) => state.ui.recipesOpen);
const [dropDownOpen, setDropDownOpen] = useState(false);

function handleSidebar() {
dispatch(uiActions.openSidebar());
}
Expand All @@ -23,6 +28,17 @@ export default function Navbar() {
dispatch(userActions.emptyChat());
navigate("/");
}
const toggleDropDown = () => {
setDropDownOpen(!dropDownOpen);
};


function roleName() {
let role = useSelector((state) => state.user.role.type);
console.log(role);
return role;
}

return (
<nav className="">
<ul className={`flex flex-row w-full py-3 justify-between sticky`}>
Expand All @@ -39,7 +55,10 @@ export default function Navbar() {
className="size-10 rounded-xl hover:bg-gray-100 hover:cursor-pointer p-2"
onClick={handleNewChat}
/>
<h2 className="font-semibold text-xl">Meal Master</h2>
<h2 className="font-semibold text-xl flex flex-row justify-center content-center text-center h-full">
<span className="text-center px-2 py-1">Meal Master </span>
<span className={`${roleName() === "Free" ? "bg-gray-200" : "bg-orange-200"} text-gray-900 rounded-full px-4 py-1`}>{roleName()}</span>
</h2>
{/* <h2 className="font-semibold text-xl flex flex-row justify-center items-center text-center content-center gap-2">
<div className="flex justify-center items-center text-center border-2 border-orange-300 text-black p-3 font-semibold text-xl rounded-full w-fit h-10">
Meal Master
Expand All @@ -51,7 +70,10 @@ export default function Navbar() {
sidebarOpen ? "block" : "hidden"
}`}
>
<h2 className="font-semibold text-xl">Meal Master</h2>
<h2 className="font-semibold text-xl flex flex-row justify-center content-center text-center h-full">
<span className="text-center px-2 py-1">Meal Master </span>
<span className={`${roleName() === "Free" ? "bg-gray-200" : "bg-orange-200"} text-gray-900 rounded-full px-4 py-1`}>{roleName()}</span>
</h2>
{/* <h2 className="font-semibold text-xl flex flex-row justify-center items-center text-center content-center gap-2">
<div className="flex justify-center items-center text-center border-2 border-orange-300 text-black p-3 font-semibold text-xl rounded-full w-fit h-10">
Meal Master
Expand All @@ -67,7 +89,13 @@ export default function Navbar() {
className="size-10 rounded-xl hover:bg-gray-100 hover:cursor-pointer p-2"
onClick={handleRecipes}
/>
<UserIcon className="size-10 rounded-xl hover:bg-gray-100 hover:cursor-pointer p-2" />
<div className="relative">
<UserIcon
className="size-10 rounded-xl hover:bg-gray-100 hover:cursor-pointer p-2"
onClick={toggleDropDown}
/>
<UserMenu isOpen={dropDownOpen} toggleDropDown={toggleDropDown}/>
</div>
</li>
</ul>
</nav>
Expand Down
12 changes: 11 additions & 1 deletion src/client/CookingAppReact/src/components/sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export default function Sidebar() {
navigate("/subscribtion");
}

function isAdmin() {
let role = useSelector(state => state.user.role.type);
console.log(role);
if(role === "Admin"){
return true;
}else {
return false;
}
}

return (
<section
className={`bg-gray-100 flex flex-col flex-shrink-0 ${
Expand All @@ -88,7 +98,7 @@ export default function Sidebar() {
Get Premium
</h5>
</button>
<button onClick={handleClickDashboard}>
<button className={`${isAdmin() ? "hi :)" : "hidden"}`} onClick={handleClickDashboard}>
<h5 className="hover:bg-gray-300 mt-5 rounded-lg m-3 px-5 py-2 flex flex-row justify-start items-center hover:cursor-pointer isolate bg-white/20 shadow-sm ring-1 ring-black/5">
<ChartPieIcon className="size-5 mr-5" />
Dashboard
Expand Down
75 changes: 75 additions & 0 deletions src/client/CookingAppReact/src/components/userMenu/UserMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import "tailwindcss/tailwind.css";
import React from "react";
import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux";
import { FaUtensils, FaCreditCard, FaCog } from "react-icons/fa";
import SignOutButton from "../auth/SignOutButton";

const UserMenu = ({ isOpen, toggleDropDown }) => {
const navigate = useNavigate();
const isDarkTheme = useSelector(state => state.ui.isDarkTheme);

if (!isOpen) return null;

return (
<div
onClick={event => event.stopPropagation()}
className={`absolute right-10 top-12 w-64
${isDarkTheme ? "bg-[#2F2F2F]" : "bg-white"}
border border-gray-300 rounded-md shadow-lg z-20`}
>
<div className="flex flex-col p-4">
<div className="flex flex-col items-start w-full space-y-2">
<div
className={`flex items-center w-full cursor-pointer p-2
${isDarkTheme ? 'hover:bg-[#424242]' : 'hover:bg-gray-100'} hover:rounded`}
onClick={() => { navigate("/recipes"); toggleDropDown(); }}
title="Recipes"
>
<FaUtensils
className="w-6 h-6 mr-4"
color={isDarkTheme ? "white" : "black"}
/>
<span className={`${isDarkTheme ? "text-white" : "text-black"}`}>
Recipes
</span>
</div>
<div
className={`flex items-center w-full cursor-pointer p-2
${isDarkTheme ? 'hover:bg-[#424242]' : 'hover:bg-gray-100'} hover:rounded`}
onClick={() => { navigate("/subscription"); toggleDropDown(); }}
title="Subscription"
>
<FaCreditCard
className="w-6 h-6 mr-4"
color={isDarkTheme ? "white" : "black"}
/>
<span className={`${isDarkTheme ? "text-white" : "text-black"}`}>
Subscription
</span>
</div>
<div
className={`flex items-center w-full cursor-pointer p-2
${isDarkTheme ? 'hover:bg-[#424242]' : 'hover:bg-gray-100'} hover:rounded`}
onClick={() => { navigate("/settings"); toggleDropDown(); }}
title="Settings"
>
<FaCog
className="w-6 h-6 mr-4"
color={isDarkTheme ? "white" : "black"}
/>
<span className={`${isDarkTheme ? "text-white" : "text-black"}`}>
Settings
</span>
</div>
</div>
<hr className={`w-full mt-2 mb-2 ${isDarkTheme ? 'border-[#3C3C3C]' : 'border-gray-200'}`} />
<div className={`p-2 ${isDarkTheme ? 'hover:bg-[#424242]' : 'hover:bg-gray-100'} hover:rounded`}>
<SignOutButton/>
</div>
</div>
</div>
);
};

export default UserMenu;
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import "tailwindcss/tailwind.css";
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { FaUserCircle, FaLeaf, FaArchive, FaLanguage, FaFileAlt, FaInfoCircle, FaEnvelope, FaBars, FaTimes } from "react-icons/fa";

const Settings = () => {
const dispatch = useDispatch();
const photoUri = useSelector(state => state.ui.photoUri);
const [selectedMenu, setSelectedMenu] = useState('food-preferences');
const [ContentComponent, setContentComponent] = useState(null);

useEffect(() => {
const loadContent = async () => {
const components = {
'food-preferences': () => import('./foodPreferences/FoodPreferences'),
// 'archived-recipes': () => import('@/app/archived-recipes/page'),
// 'language-theme': () => import('@/app/language-theme/page'),
// 'rules-policies': () => import('@/app/rules-policies/page'),
// 'about': () => import('@/app/about/page'),
'contacts': () => import('./contacts/Contacts')
};

if (components[selectedMenu]) {
const { default: Component } = await components[selectedMenu]();
setContentComponent(() => Component);
}
}
loadContent();
}, [selectedMenu]);

const menuItems = [
{ id: "food-preferences", icon: FaLeaf, label: "Food Preferences" },
{ id: "archived-recipes", icon: FaArchive, label: "Archived Recipes" },
{ id: "language-theme", icon: FaLanguage, label: "Language & Theme" },
{ id: "rules-policies", icon: FaFileAlt, label: "Rules And Policies" },
{ id: "about", icon: FaInfoCircle, label: "About" },
{ id: "contacts", icon: FaEnvelope, label: "Contacts" }
];

// const handleImageUpload = event => {
// const file = event.target.files[0];
// if (file) {
// const reader = new FileReader();
// reader.onloadend = () => {
// const result = reader.result;
// dispatch(uiActions.setPhotoUri(result));
// if (typeof window !== "undefined") {
// localStorage.setItem("photoUri", result);
// }
// };
// reader.readAsDataURL(file);
// }
// };

return (
<div className={`h-auto w-full
border-gray-300 flex px-10`}>
{/* <div className="md:flex hidden flex-col p-4 w-1/4"> */}
<div className="flex flex-col p-4 w-1/4">
<div className="flex w-full mb-8 relative">
{photoUri ? (
<img
src={photoUri}
alt="Profile"
className="w-24 h-24 rounded-full object-cover cursor-pointer"
onClick={() => document.getElementById("fileInput").click()}
/>
) : (
<FaUserCircle
className="w-24 h-24 cursor-pointer"
onClick={() => document.getElementById("fileInput").click()}
/>
)}
<input
type="file"
id="fileInput"
accept="image/*"
style={{ display: "none" }}
// onChange={handleImageUpload}
/>
</div>
<div className="flex gap-2 flex-col items-start w-full space-y-2">
{menuItems.map(item => (
<div
key={item.id}
className={`flex items-center w-full cursor-pointer p-2 rounded
`}
onClick={() => setSelectedMenu(item.id)}
title={item.label}
>
<item.icon
className="w-6 h-6 mr-4"

/>
<span
className={`text-lg `}>{item.label}
</span>
</div>
))}
</div>
</div>
{/* <div className="md:hidden flex flex-col w-full">
<div className="flex justify-between p-4">
<div className="flex items-center">
{photoUri ? (
<img
src={photoUri}
alt="Profile"
className="w-10 h-10 rounded-full object-cover cursor-pointer"
onClick={() => document.getElementById("fileInput").click()}
/>
) : (
<FaUserCircle
className="w-10 h-10 cursor-pointer"
color={isDarkTheme ? "white" : "black"}
onClick={() => document.getElementById("fileInput").click()}
/>
)}
<input
type="file"
id="fileInput"
accept="image/*"
style={{ display: "none" }}
onChange={handleImageUpload}
/>
</div>
<div className="flex items-center">
<button onClick={() => setHamMenuOpen(!hamMenuOpen)}>
{hamMenuOpen ? <FaTimes className="w-6 h-6" /> : <FaBars className="w-6 h-6" />}
</button>
</div>
</div>
{hamMenuOpen && (
<div className="flex flex-col p-4">
{menuItems.map(item => (
<div
key={item.id}
className={`flex items-center w-full cursor-pointer p-2 rounded ${selectedMenu === item.id ? isDarkTheme ? "bg-[#424242]" : " bg-[#b2b2b2]" : ""}`}
onClick={() => { setSelectedMenu(item.id); setHamMenuOpen(false); }}
title={item.label}
>
<item.icon className="w-6 h-6 mr-4" color={selectedMenu === item.id ? "white" : isDarkTheme ? "white" : "black"} />
<span className={`text-lg ${selectedMenu === item.id ? "text-white" : isDarkTheme ? "text-white" : "text-black"}`}>{item.label}</span>
</div>
))}
</div>
)}
</div> */}
<div className="flex-1 p-4">
{ContentComponent && <ContentComponent />}
</div>
</div>
);
};

export default Settings;
Loading

0 comments on commit 47b0c39

Please sign in to comment.