166 lines
8.1 KiB
TypeScript
166 lines
8.1 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import { loginUser } from '@/app/actions'
|
|
import { Button } from '@/components/ui/button'
|
|
import { Input } from '@/components/ui/input'
|
|
import { LogIn, KeyRound, User, Loader2, Eye, EyeOff } from 'lucide-react'
|
|
|
|
export default function LoginPage() {
|
|
const router = useRouter()
|
|
const [loading, setLoading] = useState(false)
|
|
const [error, setError] = useState('')
|
|
const [showPassword, setShowPassword] = useState(false)
|
|
|
|
async function handleSubmit(e: React.FormEvent<HTMLFormElement>) {
|
|
e.preventDefault()
|
|
setLoading(true)
|
|
setError('')
|
|
|
|
const formData = new FormData(e.currentTarget)
|
|
const username = (formData.get('username') as string).trim()
|
|
const password = formData.get('password') as string
|
|
|
|
if (!username || !password) {
|
|
setError('Username dan Password wajib diisi')
|
|
setLoading(false)
|
|
return
|
|
}
|
|
|
|
const res = await loginUser(username, password)
|
|
if (res.success) {
|
|
const params = new URLSearchParams(window.location.search)
|
|
const callbackUrl = params.get('callbackUrl') || '/'
|
|
window.location.href = callbackUrl // Force hard reload to update context/middleware
|
|
} else {
|
|
setError(res.error || 'Gagal login')
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-950 p-4 lg:p-6 relative overflow-hidden">
|
|
{/* Elegant Ambient Background */}
|
|
<div className="absolute inset-0 z-0 pointer-events-none">
|
|
<div className="absolute inset-0 bg-[linear-gradient(to_right,#80808012_1px,transparent_1px),linear-gradient(to_bottom,#80808012_1px,transparent_1px)] bg-[size:24px_24px] [mask-image:radial-gradient(ellipse_60%_50%_at_50%_0%,#000_70%,transparent_100%)]"></div>
|
|
<div className="absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 h-[400px] w-[600px] rounded-full bg-[#1B2CC1] opacity-10 dark:opacity-20 blur-[120px]"></div>
|
|
</div>
|
|
|
|
<div className="w-full max-w-5xl bg-white dark:bg-slate-900 lg:rounded-[2.5rem] rounded-3xl shadow-2xl shadow-[#1B2CC1]/10 flex overflow-hidden border border-slate-100 dark:border-slate-800 relative z-10">
|
|
|
|
{/* Left Side: Branding (Hidden on Mobile) */}
|
|
<div className="hidden lg:flex w-1/2 bg-gradient-to-br from-[#1B2CC1] to-[#121E85] p-12 flex-col justify-between relative overflow-hidden">
|
|
<div className="absolute top-0 left-0 w-full h-full pointer-events-none">
|
|
<div className="absolute -top-[20%] -left-[10%] w-[60%] h-[60%] rounded-full bg-white/10 blur-3xl" />
|
|
<div className="absolute top-[60%] -right-[10%] w-[70%] h-[70%] rounded-full bg-blue-400/20 blur-3xl" />
|
|
</div>
|
|
|
|
<div className="relative z-10">
|
|
<div className="inline-flex items-center justify-center p-3 bg-white/10 rounded-2xl backdrop-blur-md border border-white/20 mb-8 shadow-sm">
|
|
<LogIn className="w-8 h-8 text-white" />
|
|
</div>
|
|
<h1 className="text-4xl font-black text-white leading-tight">
|
|
Selamat Datang <br /> di TitipIn
|
|
</h1>
|
|
<p className="text-blue-100 mt-4 text-base max-w-sm leading-relaxed">
|
|
Platform modern dan terpercaya untuk mengelola pesanan jasa titip Anda dengan rapi, efisien, dan transparan.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="relative z-10 flex items-center gap-4 bg-white/10 p-4 rounded-2xl backdrop-blur-sm border border-white/10 w-fit">
|
|
<div className="flex -space-x-3">
|
|
<div className="w-10 h-10 rounded-full bg-blue-200 border-2 border-[#121E85] flex items-center justify-center text-[10px] font-bold text-blue-700">A</div>
|
|
<div className="w-10 h-10 rounded-full bg-purple-200 border-2 border-[#121E85] flex items-center justify-center text-[10px] font-bold text-purple-700">B</div>
|
|
<div className="w-10 h-10 rounded-full bg-amber-200 border-2 border-[#121E85] flex items-center justify-center text-[10px] font-bold text-amber-700">C</div>
|
|
</div>
|
|
<p className="text-xs text-blue-100 font-medium">Bergabung dengan ribuan<br/>pengguna lainnya.</p>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Right Side: Form */}
|
|
<div className="w-full lg:w-1/2 p-8 lg:p-14 flex flex-col justify-center">
|
|
<div className="lg:hidden flex flex-col items-center mb-8">
|
|
<div className="w-16 h-16 rounded-2xl bg-gradient-to-br from-[#1B2CC1] to-[#121E85] flex items-center justify-center text-white shadow-lg shadow-[#1B2CC1]/25 mb-4">
|
|
<LogIn className="w-8 h-8" />
|
|
</div>
|
|
<h1 className="text-2xl font-black text-slate-900 dark:text-white">TitipIn</h1>
|
|
</div>
|
|
|
|
<div className="mb-8 text-center lg:text-left">
|
|
<h2 className="text-2xl font-black text-slate-900 dark:text-white hidden lg:block mb-2">Masuk ke Akun</h2>
|
|
<p className="text-sm text-slate-500">Silakan masukkan kredensial Anda untuk melanjutkan</p>
|
|
</div>
|
|
|
|
{error && (
|
|
<div className="bg-rose-50 text-rose-600 p-3 rounded-xl text-sm font-medium mb-6 border border-rose-100 text-center">
|
|
{error}
|
|
</div>
|
|
)}
|
|
|
|
<form onSubmit={handleSubmit} className="space-y-5">
|
|
<div className="space-y-2">
|
|
<label className="text-xs font-bold text-slate-700 dark:text-slate-300 uppercase tracking-wider">Username</label>
|
|
<div className="relative">
|
|
<User className="absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400" />
|
|
<Input
|
|
name="username"
|
|
className="pl-10 h-12 bg-slate-50 dark:bg-slate-800/50 rounded-xl border-slate-200 focus-visible:ring-[#1B2CC1]"
|
|
placeholder="Masukkan username"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-2">
|
|
<label className="text-xs font-bold text-slate-700 dark:text-slate-300 uppercase tracking-wider">Password</label>
|
|
<div className="relative flex items-center">
|
|
<KeyRound className="absolute left-3.5 w-4 h-4 text-slate-400" />
|
|
<Input
|
|
name="password"
|
|
type={showPassword ? 'text' : 'password'}
|
|
className="pl-10 pr-12 h-12 bg-slate-50 dark:bg-slate-800/50 rounded-xl border-slate-200 focus-visible:ring-[#1B2CC1]"
|
|
placeholder="Masukkan password"
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => setShowPassword(!showPassword)}
|
|
className="absolute right-3.5 text-slate-400 hover:text-slate-600 dark:hover:text-slate-200 transition-colors cursor-pointer"
|
|
aria-label={showPassword ? 'Sembunyikan password' : 'Tampilkan password'}
|
|
>
|
|
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<Button
|
|
type="submit"
|
|
disabled={loading}
|
|
className="w-full h-12 rounded-xl bg-[#1B2CC1] hover:bg-[#15229E] text-white font-bold text-base shadow-md shadow-[#1B2CC1]/20 transition-all active:scale-[0.98] mt-2 cursor-pointer"
|
|
>
|
|
{loading ? <Loader2 className="w-5 h-5 animate-spin" /> : 'Masuk Sekarang'}
|
|
</Button>
|
|
</form>
|
|
|
|
<p className="text-center text-sm text-slate-500 mt-8">
|
|
Belum punya akun?{' '}
|
|
<button
|
|
onClick={() => {
|
|
const search = window.location.search
|
|
router.push(`/register${search}`)
|
|
}}
|
|
className="font-bold text-[#1B2CC1] hover:underline cursor-pointer"
|
|
>
|
|
Daftar di sini
|
|
</button>
|
|
</p>
|
|
|
|
<p className="text-center text-xs text-slate-400 mt-12 font-medium">
|
|
© {new Date().getFullYear()} TitipIn - Sistem Titip Pesanan
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|