Files
sirpremiumv2/resources/views/livewire/show-roles.blade.php
T

228 lines
12 KiB
PHP
Executable File

<div x-data="{ add: @entangle('add'), editar: @entangle('editar') }" class="h-full w-full max-w-7xl md:my-2 px-4 sm:px-6 lg:px-8 mx-auto">
<!-- Capa de carga -->
<div class="absolute backdrop-blur-sm bg-white/70 inset-0 h-full z-40" wire:loading wire:target="crear,actualizar,editar,eliminar,limpiarInputAdd,limpiarInputEdit">
<div class="grid h-full place-items-center">
<div class="max-w-xs">
<img src="./img/loading.gif" alt="Cargando" class="w-full text-center">
<p class="text-gray-500 text-center">Cargando</p>
</div>
</div>
</div>
<!-- Contenedor principal -->
<div class=" w-full m-auto p-2 md:p-3 relative mb-6 ">
<!-- Header -->
<div class="flex flex-col sm:flex-row justify-between gap-4 sm:items-center mb-4">
<div class="flex flex-col sm:flex-row items-start sm:items-center gap-4">
<div class="flex items-center text-sm font-medium text-gray-700">
<x-icon-arrow-right class="mr-1" />
Roles
</div>
@if (auth()->user()->subvendedor && $config->subvendedor)
<a x-on:click="add = !add" class="flex items-center px-4 py-2 rounded-lg cursor-pointer text-white bg-[#B221FD] hover:bg-[#7a02b8] transition">
Añadir rol
<svg class="w-[0.87rem] ml-2" fill="#ffffff" viewBox="0 0 512 512">
<path d="M480,224H288V32c0-17.673-14.327-32-32-32s-32,14.327-32,32v192H32c-17.673,0-32,14.327-32,32s14.327,32,32,32h192v192c0,17.673,14.327,32,32,32s32-14.327,32-32V288h192c17.673,0,32-14.327,32-32S497.673,224,480,224z" />
</svg>
</a>
@endif
</div>
@if (auth()->user()->rol_id == 5)
<!-- Buscador -->
<div x-data="{
open: false,
search: '',
selectedId: @entangle('filtro_id'),
usuarios: @js($usuarios),
reset() {
this.search = '';
this.selectedId = null;
}
}"
class="relative w-full max-w-md sm:max-w-xs">
<label class="block text-sm font-medium text-gray-700 mb-1">Buscar subvendedor</label>
<div class="relative">
<input
type="text"
placeholder="Escribe nombre o correo..."
x-model="search"
@input="open = true; if (search === '') selectedId = null"
@focus="open = true"
@click.away="open = false"
class="w-full border border-gray-300 rounded-xl shadow-sm px-4 py-2 text-sm pr-10 focus:outline-none focus:ring-2 focus:ring-blue-400 focus:border-blue-400 transition">
<!-- Botón X -->
<button
type="button"
x-show="search !== ''"
@click="reset"
class="absolute inset-y-0 right-2 text-gray-500 hover:text-gray-700 text-xl"
>
&times;
</button>
</div>
<ul x-show="open" x-transition class="absolute z-50 mt-2 w-full bg-white border border-gray-300 rounded-xl shadow-lg max-h-60 overflow-y-auto text-sm">
<template x-for="user in usuarios.filter(u => search === '' || (u.name + ' ' + u.email).toLowerCase().includes(search.toLowerCase()))" :key="user.id">
<li
@click="selectedId = user.id; search = user.name + ' - ' + user.email; open = false"
class="px-4 py-2 hover:bg-blue-100 hover:text-blue-800 cursor-pointer"
:class="{ 'bg-blue-50 text-blue-700 font-medium': selectedId === user.id }"
x-text="user.name + ' - ' + user.email"></li>
</template>
<li x-show="usuarios.filter(u => search === '' || (u.name + ' ' + u.email).toLowerCase().includes(search.toLowerCase())).length === 0" class="px-4 py-2 text-gray-500 italic">
No se encontraron resultados.
</li>
</ul>
</div>
@endif
</div>
<!-- Tabla usuarios -->
<div class="overflow-x-auto">
<table class="min-w-full text-left bg-white shadow rounded-lg mb-2 md:mb-4">
<thead class="bg-[#000029] text-white text-xs md:text-sm h-12">
<tr>
@if (auth()->user()->rol_id == 5)
<th class="rounded-l-lg px-6 py-2">Subvendedor</th>
@endif
<th class="px-6 py-2">Nombre</th>
<th class="px-6 py-2">Usuarios</th>
<th class="rounded-r-lg px-6 py-2"></th>
</tr>
</thead>
<tbody class="text-gray-700 text-xs md:text-sm">
@forelse ($roles as $rol)
<tr x-data="{ openOption: false }" class="hover:bg-gray-100 border-t">
@if (auth()->user()->rol_id == 5)
<td class="px-6 py-3">{{ $rol->subvendedor?->name ?? 'N/A' }}</td>
@endif
<td class="px-6 py-3">{{ $rol->nombre ?? '' }}</td>
<td class="px-6 py-3">{{ $rol->usuarios_count ?? '' }}</td>
<td class="py-3 pr-6">
<div class="flex justify-end items-center w-full space-x-3">
<!-- Botón Editar -->
<button wire:click="editar({{ $rol->id }})" class="text-blue-600 hover:text-blue-800 transition duration-150 ease-in-out" title="Editar">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="m16.862 4.487 1.687-1.688a1.875 1.875 0 1 1 2.652 2.652L10.582 16.07a4.5 4.5 0 0 1-1.897 1.13L6 18l.8-2.685a4.5 4.5 0 0 1 1.13-1.897l8.932-8.931Zm0 0L19.5 7.125M18 14v4.75A2.25 2.25 0 0 1 15.75 21H5.25A2.25 2.25 0 0 1 3 18.75V8.25A2.25 2.25 0 0 1 5.25 6H10" />
</svg>
</button>
<!-- Botón Eliminar -->
<button wire:click="eliminar({{ $rol->id }})" class="text-red-600 hover:text-red-800 transition duration-150 ease-in-out" title="Eliminar">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5">
<path stroke-linecap="round" stroke-linejoin="round" d="m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" />
</svg>
</button>
</div>
</td>
</tr>
@empty
<tr>
<td colspan="4" class="text-center py-6 text-gray-500 italic">Sin datos</td>
</tr>
@endforelse
</tbody>
</table>
</div>
{{-- Añadir rol --}}
<div
x-cloak
x-show="add"
x-transition:enter="transition duration-350"
x-transition:enter-start="opacity-0 scale-100"
x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition duration-350"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-100"
class="fixed inset-0 z-50 backdrop-blur-sm bg-black/20">
<div class="grid h-full place-items-center">
<form>
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4 rounded-[1rem] shadow-md w-[20rem] sm:w-[24rem]">
<div class="mb-4">
<label for="nombre" class="block text-gray-700 text-sm font-bold mb-2">Nombre:</label>
<input
type="text"
id="nombre"
wire:model="nombre"
class="border-2 border-neutral-200 rounded-[0.8rem] shadow appearance-none focus:border-neutral-300 focus:ring-0 w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="px-4 py-3 sm:px-6 flex flex-col sm:flex-row-reverse sm:justify-evenly gap-3 mt-4">
<button
wire:click="crear"
type="button"
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green ease-in-out text-sm">
Guardar
</button>
<button
wire:click="limpiarInputAdd"
type="button"
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 text-white bg-[#585858] hover:bg-[#3a3a3a] ease-in-out text-sm">
Cerrar
</button>
</div>
</div>
</form>
</div>
</div>
{{-- Editar rol --}}
<div
x-cloak
x-show="editar"
x-transition:enter="transition duration-350"
x-transition:enter-start="opacity-0 scale-100"
x-transition:enter-end="opacity-100 scale-100"
x-transition:leave="transition duration-350"
x-transition:leave-start="opacity-100 scale-100"
x-transition:leave-end="opacity-0 scale-100"
class="fixed inset-0 z-50 backdrop-blur-sm bg-black/20">
<div class="grid h-full place-items-center">
<form>
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4 rounded-[1rem] shadow-md w-[20rem] sm:w-[24rem]">
<div class="mb-4">
<label for="nombre_edit" class="block text-gray-700 text-sm font-bold mb-2">Nombre:</label>
<input
type="text"
id="nombre_edit"
wire:model="nombre"
class="border-2 border-neutral-200 rounded-[0.8rem] shadow appearance-none focus:border-neutral-300 focus:ring-0 w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
</div>
<div class="px-4 py-3 sm:px-6 flex flex-col sm:flex-row-reverse sm:justify-evenly gap-3 mt-4">
<button
wire:click="actualizar"
type="button"
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 text-white bg-[#B221FD] hover:bg-[#7a02b8] focus:shadow-outline-green ease-in-out text-sm">
Guardar
</button>
<button
wire:click="limpiarInputAdd"
type="button"
class="inline-flex justify-center w-full rounded-md border border-transparent px-4 py-2 text-white bg-[#585858] hover:bg-[#3a3a3a] ease-in-out text-sm">
Cerrar
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>