Bläddra i källkod

add the dashboardguard, sidebar, errorpage, and fix other bugs

gdias 5 månader sedan
förälder
incheckning
214a8a6f78

+ 1 - 0
src/lib/assets/beer_green.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#10B981"><path d="M540-401ZM400-121v-80h280v-399h-80q-28 0-49.5 17.5T510-545q-23 26-50.5 47T400-467v147h-80v-146q-53-14-86.5-56T200-621q0-51 30-92.5t79-58.5q23-50 69-79t102-29q33 0 63.5 11.5T600-835q10-2 19.5-3.5T640-840q66 0 113 46.5T800-680q0 21-6 41.5T777-600l62-1q34-1 57.5 22.5T920-521v240q0 33-23.5 56.5T840-201h-80v80H400Zm-40-419q23 0 41.5-13.5T437-584l56-57q21-21 49-30t58-9h119q0-33-23.5-56.5T639-760q-12 0-24 1.5t-23 6.5l-12 4-31-26q-14-12-32-19t-37-7q-32 0-58.5 17T381-737l-15 31-32 10q-24 9-39 29.5T280-620q0 33 23 56.5t57 23.5Zm400 259h80v-240h-80v240ZM160-160h240v-80H160v80Zm0 80q-33 0-56.5-23.5T80-160v-160h400v160q0 33-23.5 56.5T400-80H160Zm0-80h240-240Z"/></svg>

+ 1 - 0
src/lib/assets/close_icon.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="m336-280-56-56 144-144-144-143 56-56 144 144 143-144 56 56-144 143 144 144-56 56-143-144-144 144Z"/></svg>

+ 1 - 0
src/lib/assets/kitchen_icon.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="M177-560q14-36 4.5-64T149-680q-33-40-43.5-75.5T102-840h78q-8 38-2.5 62t28.5 52q38 46 48.5 81.5t.5 84.5h-78Zm160 0q14-36 5-64t-32-56q-33-40-44-75.5t-4-84.5h78q-8 38-2.5 62t28.5 52q38 46 48.5 81.5t.5 84.5h-78Zm160 0q14-36 5-64t-32-56q-33-40-44-75.5t-4-84.5h78q-8 38-2.5 62t28.5 52q38 46 48.5 81.5t.5 84.5h-78ZM200-160q-50 0-85-35t-35-85v-200h561q5-34 27-59.5t54-36.5l185-62 25 76-185 62q-12 4-19.5 14.5T720-462v182q0 50-35 85t-85 35H200Zm0-80h400q17 0 28.5-11.5T640-280v-120H160v120q0 17 11.5 28.5T200-240Zm200-80Z"/></svg>

+ 1 - 0
src/lib/assets/logout_icon.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#EF4444"><path d="M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h280v80H200v560h280v80H200Zm440-160-55-58 102-102H360v-80h327L585-622l55-58 200 200-200 200Z"/></svg>

+ 1 - 0
src/lib/assets/mananger.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="M400-480q-66 0-113-47t-47-113q0-66 47-113t113-47q66 0 113 47t47 113q0 66-47 113t-113 47ZM80-160v-112q0-33 17-62t47-44q51-26 115-44t141-18h14q6 0 12 2-8 18-13.5 37.5T404-360h-4q-71 0-127.5 18T180-306q-9 5-14.5 14t-5.5 20v32h252q6 21 16 41.5t22 38.5H80Zm560 40-12-60q-12-5-22.5-10.5T584-204l-58 18-40-68 46-40q-2-14-2-26t2-26l-46-40 40-68 58 18q11-8 21.5-13.5T628-460l12-60h80l12 60q12 5 22.5 11t21.5 15l58-20 40 70-46 40q2 12 2 25t-2 25l46 40-40 68-58-18q-11 8-21.5 13.5T732-180l-12 60h-80Zm40-120q33 0 56.5-23.5T760-320q0-33-23.5-56.5T680-400q-33 0-56.5 23.5T600-320q0 33 23.5 56.5T680-240ZM400-560q33 0 56.5-23.5T480-640q0-33-23.5-56.5T400-720q-33 0-56.5 23.5T320-640q0 33 23.5 56.5T400-560Zm0-80Zm12 400Z"/></svg>

+ 1 - 0
src/lib/assets/menu_icon.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="M120-680v-80h720v80H120Zm0 480v-80h720v80H120Zm0-240v-80h720v80H120Z"/></svg>

