%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/
Upload File :
Create Path :
Current File : /home2/rezakur1/ai.rezakurnia.com/zh-router-frontend/src/pages/LoginPage.tsx

import { useState, type FormEvent } from "react";
import { Link, useLocation, useNavigate } from "react-router-dom";
import Button from "@/components/ui/Button";
import Input from "@/components/ui/Input";
import GoogleAuthButton from "@/components/ui/GoogleAuthButton";
import AuthShell from "@/components/auth/AuthShell";
import { useAuth } from "@/contexts/AuthContext";

export default function LoginPage() {
  const { login } = useAuth();
  const navigate = useNavigate();
  const location = useLocation();

  const [email, setEmail] = useState("");
  const [password, setPassword] = useState("");
  const [error, setError] = useState<string | null>(
    (location.state as { oauthError?: string } | null)?.oauthError ?? null,
  );
  const [loading, setLoading] = useState(false);

  const handleSubmit = async (e: FormEvent) => {
    e.preventDefault();
    setError(null);
    setLoading(true);

    try {
      await login(email, password);
      navigate("/dashboard");
    } catch (err) {
      setError(err instanceof Error ? err.message : "Login gagal");
    } finally {
      setLoading(false);
    }
  };

  return (
    <AuthShell>
      <div className="p-6 sm:p-8">
        <form onSubmit={handleSubmit} className="space-y-5">
          <div className="flex flex-col items-center gap-3 text-center">
            <img
              src="/logo-kd.png"
              alt="KURNIADEV AI"
              className="h-12 w-auto rounded-xl object-contain shadow-soft"
            />
            <div>
              <h1 className="text-lg font-bold tracking-tight text-white">
                KURNIADEV AI{" "}
                <span className="font-normal text-slate-400">API Gateway</span>
              </h1>
              <p className="mt-1 text-sm text-slate-500">
                Masuk untuk mengelola gateway AI Anda.
              </p>
            </div>
          </div>

          {error && (
            <div className="animate-fade-in rounded-xl border border-red-500/25 bg-red-500/10 px-4 py-3 text-sm text-red-300">
              {error}
            </div>
          )}

          <Input
            label="Email"
            type="email"
            required
            autoComplete="email"
            placeholder="nama@contoh.com"
            value={email}
            onChange={(e) => setEmail(e.target.value)}
          />
          <Input
            label="Password"
            type="password"
            required
            autoComplete="current-password"
            placeholder="••••••••"
            value={password}
            onChange={(e) => setPassword(e.target.value)}
          />

          <Button type="submit" size="lg" isLoading={loading} className="w-full">
            Masuk
          </Button>

          <GoogleAuthButton />

          <p className="text-center text-sm text-slate-500">
            Belum punya akun?{" "}
            <Link
              to="/register"
              className="font-medium accent-text transition hover:text-brand-200"
            >
              Daftar sekarang
            </Link>
          </p>
        </form>
      </div>
    </AuthShell>
  );
}

Zerion Mini Shell 1.0