geo/frontend/app/(auth)/forgot-password/page.tsx

101 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useState } from "react";
import Link from "next/link";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Card,
CardContent,
CardDescription,
CardFooter,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { api } from "@/lib/api";
export default function ForgotPasswordPage() {
const [email, setEmail] = useState("");
const [error, setError] = useState("");
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
setError("");
try {
await api.auth.forgotPassword(email);
setSuccess(true);
} catch (err: unknown) {
const message = err instanceof Error ? err.message : "请求失败";
setError(message);
} finally {
setLoading(false);
}
};
if (success) {
return (
<Card className="w-full max-w-md">
<CardHeader className="space-y-1">
<CardTitle className="text-2xl"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
</p>
</CardContent>
<CardFooter>
<Link
href="/login"
className="text-sm text-primary hover:underline"
>
</Link>
</CardFooter>
</Card>
);
}
return (
<Card className="w-full max-w-md">
<CardHeader className="space-y-1">
<CardTitle className="text-2xl"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<form onSubmit={handleSubmit}>
<CardContent className="space-y-4">
{error && (
<p className="text-sm text-destructive">{error}</p>
)}
<div className="space-y-2">
<Label htmlFor="email"></Label>
<Input
id="email"
type="email"
placeholder="name@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
/>
</div>
</CardContent>
<CardFooter className="flex flex-col space-y-4">
<Button type="submit" className="w-full" disabled={loading}>
{loading ? "发送中..." : "发送重置链接"}
</Button>
<Link
href="/login"
className="text-sm text-primary hover:underline"
>
</Link>
</CardFooter>
</form>
</Card>
);
}