+ 1 - 0
src/lib/assets/product_sell.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="M856-390 570-104q-12 12-27 18t-30 6q-15 0-30-6t-27-18L103-457q-11-11-17-25.5T80-513v-287q0-33 23.5-56.5T160-880h287q16 0 31 6.5t26 17.5l352 353q12 12 17.5 27t5.5 30q0 15-5.5 29.5T856-390ZM513-160l286-286-353-354H160v286l353 354ZM260-640q25 0 42.5-17.5T320-700q0-25-17.5-42.5T260-760q-25 0-42.5 17.5T200-700q0 25 17.5 42.5T260-640Zm220 160Z"/></svg>

+ 1 - 0
src/lib/assets/report_icon.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="M80-120v-80h800v80H80Zm40-120v-280h120v280H120Zm200 0v-480h120v480H320Zm200 0v-360h120v360H520Zm200 0v-600h120v600H720Z"/></svg>

+ 1 - 0
src/lib/assets/table_bar.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#9CA3AF"><path d="m240-160 60-150q9-23 29-36.5t45-13.5h66v-161q-153-5-256.5-45T80-660q0-58 117-99t283-41q167 0 283.5 41T880-660q0 54-103.5 94T520-521v161h66q24 0 44.5 13.5T660-310l60 150h-80l-48-120H368l-48 120h-80Zm240-440q97 0 183-17t126-43q-40-26-126-43t-183-17q-97 0-183 17t-126 43q40 26 126 43t183 17Zm0-60Z"/></svg>

+ 18 - 0
src/lib/component/DashBoardGuard.svelte

@@ -0,0 +1,18 @@
+<script>
+	import { onMount } from 'svelte';
+	import { goto } from '$app/navigation';
+	import user from '$lib/utils/data.json';
+	let autorizado = false;
+
+	onMount(async () => {
+		if (user.flag === 'b' || user.flag === '') {
+			goto('/login');
+		} else {
+			autorizado = true;
+		}
+	});
+</script>
+
+{#if autorizado}
+	<slot />
+{/if}

+ 29 - 27
src/lib/layout/SideBar.svelte

@@ -3,6 +3,10 @@
 	import { goto } from '$app/navigation';
 	import { get } from 'svelte/store';
 	import { onMount } from 'svelte';
+	import beer_green from '$lib/assets/beer_green.svg';
+	import logout_icon from '$lib/assets/logout_icon.svg';
+	import close_icon from '$lib/assets/close_icon.svg';
+	import menu_icon from '$lib/assets/menu_icon.svg';
 	//import { logout } from '../lib/auth'; // Você precisa criar esse arquivo
 
 	let flagUser = 'admin';
@@ -13,11 +17,11 @@
 			navItems = [{ name: 'Mesas', path: '/dashboard/tables' }];
 		} else if (flagUser == 'admin') {
 			navItems = [
-				{ name: 'Mesas', path: '/dashboard/tables' },
-				{ name: 'Produtos', path: '/dashboard/products' },
-				{ name: 'Relatórios', path: '/dashboard/reports' },
-				{ name: 'Cozinha', path: '/dashboard/cozinha' },
-				{ name: 'Gerenciar Usuários', path: '/dashboard/control' }
+				{ name: 'Mesas', path: '/dashboard/tables', icon: 'table_bar' },
+				{ name: 'Produtos', path: '/dashboard/products', icon: 'product_sell' },
+				{ name: 'Relatórios', path: '/dashboard/reports', icon: 'report_icon' },
+				{ name: 'Cozinha', path: '/dashboard/cozinha', icon: 'kitchen_icon' },
+				{ name: 'Gerenciar Usuários', path: '/dashboard/control', icon: 'mananger' }
 			];
 		} else if (flagUser == 'kitchen') {
 			navItems = [{ name: 'Cozinha', path: '/dashboard/cozinha' }];
@@ -38,12 +42,10 @@
 </script>
 
 <div class="flex h-screen bg-gray-900 text-white">
-	<!-- Sidebar Desktop -->
 	<div class="hidden w-64 flex-col border-r border-gray-700 bg-gray-800 md:flex">
-		<div class="ml-4 flex h-16 items-center justify-center border-b border-gray-700">
-			<!-- <img src="/icons/layers.svg" alt="Logo" class="w-8 h-8 mr-2" /> -->
-			<div class="mr-2 h-8 w-8 rounded bg-emerald-500"></div>
-			<h1 class="text-xl font-semibold">Bar Management System</h1>
+		<div class=" flex h-16 items-center justify-center border-b border-gray-700">
+			<img src={beer_green} alt="Logo" class="mr-2 h-8 w-8" />
+			<h1 class="text-xl font-semibold">Bar do Ferlin</h1>
 		</div>
 		<div class="flex flex-1 flex-col overflow-y-auto">
 			<nav class="flex-1 space-y-2 px-2 py-4">
@@ -56,8 +58,11 @@
 						}`}
 						on:click={() => goto(item.path)}
 					>
-						<!-- <img src="/icons/${item.name.toLowerCase()}.svg" class="w-6 h-6" alt={item.name} /> -->
-						<div class="h-6 w-6 rounded bg-gray-500"></div>
+						<img
+							src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
+							class="h-6 w-6"
+							alt={item.name}
+						/>
 						<span class="ml-3">{item.name}</span>
 					</button>
 				{/each}
@@ -68,16 +73,14 @@
 				class="flex w-full items-center justify-center rounded-lg px-4 py-2 text-sm text-red-400 transition-colors hover:bg-gray-700"
 				on:click={handleLogout}
 			>
-				<!-- <img src="/icons/logout.svg" class="w-5 h-5 mr-2" alt="Logout" /> -->
-				<div class="mr-2 h-5 w-5 rounded bg-red-500"></div>
+				<img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
 				<span>Sair</span>
 			</button>
 		</div>
 	</div>
 
-	<!-- Conteúdo + Header Mobile -->
+	<!-- Header Mobile -->
 	<div class="flex flex-1 flex-col">
-		<!-- Mobile Header -->
 		<header
 			class="sticky top-0 z-10 flex h-16 items-center justify-between border-b border-gray-700 bg-gray-800 px-6 md:hidden"
 		>
@@ -87,17 +90,14 @@
 					on:click={() => (isMobileMenuOpen = !isMobileMenuOpen)}
 				>
 					{#if isMobileMenuOpen}
-						<!-- <img src="/icons/close.svg" class="w-6 h-6" alt="Fechar" /> -->
-						<div class="h-6 w-6 rounded bg-gray-400"></div>
+						<img src={close_icon} class="h-6 w-6" alt="Fechar" />
 					{:else}
-						<!-- <img src="/icons/menu.svg" class="w-6 h-6" alt="Menu" /> -->
-						<div class="h-6 w-6 rounded bg-gray-400"></div>
+						<img src={menu_icon} class="h-6 w-6" alt="Menu" />
 					{/if}
 				</button>
 				<div class="flex items-center">
-					<!-- <img src="/icons/layers.svg" class="w-7 h-7 mr-2 text-emerald-500" alt="Logo" /> -->
-					<div class="mr-2 h-7 w-7 rounded bg-emerald-500"></div>
-					<h1 class="text-lg font-semibold">Bar Management System</h1>
+					<img src={beer_green} class="mr-2 h-7 w-7 text-emerald-500" alt="Logo" />
+					<h1 class="text-lg font-semibold">Bar do Ferlin</h1>
 				</div>
 			</div>
 		</header>
@@ -115,8 +115,11 @@
 							}`}
 							on:click={() => navigate(item.path)}
 						>
