admin_users_personels
This commit is contained in:
976
frontend_admin/pages/users/[id]/index.vue
Normal file
976
frontend_admin/pages/users/[id]/index.vue
Normal file
@@ -0,0 +1,976 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Loading State -->
|
||||
<div v-if="loading" class="flex items-center justify-center py-20">
|
||||
<div class="flex flex-col items-center gap-3">
|
||||
<svg class="w-8 h-8 text-indigo-400 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
<p class="text-slate-400 text-sm">{{ $t('users.details.loading') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<div v-else-if="error" class="flex flex-col items-center justify-center py-20 text-center">
|
||||
<svg class="w-12 h-12 text-red-500 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" />
|
||||
</svg>
|
||||
<p class="text-red-400 text-sm mb-2">{{ error }}</p>
|
||||
<button @click="fetchUser" class="px-4 py-2 text-sm bg-indigo-600/20 text-indigo-300 hover:bg-indigo-600/30 rounded-lg transition">
|
||||
{{ $t('users.details.retry') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<template v-else-if="user">
|
||||
<!-- Header -->
|
||||
<div class="mb-8">
|
||||
<button
|
||||
@click="goBack"
|
||||
class="inline-flex items-center gap-1.5 text-sm text-slate-400 hover:text-white transition mb-4"
|
||||
>
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
||||
</svg>
|
||||
{{ $t('users.details.back') }}
|
||||
</button>
|
||||
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-4">
|
||||
<div
|
||||
class="w-12 h-12 rounded-xl flex items-center justify-center text-lg font-bold text-white"
|
||||
:class="getInitialsColor(userDisplayName)"
|
||||
>
|
||||
{{ getInitials(userDisplayName) }}
|
||||
</div>
|
||||
<div>
|
||||
<div class="flex items-center gap-3">
|
||||
<h1 class="text-2xl font-bold text-white">{{ userDisplayName }}</h1>
|
||||
<span
|
||||
class="inline-flex items-center px-3 py-1 rounded-full text-xs font-medium"
|
||||
:class="statusBadgeClass"
|
||||
>
|
||||
<span class="w-1.5 h-1.5 rounded-full mr-1.5" :class="statusDotClass"></span>
|
||||
{{ statusLabel }}
|
||||
</span>
|
||||
<span
|
||||
v-if="user.is_vip"
|
||||
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-yellow-500/10 text-yellow-400"
|
||||
>
|
||||
<svg class="w-3 h-3 mr-1" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
|
||||
</svg>
|
||||
VIP
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-sm text-slate-400 mt-0.5">
|
||||
{{ user.email }}
|
||||
<span v-if="user.person?.phone" class="ml-2 text-slate-500">· {{ user.person.phone }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-3">
|
||||
<button
|
||||
v-if="hasEditPermission"
|
||||
@click="openEditModal"
|
||||
class="inline-flex items-center gap-1.5 px-4 py-2 text-sm font-medium bg-indigo-600/20 text-indigo-300 hover:bg-indigo-600/30 rounded-lg transition"
|
||||
>
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
|
||||
</svg>
|
||||
{{ $t('users.details.edit') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tab Navigation -->
|
||||
<div class="border-b border-slate-700 mb-6">
|
||||
<nav class="flex gap-6">
|
||||
<button
|
||||
v-for="tab in tabs"
|
||||
:key="tab.key"
|
||||
@click="activeTab = tab.key"
|
||||
class="pb-3 text-sm font-medium transition border-b-2 -mb-px"
|
||||
:class="activeTab === tab.key
|
||||
? 'text-indigo-400 border-indigo-400'
|
||||
: 'text-slate-400 border-transparent hover:text-slate-300'"
|
||||
>
|
||||
{{ $t(tab.label) }}
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Profile Tab -->
|
||||
<!-- ============================================================ -->
|
||||
<div v-if="activeTab === 'profile'" class="space-y-6">
|
||||
<!-- User Account Info Card -->
|
||||
<div class="bg-slate-800/50 border border-slate-700 rounded-xl p-6">
|
||||
<div class="flex items-center gap-3 mb-5">
|
||||
<div class="p-2 rounded-lg bg-indigo-500/10 text-indigo-400">
|
||||
<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="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z" />
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-base font-semibold text-white">{{ $t('users.details.account_info') }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.user_id') }}</label>
|
||||
<p class="text-sm text-white font-mono">{{ user.id }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.email') }}</label>
|
||||
<p class="text-sm text-white">{{ user.email }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.role') }}</label>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium" :class="roleBadgeClass(user.role)">
|
||||
{{ roleLabel(user.role) }}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.registration_date') }}</label>
|
||||
<p class="text-sm text-white">{{ formatDate(user.created_at) }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.last_login') }}</label>
|
||||
<p class="text-sm text-white">{{ formatDate(user.last_login_at) || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.ui_mode') }}</label>
|
||||
<p class="text-sm text-white capitalize">{{ user.ui_mode || 'personal' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.language') }}</label>
|
||||
<p class="text-sm text-white uppercase">{{ user.preferred_language || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.region') }}</label>
|
||||
<p class="text-sm text-white">{{ user.region_code || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.currency') }}</label>
|
||||
<p class="text-sm text-white">{{ user.preferred_currency || '—' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Subscription Info Card -->
|
||||
<div class="bg-slate-800/50 border border-slate-700 rounded-xl p-6">
|
||||
<div class="flex items-center gap-3 mb-5">
|
||||
<div class="p-2 rounded-lg bg-emerald-500/10 text-emerald-400">
|
||||
<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="M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z" />
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-base font-semibold text-white">{{ $t('users.details.subscription_info') }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.package') }}</label>
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium" :class="planBadgeClass(user.subscription_plan)">
|
||||
{{ user.subscription_plan || '—' }}
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.subscription_expires') }}</label>
|
||||
<p class="text-sm text-white">{{ formatDate(user.subscription_expires_at) || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.scope_level') }}</label>
|
||||
<p class="text-sm text-white">{{ user.scope_level || 'individual' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.max_vehicles') }}</label>
|
||||
<p class="text-sm text-white">{{ user.max_vehicles }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.max_garages') }}</label>
|
||||
<p class="text-sm text-white">{{ user.max_garages }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Person Details Card (if exists) -->
|
||||
<div v-if="user.person" class="bg-slate-800/50 border border-slate-700 rounded-xl p-6">
|
||||
<div class="flex items-center gap-3 mb-5">
|
||||
<div class="p-2 rounded-lg bg-cyan-500/10 text-cyan-400">
|
||||
<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="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<h3 class="text-base font-semibold text-white">{{ $t('users.details.personal_info') }}</h3>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.last_name') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.last_name || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.first_name') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.first_name || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.phone') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.phone || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.birth_place') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.birth_place || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.birth_date') }}</label>
|
||||
<p class="text-sm text-white">{{ formatDate(user.person.birth_date) || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.mothers_name') }}</label>
|
||||
<p class="text-sm text-white">{{ [user.person.mothers_last_name, user.person.mothers_first_name].filter(Boolean).join(' ') || '—' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Address sub-card -->
|
||||
<div v-if="user.person.address" class="mt-6 pt-6 border-t border-slate-700">
|
||||
<h4 class="text-sm font-semibold text-slate-300 mb-3">{{ $t('users.details.address') }}</h4>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.zip') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.address.address_zip || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.city') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.address.address_city || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.street') }}</label>
|
||||
<p class="text-sm text-white">{{ [user.person.address.address_street_type, user.person.address.address_street_name].filter(Boolean).join(' ') || '—' }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs text-slate-400 mb-1">{{ $t('users.details.house_number') }}</label>
|
||||
<p class="text-sm text-white">{{ user.person.address.address_house_number || '—' }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- No Person record -->
|
||||
<div v-else class="bg-slate-800/50 border border-slate-700 rounded-xl p-6 text-center">
|
||||
<svg class="w-10 h-10 text-slate-600 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
<p class="text-sm text-slate-400">{{ $t('users.details.no_person_record') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Memberships Tab -->
|
||||
<!-- ============================================================ -->
|
||||
<div v-if="activeTab === 'memberships'" class="space-y-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-purple-500/10 text-purple-400">
|
||||
<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="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16l3.5-2 3.5 2 3.5-2 3.5 2M10 8.5a.5.5 0 11-1 0 .5.5 0 011 0zm5 5a.5.5 0 11-1 0 .5.5 0 011 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-base font-semibold text-white">{{ $t('users.details.memberships') }}</h3>
|
||||
<p class="text-xs text-slate-400 mt-0.5">{{ $t('users.details.memberships_count', { count: memberships.length }) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="membershipsLoading" class="flex items-center justify-center py-12">
|
||||
<svg class="w-6 h-6 text-indigo-400 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<div v-else-if="memberships.length === 0" class="bg-slate-800/50 border border-slate-700 rounded-xl p-12 text-center">
|
||||
<svg class="w-10 h-10 text-slate-600 mx-auto mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z" />
|
||||
</svg>
|
||||
<p class="text-sm text-slate-400">{{ $t('users.details.no_memberships') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="bg-slate-800/50 border border-slate-700 rounded-xl overflow-hidden">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-slate-700">
|
||||
<th class="text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider">{{ $t('users.details.org_name') }}</th>
|
||||
<th class="text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider">{{ $t('users.details.org_role') }}</th>
|
||||
<th class="text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider">{{ $t('users.details.member_status') }}</th>
|
||||
<th class="text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider">{{ $t('users.details.joined_at') }}</th>
|
||||
<th class="text-left px-4 py-3 text-xs font-medium text-slate-400 uppercase tracking-wider">{{ $t('users.details.verified') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="m in memberships" :key="m.id" class="border-b border-slate-700/50 last:border-b-0 hover:bg-slate-700/30 transition">
|
||||
<td class="px-4 py-3">
|
||||
<NuxtLink
|
||||
:to="'/garages/' + m.organization_id"
|
||||
class="text-sm font-medium text-white hover:text-indigo-400 hover:underline transition-colors"
|
||||
>
|
||||
{{ m.organization_display_name || m.organization_name }}
|
||||
</NuxtLink>
|
||||
</td>
|
||||
<td class="px-4 py-3">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium" :class="roleBadgeClass(m.role)">
|
||||
{{ orgRoleLabel(m.role) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-3">
|
||||
<span class="inline-flex items-center gap-1.5 px-2.5 py-0.5 rounded-full text-xs font-medium" :class="memberStatusBadgeClass(m.status)">
|
||||
<span class="w-1.5 h-1.5 rounded-full" :class="memberStatusDotClass(m.status)"></span>
|
||||
{{ memberStatusLabel(m.status) }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="px-4 py-3 text-slate-300 text-xs">{{ formatDate(m.joined_at) || '—' }}</td>
|
||||
<td class="px-4 py-3">
|
||||
<span v-if="m.is_verified" class="inline-flex items-center gap-1 text-xs text-emerald-400">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ $t('users.details.verified_yes') }}
|
||||
</span>
|
||||
<span v-else class="text-xs text-slate-500">{{ $t('users.details.verified_no') }}</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Edit Modal -->
|
||||
<!-- ============================================================ -->
|
||||
<div
|
||||
v-if="showEditModal"
|
||||
class="fixed inset-0 z-50 flex items-center justify-center p-4"
|
||||
>
|
||||
<!-- Backdrop -->
|
||||
<div class="absolute inset-0 bg-black/60 backdrop-blur-sm" @click="closeEditModal"></div>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="relative w-full max-w-2xl bg-slate-800 border border-slate-700 rounded-2xl shadow-2xl max-h-[90vh] overflow-hidden flex flex-col">
|
||||
<!-- Header -->
|
||||
<div class="px-6 py-4 border-b border-slate-700 flex items-center justify-between flex-shrink-0">
|
||||
<h3 class="text-lg font-semibold text-white">{{ $t('users.details.edit_user') }}</h3>
|
||||
<button @click="closeEditModal" class="p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700 transition">
|
||||
<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="M6 18L18 6M6 6l12 12" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable Body -->
|
||||
<div class="flex-1 overflow-y-auto p-6 space-y-5">
|
||||
<!-- Account Fields -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.email') }}</label>
|
||||
<input
|
||||
v-model="editForm.email"
|
||||
type="email"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.preferred_language') }}</label>
|
||||
<select
|
||||
v-model="editForm.preferred_language"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
>
|
||||
<option value="hu">HU</option>
|
||||
<option value="en">EN</option>
|
||||
<option value="de">DE</option>
|
||||
<option value="ro">RO</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.region') }}</label>
|
||||
<input
|
||||
v-model="editForm.region_code"
|
||||
type="text"
|
||||
maxlength="5"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.currency') }}</label>
|
||||
<input
|
||||
v-model="editForm.preferred_currency"
|
||||
type="text"
|
||||
maxlength="3"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.package') }}</label>
|
||||
<select
|
||||
v-model="editForm.subscription_plan"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
>
|
||||
<option value="FREE">FREE</option>
|
||||
<option value="PREMIUM">PREMIUM</option>
|
||||
<option value="ENTERPRISE">ENTERPRISE</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.subscription_expires') }}</label>
|
||||
<input
|
||||
v-model="editForm.subscription_expires_at"
|
||||
type="datetime-local"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.scope_level') }}</label>
|
||||
<select
|
||||
v-model="editForm.scope_level"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
>
|
||||
<option value="individual">individual</option>
|
||||
<option value="organization">organization</option>
|
||||
<option value="group">group</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.scope_id') }}</label>
|
||||
<input
|
||||
v-model="editForm.scope_id"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-6 pt-2">
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
v-model="editForm.is_active"
|
||||
type="checkbox"
|
||||
class="rounded border-slate-600 bg-slate-700 text-indigo-600 focus:ring-indigo-500/50"
|
||||
/>
|
||||
<span class="text-sm text-slate-300">{{ $t('users.details.is_active') }}</span>
|
||||
</label>
|
||||
<label class="flex items-center gap-2 cursor-pointer">
|
||||
<input
|
||||
v-model="editForm.is_vip"
|
||||
type="checkbox"
|
||||
class="rounded border-slate-600 bg-slate-700 text-indigo-600 focus:ring-indigo-500/50"
|
||||
/>
|
||||
<span class="text-sm text-slate-300">{{ $t('users.details.is_vip') }}</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<!-- Person Fields -->
|
||||
<div class="border-t border-slate-700 pt-5">
|
||||
<h4 class="text-sm font-semibold text-white mb-4">{{ $t('users.details.personal_info') }}</h4>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.last_name') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_last_name"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.first_name') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_first_name"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.phone') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_phone"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.mothers_name') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_mothers_last_name"
|
||||
type="text"
|
||||
placeholder="Last name"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.mothers_first_name') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_mothers_first_name"
|
||||
type="text"
|
||||
placeholder="First name"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.birth_place') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_birth_place"
|
||||
type="text"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-xs font-medium text-slate-400 mb-1.5">{{ $t('users.details.birth_date') }}</label>
|
||||
<input
|
||||
v-model="editForm.person_birth_date"
|
||||
type="date"
|
||||
class="w-full px-3 py-2 text-sm bg-slate-700/50 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Footer -->
|
||||
<div class="px-6 py-4 border-t border-slate-700 flex items-center justify-end gap-3 flex-shrink-0">
|
||||
<button
|
||||
@click="closeEditModal"
|
||||
class="px-4 py-2 text-sm font-medium text-slate-300 hover:text-white bg-slate-700/50 hover:bg-slate-700 rounded-lg transition"
|
||||
>
|
||||
{{ $t('users.details.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
@click="saveEdit"
|
||||
:disabled="saving"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium bg-indigo-600 text-white hover:bg-indigo-500 rounded-lg transition disabled:opacity-50"
|
||||
>
|
||||
<svg v-if="saving" class="w-4 h-4 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
{{ saving ? $t('users.details.saving') : $t('users.details.save') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ============================================================ -->
|
||||
<!-- Notification Toast -->
|
||||
<!-- ============================================================ -->
|
||||
<div
|
||||
v-if="notification.show"
|
||||
class="fixed bottom-6 right-6 z-50 px-5 py-3 rounded-xl shadow-2xl text-sm font-medium transition-all"
|
||||
:class="notification.type === 'success' ? 'bg-emerald-600 text-white' : 'bg-red-600 text-white'"
|
||||
>
|
||||
<div class="flex items-center gap-2">
|
||||
<svg v-if="notification.type === 'success'" 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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
<svg v-else 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="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
{{ notification.message }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '~/stores/auth'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
|
||||
const userId = route.params.id as string
|
||||
|
||||
// State
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
const user = ref<any>(null)
|
||||
const memberships = ref<any[]>([])
|
||||
const membershipsLoading = ref(false)
|
||||
const activeTab = ref('profile')
|
||||
|
||||
// Edit Modal
|
||||
const showEditModal = ref(false)
|
||||
const saving = ref(false)
|
||||
const editForm = ref({
|
||||
email: '',
|
||||
preferred_language: '',
|
||||
region_code: '',
|
||||
preferred_currency: '',
|
||||
subscription_plan: '',
|
||||
subscription_expires_at: '',
|
||||
scope_level: '',
|
||||
scope_id: '',
|
||||
is_active: true,
|
||||
is_vip: false,
|
||||
person_last_name: '',
|
||||
person_first_name: '',
|
||||
person_phone: '',
|
||||
person_mothers_last_name: '',
|
||||
person_mothers_first_name: '',
|
||||
person_birth_place: '',
|
||||
person_birth_date: '',
|
||||
})
|
||||
|
||||
// Notification
|
||||
const notification = ref({ show: false, type: 'success' as 'success' | 'error', message: '' })
|
||||
|
||||
// Tab definitions
|
||||
const tabs = [
|
||||
{ key: 'profile', label: 'users.details.profile_tab' },
|
||||
{ key: 'memberships', label: 'users.details.memberships_tab' },
|
||||
]
|
||||
|
||||
// Computed
|
||||
const userDisplayName = computed(() => {
|
||||
if (!user.value) return ''
|
||||
const p = user.value.person
|
||||
if (p?.last_name || p?.first_name) {
|
||||
return [p.last_name, p.first_name].filter(Boolean).join(' ')
|
||||
}
|
||||
return user.value.email || 'User #' + user.value.id
|
||||
})
|
||||
|
||||
const statusLabel = computed(() => {
|
||||
if (!user.value) return ''
|
||||
const map: Record<string, string> = {
|
||||
active: 'Active',
|
||||
inactive: 'Inactive',
|
||||
deleted: 'Deleted',
|
||||
banned: 'Banned',
|
||||
}
|
||||
return map[user.value.status?.toLowerCase()] || user.value.status || 'Active'
|
||||
})
|
||||
|
||||
const statusBadgeClass = computed(() => {
|
||||
if (!user.value) return ''
|
||||
const map: Record<string, string> = {
|
||||
active: 'bg-emerald-500/10 text-emerald-400',
|
||||
inactive: 'bg-slate-500/10 text-slate-400',
|
||||
deleted: 'bg-red-500/10 text-red-400',
|
||||
banned: 'bg-red-500/10 text-red-400',
|
||||
}
|
||||
return map[user.value.status?.toLowerCase()] || 'bg-emerald-500/10 text-emerald-400'
|
||||
})
|
||||
|
||||
const statusDotClass = computed(() => {
|
||||
if (!user.value) return ''
|
||||
const map: Record<string, string> = {
|
||||
active: 'bg-emerald-400',
|
||||
inactive: 'bg-slate-400',
|
||||
deleted: 'bg-red-400',
|
||||
banned: 'bg-red-400',
|
||||
}
|
||||
return map[user.value.status?.toLowerCase()] || 'bg-emerald-400'
|
||||
})
|
||||
|
||||
const hasEditPermission = computed(() => {
|
||||
if (auth.isAdmin) return true
|
||||
return !!auth.user?.system_capabilities?.['users:edit']
|
||||
})
|
||||
|
||||
// API calls
|
||||
async function fetchUser() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const tokenCookie = useCookie('access_token')
|
||||
const token = (tokenCookie.value || auth.token || '').trim()
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
const res = await fetch(`/api/v1/admin/users/${userId}`, { headers })
|
||||
if (!res.ok) {
|
||||
if (res.status === 404) throw new Error('User not found')
|
||||
if (res.status === 403) throw new Error('Access denied')
|
||||
throw new Error(`Failed to fetch user: ${res.status}`)
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
user.value = data
|
||||
|
||||
// Fetch memberships after user loads
|
||||
fetchMemberships()
|
||||
} catch (e: any) {
|
||||
error.value = e.message || 'Failed to load user details'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchMemberships() {
|
||||
membershipsLoading.value = true
|
||||
try {
|
||||
const tokenCookie = useCookie('access_token')
|
||||
const token = (tokenCookie.value || auth.token || '').trim()
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
const res = await fetch(`/api/v1/admin/users/${userId}/memberships`, { headers })
|
||||
if (!res.ok) throw new Error(`Failed to fetch memberships: ${res.status}`)
|
||||
|
||||
const data = await res.json()
|
||||
memberships.value = Array.isArray(data) ? data : (data.memberships || [])
|
||||
} catch (e: any) {
|
||||
console.error('Memberships fetch error:', e)
|
||||
memberships.value = []
|
||||
} finally {
|
||||
membershipsLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Edit Modal
|
||||
function openEditModal() {
|
||||
if (!user.value) return
|
||||
const u = user.value
|
||||
const p = u.person || {}
|
||||
editForm.value = {
|
||||
email: u.email || '',
|
||||
preferred_language: u.preferred_language || '',
|
||||
region_code: u.region_code || '',
|
||||
preferred_currency: u.preferred_currency || '',
|
||||
subscription_plan: u.subscription_plan || '',
|
||||
subscription_expires_at: u.subscription_expires_at
|
||||
? u.subscription_expires_at.slice(0, 16)
|
||||
: '',
|
||||
scope_level: u.scope_level || '',
|
||||
scope_id: u.scope_id || '',
|
||||
is_active: u.status === 'active',
|
||||
is_vip: u.is_vip || false,
|
||||
person_last_name: p.last_name || '',
|
||||
person_first_name: p.first_name || '',
|
||||
person_phone: p.phone || '',
|
||||
person_mothers_last_name: p.mothers_last_name || '',
|
||||
person_mothers_first_name: p.mothers_first_name || '',
|
||||
person_birth_place: p.birth_place || '',
|
||||
person_birth_date: p.birth_date ? p.birth_date.slice(0, 10) : '',
|
||||
}
|
||||
showEditModal.value = true
|
||||
}
|
||||
|
||||
function closeEditModal() {
|
||||
showEditModal.value = false
|
||||
}
|
||||
|
||||
async function saveEdit() {
|
||||
saving.value = true
|
||||
try {
|
||||
const tokenCookie = useCookie('access_token')
|
||||
const token = (tokenCookie.value || auth.token || '').trim()
|
||||
const headers: Record<string, string> = {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
const payload: Record<string, any> = {
|
||||
email: editForm.value.email || undefined,
|
||||
preferred_language: editForm.value.preferred_language || undefined,
|
||||
region_code: editForm.value.region_code || undefined,
|
||||
preferred_currency: editForm.value.preferred_currency || undefined,
|
||||
subscription_plan: editForm.value.subscription_plan || undefined,
|
||||
subscription_expires_at: editForm.value.subscription_expires_at
|
||||
? new Date(editForm.value.subscription_expires_at).toISOString()
|
||||
: null,
|
||||
scope_level: editForm.value.scope_level || undefined,
|
||||
scope_id: editForm.value.scope_id ? Number(editForm.value.scope_id) : undefined,
|
||||
is_active: editForm.value.is_active,
|
||||
is_vip: editForm.value.is_vip,
|
||||
}
|
||||
|
||||
// Only include person fields if any are filled
|
||||
const hasPersonData = editForm.value.person_last_name || editForm.value.person_first_name ||
|
||||
editForm.value.person_phone || editForm.value.person_mothers_last_name ||
|
||||
editForm.value.person_mothers_first_name || editForm.value.person_birth_place ||
|
||||
editForm.value.person_birth_date
|
||||
|
||||
if (hasPersonData) {
|
||||
payload.person = {
|
||||
last_name: editForm.value.person_last_name || undefined,
|
||||
first_name: editForm.value.person_first_name || undefined,
|
||||
phone: editForm.value.person_phone || undefined,
|
||||
mothers_last_name: editForm.value.person_mothers_last_name || undefined,
|
||||
mothers_first_name: editForm.value.person_mothers_first_name || undefined,
|
||||
birth_place: editForm.value.person_birth_place || undefined,
|
||||
birth_date: editForm.value.person_birth_date
|
||||
? new Date(editForm.value.person_birth_date).toISOString()
|
||||
: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
// Clean undefined values
|
||||
Object.keys(payload).forEach(key => {
|
||||
if (payload[key] === undefined) delete payload[key]
|
||||
})
|
||||
if (payload.person) {
|
||||
Object.keys(payload.person).forEach(key => {
|
||||
if (payload.person[key] === undefined) delete payload.person[key]
|
||||
})
|
||||
if (Object.keys(payload.person).length === 0) delete payload.person
|
||||
}
|
||||
|
||||
const res = await fetch(`/api/v1/admin/users/${userId}`, {
|
||||
method: 'PATCH',
|
||||
headers,
|
||||
body: JSON.stringify(payload),
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = await res.json().catch(() => ({}))
|
||||
throw new Error(errData.detail || `Save failed: ${res.status}`)
|
||||
}
|
||||
|
||||
const result = await res.json()
|
||||
user.value = result
|
||||
closeEditModal()
|
||||
showNotification('success', 'User updated successfully')
|
||||
} catch (e: any) {
|
||||
showNotification('error', e.message || 'Failed to save')
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Notification helper
|
||||
function showNotification(type: 'success' | 'error', message: string) {
|
||||
notification.value = { show: true, type, message }
|
||||
setTimeout(() => {
|
||||
notification.value.show = false
|
||||
}, 4000)
|
||||
}
|
||||
|
||||
// Navigation
|
||||
function goBack() {
|
||||
router.push('/users')
|
||||
}
|
||||
|
||||
// Helpers
|
||||
function getInitials(name: string): string {
|
||||
if (!name) return '?'
|
||||
return name.split(' ').map(w => w[0]).join('').toUpperCase().slice(0, 2)
|
||||
}
|
||||
|
||||
function getInitialsColor(name: string): string {
|
||||
const colors = [
|
||||
'bg-red-500', 'bg-yellow-500', 'bg-green-500', 'bg-blue-500',
|
||||
'bg-indigo-500', 'bg-purple-500', 'bg-pink-500', 'bg-teal-500',
|
||||
]
|
||||
let hash = 0
|
||||
for (let i = 0; i < (name || '').length; i++) {
|
||||
hash = name.charCodeAt(i) + ((hash << 5) - hash)
|
||||
}
|
||||
return colors[Math.abs(hash) % colors.length]
|
||||
}
|
||||
|
||||
function formatDate(date: string | null | undefined): string {
|
||||
if (!date) return ''
|
||||
try {
|
||||
return new Date(date).toLocaleDateString('en-GB', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
} catch {
|
||||
return String(date)
|
||||
}
|
||||
}
|
||||
|
||||
function roleLabel(role: string): string {
|
||||
const map: Record<string, string> = {
|
||||
admin: 'Admin',
|
||||
user: 'User',
|
||||
staff: 'Staff',
|
||||
superadmin: 'Superadmin',
|
||||
}
|
||||
return map[role?.toLowerCase()] || role || 'User'
|
||||
}
|
||||
|
||||
function roleBadgeClass(role: string): string {
|
||||
const map: Record<string, string> = {
|
||||
admin: 'bg-purple-500/10 text-purple-400',
|
||||
user: 'bg-blue-500/10 text-blue-400',
|
||||
staff: 'bg-cyan-500/10 text-cyan-400',
|
||||
superadmin: 'bg-amber-500/10 text-amber-400',
|
||||
}
|
||||
return map[role?.toLowerCase()] || 'bg-slate-500/10 text-slate-400'
|
||||
}
|
||||
|
||||
function planBadgeClass(plan: string): string {
|
||||
const map: Record<string, string> = {
|
||||
FREE: 'bg-slate-500/10 text-slate-400',
|
||||
PREMIUM: 'bg-emerald-500/10 text-emerald-400',
|
||||
ENTERPRISE: 'bg-amber-500/10 text-amber-400',
|
||||
}
|
||||
return map[plan?.toUpperCase()] || 'bg-slate-500/10 text-slate-400'
|
||||
}
|
||||
|
||||
function orgRoleLabel(role: string): string {
|
||||
const map: Record<string, string> = {
|
||||
admin: 'Admin',
|
||||
manager: 'Manager',
|
||||
member: 'Member',
|
||||
owner: 'Owner',
|
||||
}
|
||||
return map[role?.toLowerCase()] || role || 'Member'
|
||||
}
|
||||
|
||||
function memberStatusLabel(status: string): string {
|
||||
const map: Record<string, string> = {
|
||||
active: 'Active',
|
||||
invited: 'Invited',
|
||||
suspended: 'Suspended',
|
||||
inactive: 'Inactive',
|
||||
}
|
||||
return map[status?.toLowerCase()] || status || 'Unknown'
|
||||
}
|
||||
|
||||
function memberStatusBadgeClass(status: string): string {
|
||||
const map: Record<string, string> = {
|
||||
active: 'bg-emerald-500/10 text-emerald-400',
|
||||
invited: 'bg-blue-500/10 text-blue-400',
|
||||
suspended: 'bg-red-500/10 text-red-400',
|
||||
inactive: 'bg-slate-500/10 text-slate-400',
|
||||
}
|
||||
return map[status?.toLowerCase()] || 'bg-slate-500/10 text-slate-400'
|
||||
}
|
||||
|
||||
function memberStatusDotClass(status: string): string {
|
||||
const map: Record<string, string> = {
|
||||
active: 'bg-emerald-400',
|
||||
invited: 'bg-blue-400',
|
||||
suspended: 'bg-red-400',
|
||||
inactive: 'bg-slate-400',
|
||||
}
|
||||
return map[status?.toLowerCase()] || 'bg-slate-400'
|
||||
}
|
||||
|
||||
// Lifecycle
|
||||
onMounted(() => {
|
||||
fetchUser()
|
||||
})
|
||||
</script>
|
||||
776
frontend_admin/pages/users/index.vue
Normal file
776
frontend_admin/pages/users/index.vue
Normal file
@@ -0,0 +1,776 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Page Header -->
|
||||
<div class="mb-8">
|
||||
<h1 class="text-2xl font-bold text-white">{{ $t('users.title') }}</h1>
|
||||
<p class="text-slate-400 mt-1">{{ $t('users.subtitle') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Search & Filter Bar -->
|
||||
<div class="flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6">
|
||||
<div class="relative flex-1 max-w-md">
|
||||
<svg class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
|
||||
</svg>
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
:placeholder="$t('users.search_placeholder')"
|
||||
class="w-full pl-10 pr-4 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500 transition"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<!-- Status Filter -->
|
||||
<select
|
||||
v-model="statusFilter"
|
||||
class="px-3 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"
|
||||
>
|
||||
<option value="all">{{ $t('users.all_statuses') }}</option>
|
||||
<option value="active">{{ $t('users.status_active') }}</option>
|
||||
<option value="inactive">{{ $t('users.status_inactive') }}</option>
|
||||
<option value="deleted">{{ $t('users.status_deleted') }}</option>
|
||||
<option value="banned">{{ $t('users.status_banned') }}</option>
|
||||
</select>
|
||||
<!-- Role Filter -->
|
||||
<select
|
||||
v-model="roleFilter"
|
||||
class="px-3 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"
|
||||
>
|
||||
<option value="all">{{ $t('users.all_roles') }}</option>
|
||||
<option value="user">{{ $t('users.role_user') }}</option>
|
||||
<option value="admin">{{ $t('users.role_admin') }}</option>
|
||||
<option value="staff">{{ $t('users.role_staff') }}</option>
|
||||
<option value="superadmin">{{ $t('users.role_superadmin') }}</option>
|
||||
</select>
|
||||
<!-- Plan Filter -->
|
||||
<select
|
||||
v-model="planFilter"
|
||||
class="px-3 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"
|
||||
>
|
||||
<option value="all">{{ $t('users.all_plans') }}</option>
|
||||
<option value="FREE">{{ $t('users.plan_free') }}</option>
|
||||
<option value="PREMIUM">{{ $t('users.plan_premium') }}</option>
|
||||
<option value="ENTERPRISE">{{ $t('users.plan_enterprise') }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading State -->
|
||||
<div v-if="loading" class="flex items-center justify-center py-20">
|
||||
<div class="flex flex-col items-center gap-3">
|
||||
<svg class="w-8 h-8 text-indigo-400 animate-spin" fill="none" viewBox="0 0 24 24">
|
||||
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4" />
|
||||
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
|
||||
</svg>
|
||||
<p class="text-slate-400 text-sm">{{ $t('users.loading') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Error State -->
|
||||
<div v-else-if="error" class="flex flex-col items-center justify-center py-20 text-center">
|
||||
<svg class="w-12 h-12 text-red-500 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z" />
|
||||
</svg>
|
||||
<p class="text-red-400 text-sm mb-2">{{ error }}</p>
|
||||
<button @click="fetchUsers" class="px-4 py-2 text-sm bg-indigo-600/20 text-indigo-300 hover:bg-indigo-600/30 rounded-lg transition">
|
||||
{{ $t('users.retry') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Content -->
|
||||
<template v-else>
|
||||
<!-- Stats Cards Row -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-5 gap-4 mb-8">
|
||||
<!-- Total Users -->
|
||||
<div class="bg-slate-800 rounded-xl border border-slate-700 p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-indigo-500/10 text-indigo-400">
|
||||
<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="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider">{{ $t('users.total_users') }}</p>
|
||||
<p class="text-2xl font-bold text-white">{{ stats.total_users }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Active Users -->
|
||||
<div class="bg-slate-800 rounded-xl border border-slate-700 p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-emerald-500/10 text-emerald-400">
|
||||
<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="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider">{{ $t('users.active_users') }}</p>
|
||||
<p class="text-2xl font-bold text-emerald-400">{{ stats.active_users }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Deleted Users -->
|
||||
<div class="bg-slate-800 rounded-xl border border-slate-700 p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-red-500/10 text-red-400">
|
||||
<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="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider">{{ $t('users.deleted_users') }}</p>
|
||||
<p class="text-2xl font-bold text-red-400">{{ stats.deleted_users }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Banned Users -->
|
||||
<div class="bg-slate-800 rounded-xl border border-slate-700 p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-amber-500/10 text-amber-400">
|
||||
<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="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider">{{ $t('users.banned_users') }}</p>
|
||||
<p class="text-2xl font-bold text-amber-400">{{ stats.banned_users }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- New Today -->
|
||||
<div class="bg-slate-800 rounded-xl border border-slate-700 p-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="p-2 rounded-lg bg-cyan-500/10 text-cyan-400">
|
||||
<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="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-xs text-slate-400 uppercase tracking-wider">{{ $t('users.new_today') }}</p>
|
||||
<p class="text-2xl font-bold text-cyan-400">{{ stats.new_users_today }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Registration Trend Chart -->
|
||||
<div class="mb-8">
|
||||
<UserTrendChart :data="stats.registration_trend" :loading="loading" />
|
||||
</div>
|
||||
|
||||
<!-- Filtered results indicator -->
|
||||
<div v-if="isFilterActive" class="mb-4 text-xs text-slate-500">
|
||||
{{ $t('users.filtered_results') }}: <span class="text-slate-300 font-semibold">{{ users.length }}</span> / {{ totalCount }} db
|
||||
</div>
|
||||
|
||||
<!-- Bulk Actions Bar -->
|
||||
<div v-if="selectedUserIds.length > 0 && canEditUsers" class="mb-4 px-4 py-3 bg-indigo-900/30 border border-indigo-700/50 rounded-xl flex items-center justify-between">
|
||||
<p class="text-sm text-indigo-300">
|
||||
{{ $t('users.selected_count', { count: selectedUserIds.length }) }}
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@click="bulkActivate"
|
||||
class="px-3 py-1.5 text-xs font-medium bg-emerald-600/20 text-emerald-300 hover:bg-emerald-600/30 rounded-lg transition"
|
||||
>
|
||||
{{ $t('users.bulk_activate') }}
|
||||
</button>
|
||||
<button
|
||||
@click="bulkDeactivate"
|
||||
class="px-3 py-1.5 text-xs font-medium bg-red-600/20 text-red-300 hover:bg-red-600/30 rounded-lg transition"
|
||||
>
|
||||
{{ $t('users.bulk_deactivate') }}
|
||||
</button>
|
||||
<button
|
||||
@click="clearSelection"
|
||||
class="px-3 py-1.5 text-xs font-medium bg-slate-600/20 text-slate-300 hover:bg-slate-600/30 rounded-lg transition"
|
||||
>
|
||||
{{ $t('users.clear_selection') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Data Table -->
|
||||
<div class="bg-slate-800/50 border border-slate-700 rounded-xl overflow-hidden">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="border-b border-slate-700 bg-slate-800/80">
|
||||
<th class="text-left py-3.5 px-4 w-10">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allSelected"
|
||||
@change="toggleSelectAll"
|
||||
class="rounded border-slate-600 bg-slate-700 text-indigo-600 focus:ring-indigo-500/50"
|
||||
/>
|
||||
</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">ID</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.email') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.name') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.role') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.status') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.package') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.registration') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.language') }}</th>
|
||||
<th class="text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400">{{ $t('users.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="user in users"
|
||||
:key="user.id"
|
||||
class="border-b border-slate-700/50 hover:bg-slate-700/30 transition"
|
||||
>
|
||||
<!-- Checkbox -->
|
||||
<td class="py-3.5 px-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="selectedUserIds.includes(user.id)"
|
||||
@change="toggleUserSelection(user.id)"
|
||||
class="rounded border-slate-600 bg-slate-700 text-indigo-600 focus:ring-indigo-500/50"
|
||||
/>
|
||||
</td>
|
||||
<!-- ID -->
|
||||
<td class="py-3.5 px-4 text-slate-400 font-mono text-xs">{{ user.id }}</td>
|
||||
<!-- Email -->
|
||||
<td class="py-3.5 px-4">
|
||||
<NuxtLink
|
||||
:to="'/users/' + user.id"
|
||||
class="text-sm font-medium text-white hover:underline cursor-pointer hover:text-indigo-400 transition-colors"
|
||||
>
|
||||
{{ user.email }}
|
||||
</NuxtLink>
|
||||
</td>
|
||||
<!-- Name -->
|
||||
<td class="py-3.5 px-4">
|
||||
<span class="text-slate-300">{{ user.person_name || '—' }}</span>
|
||||
</td>
|
||||
<!-- Role -->
|
||||
<td class="py-3.5 px-4">
|
||||
<span
|
||||
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium"
|
||||
:class="roleBadgeClass(user.role)"
|
||||
>
|
||||
{{ roleLabel(user.role) }}
|
||||
</span>
|
||||
</td>
|
||||
<!-- Status -->
|
||||
<td class="py-3.5 px-4">
|
||||
<span
|
||||
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium"
|
||||
:class="statusBadgeClass(user)"
|
||||
>
|
||||
<span
|
||||
class="w-1.5 h-1.5 rounded-full mr-1.5"
|
||||
:class="statusDotClass(user)"
|
||||
></span>
|
||||
{{ statusLabel(user) }}
|
||||
</span>
|
||||
</td>
|
||||
<!-- Package -->
|
||||
<td class="py-3.5 px-4">
|
||||
<span
|
||||
class="px-2.5 py-0.5 rounded-full text-xs font-medium"
|
||||
:class="planBadgeClass(user.subscription_plan)"
|
||||
>
|
||||
{{ user.subscription_plan || '—' }}
|
||||
</span>
|
||||
</td>
|
||||
<!-- Registration -->
|
||||
<td class="py-3.5 px-4 text-slate-300 text-xs">
|
||||
{{ formatDate(user.created_at) }}
|
||||
</td>
|
||||
<!-- Language -->
|
||||
<td class="py-3.5 px-4">
|
||||
<span class="text-slate-400 text-xs uppercase">{{ user.preferred_language || '—' }}</span>
|
||||
</td>
|
||||
<!-- Actions -->
|
||||
<td class="py-3.5 px-4">
|
||||
<div class="flex items-center gap-2">
|
||||
<NuxtLink
|
||||
:to="'/users/' + user.id"
|
||||
class="px-3 py-1.5 text-xs font-medium bg-slate-600/20 text-slate-300 hover:bg-slate-600/30 rounded-lg transition"
|
||||
>
|
||||
{{ $t('users.view') }}
|
||||
</NuxtLink>
|
||||
<button
|
||||
v-if="!user.is_deleted && canEditUsers"
|
||||
@click="toggleUserActive(user)"
|
||||
class="px-3 py-1.5 text-xs font-medium rounded-lg transition"
|
||||
:class="user.is_active
|
||||
? 'bg-red-500/10 text-red-300 hover:bg-red-500/20'
|
||||
: 'bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20'"
|
||||
>
|
||||
{{ user.is_active ? $t('users.deactivate') : $t('users.activate') }}
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<!-- Empty State -->
|
||||
<div
|
||||
v-if="users.length === 0 && !loading"
|
||||
class="flex flex-col items-center justify-center py-16 text-center"
|
||||
>
|
||||
<svg class="w-12 h-12 text-slate-600 mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z" />
|
||||
</svg>
|
||||
<p class="text-slate-400 text-sm">{{ $t('users.no_results') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Pagination -->
|
||||
<div v-if="totalCount > limit" class="flex items-center justify-between mt-6">
|
||||
<p class="text-xs text-slate-500">
|
||||
{{ $t('users.showing') }} {{ skip + 1 }}–{{ Math.min(skip + limit, totalCount) }} / {{ totalCount }}
|
||||
</p>
|
||||
<div class="flex items-center gap-2">
|
||||
<button
|
||||
@click="prevPage"
|
||||
:disabled="skip === 0"
|
||||
class="px-3 py-1.5 text-xs font-medium rounded-lg transition disabled:opacity-30 disabled:cursor-not-allowed"
|
||||
:class="skip > 0 ? 'bg-slate-700 text-slate-300 hover:bg-slate-600' : 'bg-slate-800 text-slate-600'"
|
||||
>
|
||||
{{ $t('users.prev') }}
|
||||
</button>
|
||||
<button
|
||||
@click="nextPage"
|
||||
:disabled="skip + limit >= totalCount"
|
||||
class="px-3 py-1.5 text-xs font-medium rounded-lg transition disabled:opacity-30 disabled:cursor-not-allowed"
|
||||
:class="skip + limit < totalCount ? 'bg-slate-700 text-slate-300 hover:bg-slate-600' : 'bg-slate-800 text-slate-600'"
|
||||
>
|
||||
{{ $t('users.next') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Notification -->
|
||||
<div
|
||||
v-if="notification"
|
||||
class="fixed bottom-6 right-6 px-5 py-3 rounded-xl shadow-xl text-sm font-medium z-50"
|
||||
:class="notification.type === 'success'
|
||||
? 'bg-emerald-600 text-white'
|
||||
: 'bg-red-600 text-white'"
|
||||
>
|
||||
{{ notification.message }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, watch } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useAuthStore } from '~/stores/auth'
|
||||
import UserTrendChart from '~/components/charts/UserTrendChart.vue'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
|
||||
definePageMeta({
|
||||
middleware: 'auth',
|
||||
})
|
||||
|
||||
// ── RBAC Permission Check ──────────────────────────────────────────
|
||||
|
||||
const canViewUsers = computed(() => {
|
||||
if (auth.isAdmin) return true
|
||||
return !!auth.user?.system_capabilities?.['users:view']
|
||||
})
|
||||
|
||||
const canEditUsers = computed(() => {
|
||||
if (auth.isAdmin) return true
|
||||
return !!auth.user?.system_capabilities?.['users:edit']
|
||||
})
|
||||
|
||||
const canBanUsers = computed(() => {
|
||||
if (auth.isAdmin) return true
|
||||
return !!auth.user?.system_capabilities?.['users:ban']
|
||||
})
|
||||
|
||||
const canDeleteUsers = computed(() => {
|
||||
if (auth.isAdmin) return true
|
||||
return !!auth.user?.system_capabilities?.['users:delete']
|
||||
})
|
||||
|
||||
// Redirect if no view permission
|
||||
if (!canViewUsers.value && !auth.isAdmin) {
|
||||
router.push('/')
|
||||
}
|
||||
|
||||
// ── Types ──────────────────────────────────────────────────────────
|
||||
|
||||
interface UserListItem {
|
||||
id: number
|
||||
email: string
|
||||
role: string
|
||||
is_active: boolean
|
||||
is_deleted: boolean
|
||||
is_vip: boolean
|
||||
subscription_plan: string
|
||||
preferred_language: string
|
||||
region_code: string
|
||||
created_at: string | null
|
||||
person_name: string | null
|
||||
person_phone: string | null
|
||||
}
|
||||
|
||||
interface UserListResponse {
|
||||
total: number
|
||||
skip: number
|
||||
limit: number
|
||||
users: UserListItem[]
|
||||
}
|
||||
|
||||
interface UserStats {
|
||||
total_users: number
|
||||
active_users: number
|
||||
deleted_users: number
|
||||
banned_users: number
|
||||
new_users_today: number
|
||||
new_users_this_week: number
|
||||
new_users_this_month: number
|
||||
users_by_role: Record<string, number>
|
||||
users_by_plan: Record<string, number>
|
||||
users_by_language: Record<string, number>
|
||||
users_with_person: number
|
||||
users_without_person: number
|
||||
registration_trend: { date: string; count: number }[]
|
||||
active_organizations_count: number
|
||||
total_memberships: number
|
||||
}
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────
|
||||
|
||||
const loading = ref(true)
|
||||
const error = ref<string | null>(null)
|
||||
const users = ref<UserListItem[]>([])
|
||||
const totalCount = ref(0)
|
||||
const skip = ref(0)
|
||||
const limit = ref(50)
|
||||
|
||||
const searchQuery = ref('')
|
||||
const statusFilter = ref('all')
|
||||
const roleFilter = ref('all')
|
||||
const planFilter = ref('all')
|
||||
|
||||
const stats = ref<UserStats>({
|
||||
total_users: 0,
|
||||
active_users: 0,
|
||||
deleted_users: 0,
|
||||
banned_users: 0,
|
||||
new_users_today: 0,
|
||||
new_users_this_week: 0,
|
||||
new_users_this_month: 0,
|
||||
users_by_role: {},
|
||||
users_by_plan: {},
|
||||
users_by_language: {},
|
||||
users_with_person: 0,
|
||||
users_without_person: 0,
|
||||
registration_trend: [],
|
||||
active_organizations_count: 0,
|
||||
total_memberships: 0,
|
||||
})
|
||||
|
||||
// Bulk selection
|
||||
const selectedUserIds = ref<number[]>([])
|
||||
|
||||
// Notification
|
||||
const notification = ref<{ type: 'success' | 'error'; message: string } | null>(null)
|
||||
|
||||
// ── Debounced Search Timer ──────────────────────────────────────────
|
||||
|
||||
let searchDebounceTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
function debouncedFetchUsers() {
|
||||
if (searchDebounceTimer) {
|
||||
clearTimeout(searchDebounceTimer)
|
||||
}
|
||||
searchDebounceTimer = setTimeout(() => {
|
||||
skip.value = 0
|
||||
fetchUsers()
|
||||
}, 400)
|
||||
}
|
||||
|
||||
// ── Watchers ────────────────────────────────────────────────────────
|
||||
|
||||
watch(searchQuery, () => {
|
||||
debouncedFetchUsers()
|
||||
})
|
||||
|
||||
watch(statusFilter, () => {
|
||||
skip.value = 0
|
||||
fetchUsers()
|
||||
})
|
||||
|
||||
watch(roleFilter, () => {
|
||||
skip.value = 0
|
||||
fetchUsers()
|
||||
})
|
||||
|
||||
watch(planFilter, () => {
|
||||
skip.value = 0
|
||||
fetchUsers()
|
||||
})
|
||||
|
||||
// ── Computed ───────────────────────────────────────────────────────
|
||||
|
||||
const isFilterActive = computed(() => {
|
||||
return searchQuery.value !== '' || statusFilter.value !== 'all' || roleFilter.value !== 'all' || planFilter.value !== 'all'
|
||||
})
|
||||
|
||||
const allSelected = computed(() => {
|
||||
return users.value.length > 0 && selectedUserIds.value.length === users.value.length
|
||||
})
|
||||
|
||||
// ── Auth Helper ────────────────────────────────────────────────────
|
||||
|
||||
function getAuthHeaders() {
|
||||
const tokenCookie = useCookie('access_token')
|
||||
const token = tokenCookie.value
|
||||
return token ? { Authorization: `Bearer ${token}` } : {}
|
||||
}
|
||||
|
||||
// ── Data Fetching ──────────────────────────────────────────────────
|
||||
|
||||
async function fetchUsers() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const params: Record<string, any> = { skip: skip.value, limit: limit.value }
|
||||
|
||||
if (searchQuery.value) {
|
||||
params.search_term = searchQuery.value
|
||||
}
|
||||
// Status filter mapping: frontend uses combined status_filter, backend uses is_active/is_deleted
|
||||
if (statusFilter.value !== 'all') {
|
||||
switch (statusFilter.value) {
|
||||
case 'active':
|
||||
params.is_active = true
|
||||
break
|
||||
case 'inactive':
|
||||
params.is_active = false
|
||||
break
|
||||
case 'deleted':
|
||||
params.is_deleted = true
|
||||
break
|
||||
case 'banned':
|
||||
params.is_active = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (roleFilter.value !== 'all') {
|
||||
params.role = roleFilter.value
|
||||
}
|
||||
if (planFilter.value !== 'all') {
|
||||
params.plan_filter = planFilter.value
|
||||
}
|
||||
|
||||
const response = await $fetch<UserListResponse>('/api/v1/admin/users', {
|
||||
params,
|
||||
headers: getAuthHeaders(),
|
||||
})
|
||||
users.value = response.users
|
||||
totalCount.value = response.total
|
||||
} catch (err: any) {
|
||||
console.error('[Users] Failed to fetch users:', err)
|
||||
error.value = err?.data?.detail || err?.message || 'Failed to load users'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchStats() {
|
||||
try {
|
||||
const response = await $fetch<UserStats>('/api/v1/admin/users/stats', {
|
||||
headers: getAuthHeaders(),
|
||||
})
|
||||
stats.value = response
|
||||
} catch (err: any) {
|
||||
console.error('[Users] Failed to fetch stats:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Pagination ─────────────────────────────────────────────────────
|
||||
|
||||
function nextPage() {
|
||||
if (skip.value + limit.value < totalCount.value) {
|
||||
skip.value += limit.value
|
||||
fetchUsers()
|
||||
}
|
||||
}
|
||||
|
||||
function prevPage() {
|
||||
if (skip.value > 0) {
|
||||
skip.value = Math.max(0, skip.value - limit.value)
|
||||
fetchUsers()
|
||||
}
|
||||
}
|
||||
|
||||
// ── Bulk Selection ─────────────────────────────────────────────────
|
||||
|
||||
function toggleSelectAll() {
|
||||
if (allSelected.value) {
|
||||
selectedUserIds.value = []
|
||||
} else {
|
||||
selectedUserIds.value = users.value.map(u => u.id)
|
||||
}
|
||||
}
|
||||
|
||||
function toggleUserSelection(userId: number) {
|
||||
const idx = selectedUserIds.value.indexOf(userId)
|
||||
if (idx === -1) {
|
||||
selectedUserIds.value.push(userId)
|
||||
} else {
|
||||
selectedUserIds.value.splice(idx, 1)
|
||||
}
|
||||
}
|
||||
|
||||
function clearSelection() {
|
||||
selectedUserIds.value = []
|
||||
}
|
||||
|
||||
async function bulkActivate() {
|
||||
if (selectedUserIds.value.length === 0) return
|
||||
try {
|
||||
await $fetch('/api/v1/admin/users/bulk-action', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: {
|
||||
user_ids: selectedUserIds.value,
|
||||
action: 'activate',
|
||||
},
|
||||
})
|
||||
showNotification('success', `${selectedUserIds.value.length} user(s) activated successfully`)
|
||||
selectedUserIds.value = []
|
||||
await fetchUsers()
|
||||
await fetchStats()
|
||||
} catch (err: any) {
|
||||
console.error('[Users] Bulk activate failed:', err)
|
||||
showNotification('error', err?.data?.detail || err?.message || 'Bulk activate failed')
|
||||
}
|
||||
}
|
||||
|
||||
async function bulkDeactivate() {
|
||||
if (selectedUserIds.value.length === 0) return
|
||||
try {
|
||||
await $fetch('/api/v1/admin/users/bulk-action', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: {
|
||||
user_ids: selectedUserIds.value,
|
||||
action: 'deactivate',
|
||||
},
|
||||
})
|
||||
showNotification('success', `${selectedUserIds.value.length} user(s) deactivated successfully`)
|
||||
selectedUserIds.value = []
|
||||
await fetchUsers()
|
||||
await fetchStats()
|
||||
} catch (err: any) {
|
||||
console.error('[Users] Bulk deactivate failed:', err)
|
||||
showNotification('error', err?.data?.detail || err?.message || 'Bulk deactivate failed')
|
||||
}
|
||||
}
|
||||
|
||||
// ── Single User Toggle ─────────────────────────────────────────────
|
||||
|
||||
async function toggleUserActive(user: UserListItem) {
|
||||
const newActive = !user.is_active
|
||||
try {
|
||||
await $fetch(`/api/v1/admin/users/${user.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
...getAuthHeaders(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: { is_active: newActive },
|
||||
})
|
||||
showNotification('success', `User "${user.email}" ${newActive ? 'activated' : 'deactivated'} successfully`)
|
||||
await fetchUsers()
|
||||
await fetchStats()
|
||||
} catch (err: any) {
|
||||
console.error('[Users] Toggle status failed:', err)
|
||||
showNotification('error', err?.data?.detail || err?.message || 'Failed to toggle user status')
|
||||
}
|
||||
}
|
||||
|
||||
// ── Helpers ────────────────────────────────────────────────────────
|
||||
|
||||
function roleBadgeClass(role: string): string {
|
||||
const r = role.toLowerCase()
|
||||
if (r === 'superadmin') return 'bg-purple-500/20 text-purple-300'
|
||||
if (r === 'admin') return 'bg-indigo-500/20 text-indigo-300'
|
||||
if (r === 'staff') return 'bg-cyan-500/20 text-cyan-300'
|
||||
return 'bg-slate-500/20 text-slate-300'
|
||||
}
|
||||
|
||||
function roleLabel(role: string): string {
|
||||
const r = role.toLowerCase()
|
||||
if (r === 'superadmin') return 'Superadmin'
|
||||
if (r === 'admin') return 'Admin'
|
||||
if (r === 'staff') return 'Staff'
|
||||
return 'User'
|
||||
}
|
||||
|
||||
function statusBadgeClass(user: UserListItem): string {
|
||||
if (user.is_deleted) return 'bg-red-500/10 text-red-400'
|
||||
if (!user.is_active) return 'bg-amber-500/10 text-amber-400'
|
||||
return 'bg-emerald-500/10 text-emerald-400'
|
||||
}
|
||||
|
||||
function statusDotClass(user: UserListItem): string {
|
||||
if (user.is_deleted) return 'bg-red-400'
|
||||
if (!user.is_active) return 'bg-amber-400'
|
||||
return 'bg-emerald-400'
|
||||
}
|
||||
|
||||
function statusLabel(user: UserListItem): string {
|
||||
if (user.is_deleted) return 'Deleted'
|
||||
if (!user.is_active) return 'Inactive'
|
||||
return 'Active'
|
||||
}
|
||||
|
||||
function planBadgeClass(plan: string): string {
|
||||
const p = (plan || '').toLowerCase()
|
||||
if (p.includes('enterprise') || p.includes('vip')) return 'bg-purple-500/20 text-purple-300'
|
||||
if (p.includes('premium') || p.includes('pro')) return 'bg-amber-500/20 text-amber-300'
|
||||
return 'bg-slate-500/20 text-slate-300'
|
||||
}
|
||||
|
||||
function formatDate(dateStr: string | null): string {
|
||||
if (!dateStr) return '—'
|
||||
try {
|
||||
const d = new Date(dateStr)
|
||||
return d.toLocaleDateString('hu-HU', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
})
|
||||
} catch {
|
||||
return dateStr
|
||||
}
|
||||
}
|
||||
|
||||
function showNotification(type: 'success' | 'error', message: string) {
|
||||
notification.value = { type, message }
|
||||
setTimeout(() => {
|
||||
notification.value = null
|
||||
}, 4000)
|
||||
}
|
||||
|
||||
// ── Lifecycle ──────────────────────────────────────────────────────
|
||||
|
||||
onMounted(() => {
|
||||
fetchUsers()
|
||||
fetchStats()
|
||||
})
|
||||
</script>
|
||||
Reference in New Issue
Block a user