Files
dockerank2/resources/views/superadmin/users/edit.blade.php
T
2026-09-01 07:49:48 -03:00

154 lines
10 KiB
PHP
Executable File

@extends("layouts.app")
@section("title", __("Edit User"))
@section("header")
<div class="flex justify-between items-center">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
{{ __("Edit User") }}
</h2>
</div>
@endsection
@section("content")
<div class="py-6">
<div class="max-w-3xl mx-auto sm:px-6 lg:px-8">
<div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6">
<div class="flex items-center gap-4 mb-6">
<span class="w-16 h-16 rounded-full bg-indigo-100 flex items-center justify-center text-xl font-bold text-indigo-600">
{{ substr($user->name, 0, 1) }}
</span>
<div>
<h3 class="text-xl font-semibold text-gray-900">{{ $user->name }}</h3>
<p class="text-sm text-gray-500">{{ $user->email }}</p>
</div>
</div>
<form method="POST" action="{{ route("superadmin.users.update", $user) }}">
@csrf
@method("PUT")
<div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-4">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Name") }}</label>
<input type="text" name="name" id="name" value="{{ old("name", $user->name) }}" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
<div>
<label for="email" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Email") }}</label>
<input type="email" name="email" id="email" value="{{ old("email", $user->email) }}" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
</div>
</div>
<div class="mb-6">
<label for="role" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Role") }}</label>
<select name="role" id="role" required
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
<option value="admin" {{ $user->hasRole('admin') ? 'selected' : '' }}>{{ __("Admin") }}</option>
<option value="superadmin" {{ $user->hasRole('superadmin') ? 'selected' : '' }}>{{ __("SuperAdmin") }}</option>
</select>
</div>
<div class="mb-6">
<label for="plan_id" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Subscription Plan") }}</label>
<select name="plan_id" id="plan_id" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
<option value="">{{ __("No plan") }}</option>
@foreach(\App\Models\SubscriptionPlan::where('is_active', true)->get() as $plan)
@php $activeSub = $user->subscriptions()->where('status', 'active')->first(); @endphp
<option value="{{ $plan->id }}" {{ $activeSub && $activeSub->subscription_plan_id == $plan->id ? 'selected' : '' }}>
{{ $plan->name }} - R$ {{ number_format($plan->price, 2, ',', '.') }} / {{ $plan->duration_days }}d
({{ $plan->token_limit ? number_format($plan->token_limit) . ' tokens' : __('Unlimited') }})
</option>
@endforeach
</select>
@if($activeSub ?? false)
<p class="text-xs text-gray-500 mt-1">
{{ __("Current plan ends: :date", ['date' => $activeSub->end_date->format('d/m/Y')]) }}
</p>
@endif
</div>
<div class="mb-6">
<label for="token_limit" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Token Limit") }}</label>
<p class="text-xs text-gray-500 mb-2">{{ __("Maximum tokens this user can consume. Leave empty for unlimited.") }}</p>
<input type="number" name="token_limit" id="token_limit"
value="{{ old("token_limit", $user->token_limit) }}" min="0" step="1000"
class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500"
placeholder="{{ __("e.g., 100000 for 100k tokens") }}">
@php
$totalUsed = \App\Models\TokenUsage::where('user_id', $user->id)->sum('total_tokens');
@endphp
@if($totalUsed > 0)
<p class="text-xs text-gray-500 mt-1">
{{ __("Current usage: :used tokens", ['used' => number_format($totalUsed)]) }}
@if($user->token_limit)
| {{ __("Limit: :limit tokens", ['limit' => number_format($user->token_limit)]) }}
| {{ round(($totalUsed / $user->token_limit) * 100) }}% {{ __("used") }}
@endif
</p>
@endif
</div>
<div class="mb-6">
<h3 class="text-lg font-semibold text-gray-900 mb-2">{{ __("Update Password") }}</h3>
<p class="text-xs text-gray-500 mb-4">{{ __("Leave blank to keep current password") }}</p>
<div class="mb-4">
<label for="password" class="block text-sm font-medium text-gray-700 mb-2">{{ __("New Password") }}</label>
<div class="relative">
<input type="password" name="password" id="password"
class="w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
<button type="button" onclick="togglePassword('password', this)" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
</button>
</div>
@error('password')
<p class="text-red-500 text-sm mt-1">{{ $message }}</p>
@enderror
</div>
<div class="mb-4">
<label for="password_confirmation" class="block text-sm font-medium text-gray-700 mb-2">{{ __("Confirm New Password") }}</label>
<div class="relative">
<input type="password" name="password_confirmation" id="password_confirmation"
class="w-full px-3 py-2 pr-10 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500">
<button type="button" onclick="togglePassword('password_confirmation', this)" class="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>
</button>
</div>
@error('password_confirmation')
<p class="text-red-500 text-sm mt-1">{{ $message }}</p>
@enderror
</div>
</div>
<div class="flex items-center justify-between pt-4 border-t border-gray-100">
<a href="{{ route("superadmin.users.index") }}"
class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition font-medium">
{{ __("Back") }}
</a>
<button type="submit" class="px-6 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition font-medium">
{{ __("Update User") }}
</button>
</div>
</form>
</div>
</div>
</div>
@endsection
@push('scripts')
<script>
function togglePassword(fieldId, btn) {
var input = document.getElementById(fieldId);
if (input.type === 'password') {
input.type = 'text';
btn.innerHTML = '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"/></svg>';
} else {
input.type = 'password';
btn.innerHTML = '<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"/></svg>';
}
}
</script>
@endpush