feature: add user verify page
This commit is contained in:
parent
ffb1fafc7e
commit
6aec40b660
326
src/app/admin/user-verify/page.tsx
Normal file
326
src/app/admin/user-verify/page.tsx
Normal file
@ -0,0 +1,326 @@
|
|||||||
|
'use client'
|
||||||
|
|
||||||
|
import { useMemo, useState, useCallback } from 'react'
|
||||||
|
import PageLayout from '../../components/PageLayout'
|
||||||
|
import {
|
||||||
|
MagnifyingGlassIcon,
|
||||||
|
CheckIcon
|
||||||
|
} from '@heroicons/react/24/outline'
|
||||||
|
|
||||||
|
type UserType = 'personal' | 'company'
|
||||||
|
type UserRole = 'user' | 'admin'
|
||||||
|
interface PendingUser {
|
||||||
|
id: string
|
||||||
|
firstName: string
|
||||||
|
lastName: string
|
||||||
|
email: string
|
||||||
|
type: UserType
|
||||||
|
role: UserRole
|
||||||
|
created: string
|
||||||
|
lastLogin: string
|
||||||
|
status: 'pending' | 'verifying' | 'active'
|
||||||
|
}
|
||||||
|
|
||||||
|
const TYPES: UserType[] = ['personal', 'company']
|
||||||
|
const ROLES: UserRole[] = ['user', 'admin']
|
||||||
|
|
||||||
|
const rand = <T,>(arr: T[]) => arr[Math.floor(Math.random() * arr.length)]
|
||||||
|
const daysAgo = (d: number) => {
|
||||||
|
const dt = new Date()
|
||||||
|
dt.setDate(dt.getDate() - d)
|
||||||
|
return dt.toISOString().slice(0, 10)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function AdminUserVerifyPage() {
|
||||||
|
// Mock pending users (only a small subset)
|
||||||
|
const seedUsers = useMemo<PendingUser[]>(() => {
|
||||||
|
const first = ['Avgust', 'Katarina', 'Ana', 'Luka', 'Sara', 'Jonas', 'Niko', 'Eva']
|
||||||
|
const last = ['Senica', 'Fedzer', 'Hochkraut', 'Novak', 'Schmidt', 'Keller', 'Mayr', 'Hansen']
|
||||||
|
const list: PendingUser[] = []
|
||||||
|
for (let i = 0; i < 18; i++) {
|
||||||
|
const fn = rand(first)
|
||||||
|
const ln = rand(last)
|
||||||
|
list.push({
|
||||||
|
id: `P${i + 1}`,
|
||||||
|
firstName: fn,
|
||||||
|
lastName: ln,
|
||||||
|
email: `${fn}.${ln}${i}@example.com`.toLowerCase(),
|
||||||
|
type: Math.random() > 0.9 ? 'company' : 'personal',
|
||||||
|
role: Math.random() > 0.95 ? 'admin' : 'user',
|
||||||
|
created: daysAgo(Math.floor(Math.random() * 12)),
|
||||||
|
lastLogin: daysAgo(Math.floor(Math.random() * 5)),
|
||||||
|
status: 'pending'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
const [users, setUsers] = useState<PendingUser[]>(seedUsers)
|
||||||
|
const [search, setSearch] = useState('')
|
||||||
|
const [fType, setFType] = useState<'all' | UserType>('all')
|
||||||
|
const [fRole, setFRole] = useState<'all' | UserRole>('all')
|
||||||
|
const [perPage, setPerPage] = useState(10)
|
||||||
|
const [page, setPage] = useState(1)
|
||||||
|
|
||||||
|
const filtered = useMemo(() => {
|
||||||
|
return users.filter(u =>
|
||||||
|
u.status === 'pending' &&
|
||||||
|
(fType === 'all' || u.type === fType) &&
|
||||||
|
(fRole === 'all' || u.role === fRole) &&
|
||||||
|
(
|
||||||
|
!search.trim() ||
|
||||||
|
u.email.toLowerCase().includes(search.toLowerCase()) ||
|
||||||
|
`${u.firstName} ${u.lastName}`.toLowerCase().includes(search.toLowerCase())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}, [users, search, fType, fRole])
|
||||||
|
|
||||||
|
const totalPages = Math.max(1, Math.ceil(filtered.length / perPage))
|
||||||
|
const current = filtered.slice((page - 1) * perPage, page * perPage)
|
||||||
|
|
||||||
|
const applyFilters = (e: React.FormEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
setPage(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
const badge = (text: string, color: string) =>
|
||||||
|
<span className={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-medium ${color}`}>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
const typeBadge = (t: UserType) =>
|
||||||
|
t === 'personal'
|
||||||
|
? badge('Personal', 'bg-blue-100 text-blue-700')
|
||||||
|
: badge('Company', 'bg-purple-100 text-purple-700')
|
||||||
|
|
||||||
|
const roleBadge = (r: UserRole) =>
|
||||||
|
r === 'admin'
|
||||||
|
? badge('Admin', 'bg-indigo-100 text-indigo-700')
|
||||||
|
: badge('User', 'bg-gray-100 text-gray-700')
|
||||||
|
|
||||||
|
const statusBadge = (s: PendingUser['status']) => {
|
||||||
|
if (s === 'pending') return badge('Pending', 'bg-amber-100 text-amber-700')
|
||||||
|
if (s === 'verifying') return badge('Verifying', 'bg-blue-100 text-blue-700')
|
||||||
|
return badge('Active', 'bg-green-100 text-green-700')
|
||||||
|
}
|
||||||
|
|
||||||
|
const verifyUser = useCallback((id: string) => {
|
||||||
|
setUsers(prev => prev.map(u => u.id === id ? { ...u, status: 'verifying' } : u))
|
||||||
|
// simulate async approval
|
||||||
|
setTimeout(() => {
|
||||||
|
setUsers(prev => prev.map(u => u.id === id ? { ...u, status: 'active' } : u))
|
||||||
|
}, 900)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageLayout>
|
||||||
|
<div className="relative flex flex-col flex-1 px-4 sm:px-6 lg:px-10 py-10">
|
||||||
|
{/* Background */}
|
||||||
|
<div className="fixed inset-0 -z-10">
|
||||||
|
<div className="absolute inset-0 -z-20 bg-gradient-to-tr from-[#0d3894] via-[#1860d2] to-[#1d66d9]" />
|
||||||
|
<svg aria-hidden="true" className="absolute inset-0 h-full w-full stroke-white/10">
|
||||||
|
<defs>
|
||||||
|
<pattern id="admin-user-verify-pattern" x="50%" y={-1} width={200} height={200} patternUnits="userSpaceOnUse">
|
||||||
|
<path d="M.5 200V.5H200" fill="none" stroke="rgba(255,255,255,0.05)" />
|
||||||
|
</pattern>
|
||||||
|
</defs>
|
||||||
|
<rect fill="url(#admin-user-verify-pattern)" width="100%" height="100%" strokeWidth={0} />
|
||||||
|
</svg>
|
||||||
|
<div
|
||||||
|
aria-hidden="true"
|
||||||
|
className="absolute top-0 right-0 left-1/2 -ml-24 blur-3xl transform-gpu overflow-hidden lg:ml-24 xl:ml-48"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="aspect-[801/1036] w-[50.0625rem] bg-gradient-to-tr from-[#5b8dff] to-[#a78bfa] opacity-40"
|
||||||
|
style={{ clipPath: 'polygon(63.1% 29.5%,100% 17.1%,76.6% 3%,48.4% 0%,44.6% 4.7%,54.5% 25.3%,59.8% 49%,55.2% 57.8%,44.4% 57.2%,27.8% 47.9%,35.1% 81.5%,0% 97.7%,39.2% 100%,35.2% 81.4%,97.2% 52.8%,63.1% 29.5%)' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Outer container */}
|
||||||
|
<div className="relative mx-auto w-full max-w-7xl space-y-8 bg-white/95 backdrop-blur rounded-2xl shadow-2xl ring-1 ring-black/10 p-6 sm:p-10">
|
||||||
|
<div className="text-center">
|
||||||
|
<h1 className="text-3xl sm:text-4xl font-bold tracking-tight text-[#0e2f63]">
|
||||||
|
Users Pending Verification
|
||||||
|
</h1>
|
||||||
|
<p className="mt-2 text-sm sm:text-base text-[#33507d] font-medium">
|
||||||
|
Review and verify users who have completed all registration steps.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Filter Card */}
|
||||||
|
<form
|
||||||
|
onSubmit={applyFilters}
|
||||||
|
className="bg-white rounded-xl shadow-sm ring-1 ring-gray-200 px-4 sm:px-6 py-5 flex flex-col gap-4"
|
||||||
|
>
|
||||||
|
<h2 className="text-sm font-semibold text-[#0f2c55]">
|
||||||
|
Search & Filter Pending Users
|
||||||
|
</h2>
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-6 gap-4">
|
||||||
|
<div className="md:col-span-2">
|
||||||
|
<label className="sr-only">Search</label>
|
||||||
|
<div className="relative">
|
||||||
|
<MagnifyingGlassIcon className="absolute left-3 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400" />
|
||||||
|
<input
|
||||||
|
value={search}
|
||||||
|
onChange={e => setSearch(e.target.value)}
|
||||||
|
placeholder="Email, name, company..."
|
||||||
|
className="w-full rounded-md border border-gray-300 pl-10 pr-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<select
|
||||||
|
value={fType}
|
||||||
|
onChange={e => { setFType(e.target.value as any); setPage(1) }}
|
||||||
|
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||||
|
>
|
||||||
|
<option value="all">All Types</option>
|
||||||
|
<option value="personal">Personal</option>
|
||||||
|
<option value="company">Company</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<select
|
||||||
|
value={fRole}
|
||||||
|
onChange={e => { setFRole(e.target.value as any); setPage(1) }}
|
||||||
|
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||||
|
>
|
||||||
|
<option value="all">All Roles</option>
|
||||||
|
<option value="user">User</option>
|
||||||
|
<option value="admin">Admin</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<select
|
||||||
|
value={perPage}
|
||||||
|
onChange={e => { setPerPage(parseInt(e.target.value, 10)); setPage(1) }}
|
||||||
|
className="w-full rounded-md border border-gray-300 px-3 py-2 text-sm focus:ring-2 focus:ring-indigo-500 focus:border-transparent"
|
||||||
|
>
|
||||||
|
{[5, 10, 15, 20].map(n => <option key={n} value={n}>{n}</option>)}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-stretch">
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
className="w-full inline-flex items-center justify-center rounded-md bg-blue-600 hover:bg-blue-500 text-white text-sm font-semibold px-5 py-2.5 shadow transition"
|
||||||
|
>
|
||||||
|
Filter
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{/* Pending Users Table */}
|
||||||
|
<div className="bg-white rounded-xl shadow-sm ring-1 ring-gray-200 overflow-hidden">
|
||||||
|
<div className="px-5 py-4 border-b border-gray-100 flex items-center justify-between">
|
||||||
|
<div className="text-sm font-semibold text-[#0f2c55]">
|
||||||
|
Users Pending Verification
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-gray-500">
|
||||||
|
Showing {current.length} of {filtered.length} users
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="overflow-x-auto">
|
||||||
|
<table className="min-w-full divide-y divide-gray-100 text-sm">
|
||||||
|
<thead className="bg-gray-50 text-gray-600 font-medium">
|
||||||
|
<tr>
|
||||||
|
<th className="px-4 py-2 text-left">User</th>
|
||||||
|
<th className="px-4 py-2 text-left">Type</th>
|
||||||
|
<th className="px-4 py-2 text-left">Status</th>
|
||||||
|
<th className="px-4 py-2 text-left">Role</th>
|
||||||
|
<th className="px-4 py-2 text-left">Created</th>
|
||||||
|
<th className="px-4 py-2 text-left">Last Login</th>
|
||||||
|
<th className="px-4 py-2 text-left">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-gray-100">
|
||||||
|
{current.map(u => {
|
||||||
|
const initials = `${u.firstName[0]}${u.lastName[0]}`.toUpperCase()
|
||||||
|
return (
|
||||||
|
<tr key={u.id} className="hover:bg-gray-50">
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<div className="h-9 w-9 flex items-center justify-center rounded-full bg-gradient-to-br from-indigo-500 to-indigo-600 text-white text-xs font-semibold shadow">
|
||||||
|
{initials}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="font-medium text-gray-900 leading-tight">
|
||||||
|
{u.firstName} {u.lastName}
|
||||||
|
</div>
|
||||||
|
<div className="text-[11px] text-gray-500">{u.email}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td className="px-4 py-3">{typeBadge(u.type)}</td>
|
||||||
|
<td className="px-4 py-3">{statusBadge(u.status)}</td>
|
||||||
|
<td className="px-4 py-3">{roleBadge(u.role)}</td>
|
||||||
|
<td className="px-4 py-3 text-gray-700">{u.created}</td>
|
||||||
|
<td className="px-4 py-3 text-gray-500 italic">{u.lastLogin}</td>
|
||||||
|
<td className="px-4 py-3">
|
||||||
|
{u.status === 'active' ? (
|
||||||
|
<span className="text-xs font-medium text-emerald-600">Verified</span>
|
||||||
|
) : (
|
||||||
|
<button
|
||||||
|
onClick={() => verifyUser(u.id)}
|
||||||
|
disabled={u.status !== 'pending'}
|
||||||
|
className={`inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs font-medium transition
|
||||||
|
${u.status === 'pending'
|
||||||
|
? 'border-emerald-200 bg-emerald-50 hover:bg-emerald-100 text-emerald-700'
|
||||||
|
: 'border-gray-200 bg-gray-100 text-gray-400 cursor-not-allowed'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{u.status === 'verifying' ? (
|
||||||
|
<>
|
||||||
|
<span className="h-3 w-3 rounded-full border-2 border-emerald-500 border-b-transparent animate-spin" />
|
||||||
|
Verifying...
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<CheckIcon className="h-4 w-4" /> Verify
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
{current.length === 0 && (
|
||||||
|
<tr>
|
||||||
|
<td colSpan={7} className="px-4 py-10 text-center text-sm text-gray-500">
|
||||||
|
No pending users match current filters.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
)}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{/* Pagination */}
|
||||||
|
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-4 px-5 py-4 bg-gray-50 border-t border-gray-100">
|
||||||
|
<div className="text-xs text-gray-600">
|
||||||
|
Page {page} of {totalPages} ({filtered.length} pending users)
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
disabled={page === 1}
|
||||||
|
onClick={() => setPage(p => Math.max(1, p - 1))}
|
||||||
|
className="px-3 py-1.5 text-xs font-medium rounded-md border border-gray-300 bg-white hover:bg-gray-100 disabled:opacity-40 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
‹ Previous
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
disabled={page === totalPages}
|
||||||
|
onClick={() => setPage(p => Math.min(totalPages, p + 1))}
|
||||||
|
className="px-3 py-1.5 text-xs font-medium rounded-md border border-gray-300 bg-white hover:bg-gray-100 disabled:opacity-40 disabled:cursor-not-allowed"
|
||||||
|
>
|
||||||
|
Next ›
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</PageLayout>
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user