From 5fc8e5a5582ba685414488f00a2b1d231bec7b5d Mon Sep 17 00:00:00 2001 From: lucasgfaj Date: Mon, 8 Jun 2026 14:52:23 -0300 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20corrige=20flash=20messages,=20timeou?= =?UTF-8?q?t=20SSH,=20dele=C3=A7=C3=A3o=20de=20visitantes=20e=20role=20por?= =?UTF-8?q?=20departamento?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/UsersController.php | 11 ++-- .../Controllers/VisitorTypeController.php | 9 ++- app/Models/User.php | 5 ++ app/Services/SambaService.php | 5 +- app/Services/VisitorService.php | 2 +- resources/js/layouts/app-layout.tsx | 3 +- resources/js/pages/users/create.tsx | 21 ------- resources/js/pages/users/edit.tsx | 59 +++---------------- resources/js/pages/visitors/create.tsx | 17 +----- resources/js/pages/visitors/edit.tsx | 30 +--------- resources/js/pages/visitors/index.tsx | 15 ----- resources/js/pages/visitors/show.tsx | 14 ----- resources/js/pages/vouchers/index.tsx | 17 ------ 13 files changed, 35 insertions(+), 173 deletions(-) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 73c3fd4..cedbfc8 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -56,14 +56,13 @@ public function edit(User $user) public function update(Request $request, User $user) { $request->validate([ - 'role' => ['required', 'in:admin,operator'], - 'enabled' => ['required', 'boolean'], + 'active' => ['required', 'in:0,1'], ]); - $user->update([ - 'role' => $request->role, - 'enabled' => $request->enabled, - ]); + $user->load('department'); + $user->syncRoleFromDepartment(); + $user->enabled = $request->active === '1'; + $user->save(); return redirect()->route('users.index'); } diff --git a/app/Http/Controllers/VisitorTypeController.php b/app/Http/Controllers/VisitorTypeController.php index 5ca6d87..c19a573 100644 --- a/app/Http/Controllers/VisitorTypeController.php +++ b/app/Http/Controllers/VisitorTypeController.php @@ -61,7 +61,8 @@ public function store(Request $request, ActivityLogInterface $activityLogService auth()->id() ); - return redirect()->route('visitorTypes.index'); + return redirect()->route('visitorTypes.index') + ->with('success', 'Tipo de visitante criado com sucesso.'); } public function edit(VisitorType $visitorType) @@ -80,7 +81,8 @@ public function update(Request $request, VisitorType $visitorType) $visitorType->update($request->only(['name', 'description'])); - return redirect()->route('visitorTypes.index'); + return redirect()->route('visitorTypes.index') + ->with('success', 'Tipo de visitante atualizado com sucesso.'); } public function destroy(VisitorType $visitorType, ActivityLogInterface $activityLogService) @@ -94,6 +96,7 @@ public function destroy(VisitorType $visitorType, ActivityLogInterface $activity auth()->id() ); - return redirect()->route('visitorTypes.index'); + return redirect()->route('visitorTypes.index') + ->with('success', 'Tipo de visitante excluído com sucesso.'); } } diff --git a/app/Models/User.php b/app/Models/User.php index a7d2bb6..22721af 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -62,6 +62,11 @@ public function belongsToDepartment(Department $department): bool return $this->department_id === $department->id; } + public function syncRoleFromDepartment(): void + { + $this->role = $this->department?->name === 'COGETI' ? 'admin' : 'operator'; + } + /** * Verifica se é admin pelo papel vindo do AD */ diff --git a/app/Services/SambaService.php b/app/Services/SambaService.php index 77d804d..db58a73 100644 --- a/app/Services/SambaService.php +++ b/app/Services/SambaService.php @@ -14,6 +14,8 @@ class SambaService implements SambaInterface protected string $keyPath; protected int $port; protected bool $debug = true; + protected int $timeout = 10; + protected int $connectionTimeout = 5; public function __construct() { @@ -25,7 +27,8 @@ public function __construct() protected function connect(): SSH2 { - $ssh = new SSH2($this->host, $this->port); + $ssh = new SSH2($this->host, $this->port, $this->connectionTimeout); + $ssh->setTimeout($this->timeout); $key = PublicKeyLoader::loadPrivateKey( file_get_contents($this->keyPath) diff --git a/app/Services/VisitorService.php b/app/Services/VisitorService.php index e0fd894..393a29d 100644 --- a/app/Services/VisitorService.php +++ b/app/Services/VisitorService.php @@ -128,7 +128,7 @@ public function delete(Visitor $visitor, int $userId): void if (!$result['success']) { $errorMsg = $result['error'] ?? 'Erro desconhecido'; - if (stripos($errorMsg, 'NT_STATUS_NO_SUCH_USER') !== false || stripos($errorMsg, 'not found') !== false) { + if (stripos($errorMsg, 'NT_STATUS_NO_SUCH_USER') !== false || stripos($errorMsg, 'not found') !== false || stripos($errorMsg, 'Unable to find user') !== false) { \Log::warning('Usuário SAMBA não encontrado, continuando remoção local', ['login' => $login]); } else { \Log::error('Erro ao deletar usuário SAMBA', [ diff --git a/resources/js/layouts/app-layout.tsx b/resources/js/layouts/app-layout.tsx index 4bd452a..b2303b2 100644 --- a/resources/js/layouts/app-layout.tsx +++ b/resources/js/layouts/app-layout.tsx @@ -15,7 +15,8 @@ interface PageProps { } export default function AppLayout({ children, breadcrumbs, ...props }: AppLayoutProps) { - const { flash, errors } = usePage() + const { props: pageProps } = usePage<{ flash?: { success?: string; error?: string }; errors?: { error?: string } }>(); + const { flash, errors } = pageProps useEffect(() => { if (flash?.success) { diff --git a/resources/js/pages/users/create.tsx b/resources/js/pages/users/create.tsx index 02b27f7..68ff598 100644 --- a/resources/js/pages/users/create.tsx +++ b/resources/js/pages/users/create.tsx @@ -23,7 +23,6 @@ export default function CreateUser({ departments }: { departments: Array<{ id: n name: '', email: '', password: '', - role: 'operator', // default department_id: departments.length ? String(departments[0].id) : '', }); @@ -90,26 +89,6 @@ export default function CreateUser({ departments }: { departments: Array<{ id: n )} - {/* Role */} -
- - - {errors.role && ( -

{errors.role}

- )} -
- {/* Departamento */}
diff --git a/resources/js/pages/users/edit.tsx b/resources/js/pages/users/edit.tsx index 9784914..cb75aec 100644 --- a/resources/js/pages/users/edit.tsx +++ b/resources/js/pages/users/edit.tsx @@ -1,50 +1,26 @@ import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from '@/components/ui/select'; import AppLayout from '@/layouts/app-layout'; import users from '@/routes/users'; import { type BreadcrumbItem } from '@/types'; -import { Head, Link, useForm } from '@inertiajs/react'; +import { Head, Link } from '@inertiajs/react'; interface User { id: number; role: string; - active: boolean | string; name: string; email: string; username: string; department: { name: string }; } -interface AuthUser { - id: number; -} - -export default function EditUsers({ user, authUser }: { user: User; authUser: AuthUser }) { - const isSelf = Number(authUser.id) === Number(user.id); - +export default function EditUsers({ user }: { user: User }) { const breadcrumbs: BreadcrumbItem[] = [ { title: 'Usuários', href: users.index.get().url }, { title: 'Editar', href: '#' }, ]; - const { data, setData, put, errors } = useForm({ - role: user.role, - active: user.active ? '1' : '0', - }); - - const submit = (e: React.FormEvent) => { - e.preventDefault(); - put(users.update({ user: user.id }).url); - }; - return ( @@ -52,8 +28,7 @@ export default function EditUsers({ user, authUser }: { user: User; authUser: Au

Editar Usuário

-
- +
@@ -76,35 +51,19 @@ export default function EditUsers({ user, authUser }: { user: User; authUser: Au
- - - {errors.role && ( -

{errors.role}

- )} +
- - {/* */}
- +
); diff --git a/resources/js/pages/visitors/create.tsx b/resources/js/pages/visitors/create.tsx index 30dbb77..8bc63d2 100644 --- a/resources/js/pages/visitors/create.tsx +++ b/resources/js/pages/visitors/create.tsx @@ -16,7 +16,6 @@ import { maskCPF, maskPhone } from '@/utils/masks'; import { Head, Link, useForm } from '@inertiajs/react'; import { useEffect } from 'react'; import { toast } from 'sonner'; -import { Toaster } from '@/components/ui/sonner'; export default function CreateVisitor({ types }: { types: Array<{ id: number; name: string }> }) { @@ -55,20 +54,7 @@ export default function CreateVisitor({ types }: { types: Array<{ id: number; na return; } - post(visitors.store.post().url, { - onSuccess: (page) => { - const success = page.props.flash?.success; - if (success) { - toast.success(success); - } - }, - onError: (errors) => { - const firstError = Object.values(errors)[0]; - if (firstError) { - toast.error(String(firstError)); - } - }, - }); + post(visitors.store.post().url); }; useEffect(() => { @@ -87,7 +73,6 @@ export default function CreateVisitor({ types }: { types: Array<{ id: number; na return ( -

Criar Visitante

diff --git a/resources/js/pages/visitors/edit.tsx b/resources/js/pages/visitors/edit.tsx index 1730c22..00c1ba8 100644 --- a/resources/js/pages/visitors/edit.tsx +++ b/resources/js/pages/visitors/edit.tsx @@ -12,10 +12,9 @@ import { import AppLayout from '@/layouts/app-layout'; import visitors from '@/routes/visitors'; import { type BreadcrumbItem } from '@/types'; -import { Head, Link, router, useForm, usePage } from '@inertiajs/react'; -import React, { useEffect } from 'react'; +import { Head, Link, router, useForm } from '@inertiajs/react'; +import React from 'react'; import { toast } from 'sonner'; -import { Toaster } from '@/components/ui/sonner'; interface Visitor { id: number; @@ -30,18 +29,6 @@ interface Visitor { } export default function EditVisitor({ visitor, types }: { visitor: Visitor; types: Array<{ id: number; name: string }> }) { - const { props } = usePage<{ flash: { success?: string; error?: string } }>(); - const flash = props.flash; - - useEffect(() => { - if (flash.success) { - toast.success(flash.success); - } - if (flash.error) { - toast.error(flash.error); - } - }, [flash.success, flash.error]); - const breadcrumbs: BreadcrumbItem[] = [ { title: 'Visitantes', href: visitors.index.get().url }, { title: 'Editar', href: '#' }, @@ -78,25 +65,12 @@ export default function EditVisitor({ visitor, types }: { visitor: Visitor; type put(visitors.update({ visitor: visitor.id }).url, { preserveScroll: true, - onSuccess: (page) => { - const success = page.props.flash?.success; - if (success) { - toast.success(success); - } - }, - onError: (errors) => { - const firstError = Object.values(errors)[0]; - if (firstError) { - toast.error(String(firstError)); - } - }, }); }; return ( -

Editar Visitante

diff --git a/resources/js/pages/visitors/index.tsx b/resources/js/pages/visitors/index.tsx index 148ca7e..001285f 100644 --- a/resources/js/pages/visitors/index.tsx +++ b/resources/js/pages/visitors/index.tsx @@ -20,8 +20,6 @@ import debounce from "lodash.debounce"; import { Edit, Trash2, SlidersHorizontal, FileSpreadsheet } from "lucide-react"; import { shortenName } from "@/lib/utils"; import { useEffect, useState } from "react"; -import { toast } from "sonner"; -import { Toaster } from "@/components/ui/sonner"; interface Visitor { id: number; @@ -137,7 +135,6 @@ export default function VisitorsIndex() { return ( -
@@ -257,18 +254,6 @@ export default function VisitorsIndex() { onConfirm={() => router.delete(visitors.destroy(v.id).url, { preserveScroll: true, - onSuccess: (page) => { - const success = page.props.flash?.success; - if (success) { - toast.success(success); - } - }, - onError: (errors) => { - const firstError = Object.values(errors)[0]; - if (firstError) { - toast.error(String(firstError)); - } - }, }) } title="Excluir Visitante" diff --git a/resources/js/pages/visitors/show.tsx b/resources/js/pages/visitors/show.tsx index b5644ad..bd5518b 100644 --- a/resources/js/pages/visitors/show.tsx +++ b/resources/js/pages/visitors/show.tsx @@ -5,11 +5,8 @@ import AppLayout from '@/layouts/app-layout'; import visitors from '@/routes/visitors'; import { type BreadcrumbItem } from '@/types'; import { Head, Link, router, usePage } from '@inertiajs/react'; -import { useEffect } from 'react'; import { shortenName } from '@/lib/utils'; import { ArrowLeft, Edit, Mail, Calendar, Building, User, Send } from 'lucide-react'; -import { toast } from 'sonner'; -import { Toaster } from '@/components/ui/sonner'; interface Visitor { id: number; @@ -47,7 +44,6 @@ interface Props { export default function VisitorShow() { const { props } = usePage(); const { visitor } = props; - const flash = props.flash; const handleResend = () => { console.log('CLICOU NO BOTÃO REENVIAR'); @@ -57,15 +53,6 @@ export default function VisitorShow() { ); }; - useEffect(() => { - if (flash?.success) { - toast.success(flash.success); - } - if (flash?.error) { - toast.error(flash.error); - } - }, [flash?.success, flash?.error]); - const breadcrumbs: BreadcrumbItem[] = [ { title: 'Dashboard', href: '/dashboard' }, { title: 'Visitantes', href: visitors.index.get().url }, @@ -75,7 +62,6 @@ export default function VisitorShow() { return ( -
diff --git a/resources/js/pages/vouchers/index.tsx b/resources/js/pages/vouchers/index.tsx index a935a3b..0e7a3a9 100644 --- a/resources/js/pages/vouchers/index.tsx +++ b/resources/js/pages/vouchers/index.tsx @@ -17,8 +17,6 @@ import { Head, router, usePage } from "@inertiajs/react"; import debounce from "lodash.debounce"; import { SlidersHorizontal } from "lucide-react"; import { useEffect, useState } from "react"; -import { toast } from "sonner"; -import { Toaster } from "@/components/ui/sonner"; import { shortenName } from "@/lib/utils"; interface Voucher { @@ -52,10 +50,6 @@ interface PageProps { direction?: string; }; creators: unknown; - flash?: { - success?: string; - error?: string; - }; user_department_id: unknown; departments: unknown; } @@ -63,16 +57,6 @@ interface PageProps { export default function VouchersIndex() { const { props } = usePage<{ props: PageProps }>(); const { vouchers: paginated, filters, creators } = props; - const flash = props.flash; - - useEffect(() => { - if (flash?.success) { - toast.success(flash.success); - } - if (flash?.error) { - toast.error(flash.error); - } - }, [flash?.success, flash?.error]); const [search, setSearch] = useState(filters?.search || ""); const [showFilters, setShowFilters] = useState(false); @@ -154,7 +138,6 @@ export default function VouchersIndex() { return ( -
{/* HEADER */} From 8a662f09b5e3f4d10ce5d64f38e2c981db828c0a Mon Sep 17 00:00:00 2001 From: lucasgfaj Date: Mon, 8 Jun 2026 16:06:14 -0300 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20valida=C3=A7=C3=A3o=20de=20filtro=20?= =?UTF-8?q?de=20departamento=20em=20visitantes=20e=20endurecimento=20de=20?= =?UTF-8?q?regras=20de=20request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/UsersController.php | 4 +++- app/Http/Controllers/VisitorsController.php | 1 + app/Http/Controllers/VouchersController.php | 1 + app/Http/Requests/UserIndexRequest.php | 2 +- app/Http/Requests/VisitorIndexRequest.php | 1 + app/Http/Requests/VoucherIndexRequest.php | 2 +- app/Models/User.php | 6 +++++- app/Models/Voucher.php | 3 +-- resources/js/components/visitors/visitors-filters.tsx | 8 ++++---- resources/js/components/vouchers/vouchers-filters.tsx | 8 ++++---- resources/js/pages/visitors/index.tsx | 3 ++- resources/js/pages/vouchers/index.tsx | 3 ++- 12 files changed, 26 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index cedbfc8..6ffedd7 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -15,9 +15,11 @@ public function index(UserIndexRequest $request) { $filters = $request->validated(); + $user = auth()->user(); + $query = User::with('department') ->search($filters['search'] ?? null) - ->departmentFilter($filters['department_id'] ?? null) + ->departmentFilter($filters['department_id'] ?? null, $user) ->applyOrdering( $filters['order_name'] ?? null, $filters['order_created'] ?? null, diff --git a/app/Http/Controllers/VisitorsController.php b/app/Http/Controllers/VisitorsController.php index 5aa1d30..2d21f21 100644 --- a/app/Http/Controllers/VisitorsController.php +++ b/app/Http/Controllers/VisitorsController.php @@ -55,6 +55,7 @@ public function index(VisitorIndexRequest $request) 'filters' => $filters, 'types' => VisitorType::select(['id', 'name'])->get(), 'user_department_id' => $user->department_id, + 'is_admin' => $user->isAdmin(), 'departments' => Department::select(['id', 'name'])->get(), ]); } diff --git a/app/Http/Controllers/VouchersController.php b/app/Http/Controllers/VouchersController.php index 66de030..3f7aa0c 100644 --- a/app/Http/Controllers/VouchersController.php +++ b/app/Http/Controllers/VouchersController.php @@ -60,6 +60,7 @@ public function index(VoucherIndexRequest $request) 'creators' => User::select(['id', 'name'])->get(), 'departments' => Department::select(['id', 'name'])->get(), 'user_department_id' => $user->department_id, + 'is_admin' => $user->isAdmin(), ]); } diff --git a/app/Http/Requests/UserIndexRequest.php b/app/Http/Requests/UserIndexRequest.php index a642efd..24bd87f 100644 --- a/app/Http/Requests/UserIndexRequest.php +++ b/app/Http/Requests/UserIndexRequest.php @@ -23,7 +23,7 @@ public function rules(): array { return [ 'search' => ['nullable', 'string', 'max:255'], - 'type_id' => ['nullable', 'integer', 'exists:visitor_types,id'], + 'department_id' => ['nullable', 'integer', 'exists:departments,id'], 'order_name' => ['nullable', 'in:asc,desc'], 'order_created' => ['nullable', 'in:newest,oldest'], 'order_department' => ['nullable', 'integer'], diff --git a/app/Http/Requests/VisitorIndexRequest.php b/app/Http/Requests/VisitorIndexRequest.php index 02a3ae3..a7ef958 100644 --- a/app/Http/Requests/VisitorIndexRequest.php +++ b/app/Http/Requests/VisitorIndexRequest.php @@ -26,6 +26,7 @@ public function rules(): array 'search' => ['nullable', 'string', 'max:255'], 'type_id' => ['nullable', 'integer', 'exists:visitor_types,id'], 'department_id' => ['nullable', 'integer', 'exists:departments,id'], + 'order_department' => ['nullable', 'integer', 'exists:departments,id'], 'order_name' => ['nullable', 'in:asc,desc'], 'order_created' => ['nullable', 'in:newest,oldest'], 'sort' => ['nullable', 'in:id,name,created_at'], diff --git a/app/Http/Requests/VoucherIndexRequest.php b/app/Http/Requests/VoucherIndexRequest.php index 669483e..edf8531 100644 --- a/app/Http/Requests/VoucherIndexRequest.php +++ b/app/Http/Requests/VoucherIndexRequest.php @@ -25,7 +25,7 @@ public function rules(): array 'search' => ['nullable', 'string', 'max:255'], 'type_id' => ['nullable', 'integer', 'exists:visitor_types,id'], 'creator_id' => ['nullable', 'integer', 'exists:users,id'], - 'order_department' => ['nullable'], + 'order_department' => ['nullable', 'integer', 'exists:departments,id'], 'expire_sort' => ['nullable', 'in:closest,furthest'], 'created_sort' => ['nullable', 'in:newest,oldest'], 'sort' => ['nullable', 'string', 'in:id,created_at,expires_at,login'], diff --git a/app/Models/User.php b/app/Models/User.php index 22721af..c3b5a8d 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -99,8 +99,12 @@ public function scopeSearch(Builder $query, ?string $search): Builder }); } - public function scopeDepartmentFilter(Builder $query, ?int $departmentId): Builder + public function scopeDepartmentFilter(Builder $query, ?int $departmentId, ?User $authUser = null): Builder { + if ($authUser && !$authUser->isAdmin()) { + return $query->where('department_id', $authUser->department_id); + } + if (!$departmentId) { return $query; } diff --git a/app/Models/Voucher.php b/app/Models/Voucher.php index 9c9a136..227db31 100644 --- a/app/Models/Voucher.php +++ b/app/Models/Voucher.php @@ -48,8 +48,7 @@ public function scopeDepartmentFilter( User $user, ?int $departmentId ): Builder { - // COGETI - if ($user->department_id === 1) { + if ($user->isAdmin()) { if ($departmentId && $departmentId !== 'all') { return $query->whereHas( 'visitor.creator', diff --git a/resources/js/components/visitors/visitors-filters.tsx b/resources/js/components/visitors/visitors-filters.tsx index 12abccc..61f7bdf 100644 --- a/resources/js/components/visitors/visitors-filters.tsx +++ b/resources/js/components/visitors/visitors-filters.tsx @@ -13,7 +13,7 @@ interface VisitorsFiltersProps { types: Array<{ id: number; name: string }>; onChange: (filters: Record) => void; onClear: () => void; - userDepartmentId: number; + isAdmin: boolean; departments: Array<{ id: number; name: string }>; } @@ -22,7 +22,7 @@ export default function VisitorsFilters({ types, onChange, onClear, - userDepartmentId, + isAdmin, departments, }: VisitorsFiltersProps) { const [typeId, setTypeId] = useState(filters?.type_id ?? "all"); @@ -49,7 +49,7 @@ export default function VisitorsFilters({ params.order_created = orderCreated; } - if (userDepartmentId === 1 && orderDepartment !== "none") { + if (isAdmin && orderDepartment !== "none") { params.order_department = orderDepartment; } @@ -116,7 +116,7 @@ export default function VisitorsFilters({
{/* DEPARTAMENTO */} - {userDepartmentId === 1 && ( + {isAdmin && (
diff --git a/resources/js/pages/visitors/index.tsx b/resources/js/pages/visitors/index.tsx index 001285f..c88b5a6 100644 --- a/resources/js/pages/visitors/index.tsx +++ b/resources/js/pages/visitors/index.tsx @@ -47,6 +47,7 @@ interface PageProps { }; types: unknown; user_department_id: unknown; + is_admin: boolean; departments: unknown; } @@ -192,7 +193,7 @@ export default function VisitorsIndex() { types={types} onChange={handleFilterChange} onClear={handleFilterClear} - userDepartmentId={props.user_department_id} + isAdmin={props.is_admin} departments={props.departments} /> )} diff --git a/resources/js/pages/vouchers/index.tsx b/resources/js/pages/vouchers/index.tsx index 0e7a3a9..f0aa3b9 100644 --- a/resources/js/pages/vouchers/index.tsx +++ b/resources/js/pages/vouchers/index.tsx @@ -51,6 +51,7 @@ interface PageProps { }; creators: unknown; user_department_id: unknown; + is_admin: boolean; departments: unknown; } @@ -176,7 +177,7 @@ export default function VouchersIndex() { creators={creators} onChange={handleFilterChange} onClear={handleFilterClear} - userDepartmentId={props.user_department_id} + isAdmin={props.is_admin} departments={props.departments} /> )} From 96ce6f6d32fea5bac9ae69d2d74745acd3954e65 Mon Sep 17 00:00:00 2001 From: lucasgfaj Date: Mon, 8 Jun 2026 16:13:07 -0300 Subject: [PATCH 3/4] fix: substitui hardcoded department_id por isAdmin() no dashboard e adiciona total de vouchers --- app/Http/Controllers/DashboardController.php | 21 ++++++++++++++------ resources/js/pages/dashboard.tsx | 17 +++++++++++++++- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index c51f449..1ede8f3 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -22,7 +22,7 @@ public function index(Request $request) $queryBase = Visitor::query() ->whereHas('voucher'); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $queryBase->whereHas('creator', fn ($q) => $q->where('department_id', $user->department_id) ); @@ -30,6 +30,14 @@ public function index(Request $request) $totalVisitors = (clone $queryBase)->count(); + $voucherQuery = Voucher::query(); + if (!$user->isAdmin()) { + $voucherQuery->whereHas('visitor.creator', fn ($q) => + $q->where('department_id', $user->department_id) + ); + } + $totalVouchers = $voucherQuery->count(); + $totalThisMonth = (clone $queryBase) ->whereBetween('created_at', [ $today->copy()->startOfMonth(), @@ -42,7 +50,7 @@ public function index(Request $request) ->count(); $departments = Department::all(); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $departments = $departments->where('id', $user->department_id); } @@ -83,7 +91,7 @@ public function index(Request $request) ->where('expires_at', '>=', $today->startOfDay()) ->where('expires_at', '<', $today->copy()->addDays(8)); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $nextToExpireQuery->whereHas('visitor.creator', fn ($q) => $q->where('department_id', $user->department_id) ); @@ -101,7 +109,7 @@ public function index(Request $request) ->where('expires_at', '<', $today) ->whereHas('voucher'); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $alreadyExpiredQuery->whereHas('creator', fn ($q) => $q->where('department_id', $user->department_id) ); @@ -165,7 +173,7 @@ public function index(Request $request) $importStatsQuery = ImportBatch::query(); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $importStatsQuery->where('created_by', $user->id); } @@ -178,7 +186,7 @@ public function index(Request $request) $recentImportsQuery = ImportBatch::with('creator:id,name'); - if ($user->department_id !== 1) { + if (!$user->isAdmin()) { $recentImportsQuery->where('created_by', $user->id); } @@ -200,6 +208,7 @@ public function index(Request $request) return Inertia::render('dashboard', [ 'stats' => [ 'totalVisitors' => $totalVisitors, + 'totalVouchers' => $totalVouchers, 'totalThisMonth' => $totalThisMonth, 'expiredVisitors' => $expiredVisitors, ], diff --git a/resources/js/pages/dashboard.tsx b/resources/js/pages/dashboard.tsx index 7d9a980..54a9e4b 100644 --- a/resources/js/pages/dashboard.tsx +++ b/resources/js/pages/dashboard.tsx @@ -5,7 +5,7 @@ import { dashboard } from '@/routes'; import { type BreadcrumbItem } from '@/types'; import { usePage, router, Link } from '@inertiajs/react'; import { shortenName } from '@/lib/utils'; -import { Users, Calendar, Clock, AlertCircle, FileSpreadsheet, CheckCircle, XCircle } from 'lucide-react'; +import { Users, Calendar, Clock, AlertCircle, FileSpreadsheet, CheckCircle, XCircle, Receipt } from 'lucide-react'; import { useEffect } from 'react'; const breadcrumbs: BreadcrumbItem[] = [ @@ -17,6 +17,7 @@ const breadcrumbs: BreadcrumbItem[] = [ interface DashboardStats { totalVisitors: number; + totalVouchers: number; totalThisMonth: number; expiredVisitors: number; } @@ -130,6 +131,20 @@ export default function Dashboard() { + + + + Total de Vouchers + + + + +
+ {stats.totalVouchers} +
+
+
+ From 5d65faa1dc75d7c50c76c04ceb8ddf53e91d52ff Mon Sep 17 00:00:00 2001 From: lucasgfaj Date: Mon, 8 Jun 2026 16:18:21 -0300 Subject: [PATCH 4/4] fix:linter --- resources/js/layouts/app-layout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/layouts/app-layout.tsx b/resources/js/layouts/app-layout.tsx index b2303b2..5f9b619 100644 --- a/resources/js/layouts/app-layout.tsx +++ b/resources/js/layouts/app-layout.tsx @@ -15,7 +15,7 @@ interface PageProps { } export default function AppLayout({ children, breadcrumbs, ...props }: AppLayoutProps) { - const { props: pageProps } = usePage<{ flash?: { success?: string; error?: string }; errors?: { error?: string } }>(); + const { props: pageProps } = usePage(); const { flash, errors } = pageProps useEffect(() => {