-							<!-- <img src="/icons/${item.name.toLowerCase()}.svg" class="w-6 h-6" alt={item.name} /> -->
-							<div class="h-6 w-6 rounded bg-gray-500"></div>
+							<img
+								src="../src/lib/assets/{item.icon.toLowerCase()}.svg"
+								class="h-6 w-6"
+								alt={item.name}
+							/>
 							<span class="ml-3">{item.name}</span>
 						</button>
 					{/each}
@@ -124,8 +127,7 @@
 						class="flex items-center rounded-lg px-4 py-3 text-sm text-red-400 transition-colors hover:bg-gray-700"
 						on:click={handleLogout}
 					>
-						<!-- <img src="/icons/logout.svg" class="w-5 h-5 mr-2" alt="Logout" /> -->
-						<div class="mr-2 h-5 w-5 rounded bg-red-500"></div>
+						<img src={logout_icon} class="mr-2 h-5 w-5" alt="Logout" />
 						<span>Sair</span>
 					</button>
 				</nav>

+ 4 - 0
src/lib/utils/data.json

@@ -0,0 +1,4 @@
+{
+	"name": "gabriel",
+	"flag": "waiter"
+}

+ 10 - 0
src/routes/+error.svelte

@@ -0,0 +1,10 @@
+<script>
+	import { goto } from '$app/navigation';
+	import { onMount } from 'svelte';
+	function handleErrorPage() {
+		goto('/');
+	}
+	onMount(() => {
+		handleErrorPage();
+	});
+</script>

+ 4 - 1
src/routes/dashboard/tables/+page.svelte

@@ -1,5 +1,8 @@
 <script>
 	import SideBar from '$lib/layout/SideBar.svelte';
+	import DashBoardGuard from '$lib/component/DashBoardGuard.svelte';
 </script>
 
-<SideBar />
+<DashBoardGuard>
+	<SideBar />
+</DashBoardGuard>