Files
zellyy-finance/src/pages/ForgotPassword.tsx
gpt-engineer-app[bot] fd34c62170 Refactor AuthContext into smaller files
Refactors the AuthContext.tsx file into smaller, more manageable files to improve code organization and maintainability. The functionality remains the same.
2025-03-15 06:57:27 +00:00

105 lines
3.6 KiB
TypeScript

import React, { useState } from "react";
import { Link } from "react-router-dom";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { ArrowLeft, Mail, ArrowRight } from "lucide-react";
import { useAuth } from "@/contexts/auth";
const ForgotPassword = () => {
const [email, setEmail] = useState("");
const [isLoading, setIsLoading] = useState(false);
const [isSent, setIsSent] = useState(false);
const { resetPassword } = useAuth();
const handleResetPassword = async (e: React.FormEvent) => {
e.preventDefault();
if (!email) {
return;
}
setIsLoading(true);
try {
const { error } = await resetPassword(email);
if (!error) {
setIsSent(true);
}
} finally {
setIsLoading(false);
}
};
return (
<div className="min-h-screen flex flex-col items-center justify-center p-6 bg-neuro-background">
<div className="w-full max-w-md">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold text-neuro-income mb-2"> </h1>
<p className="text-gray-500">
{isSent
? "이메일을 확인하여 비밀번호를 재설정하세요"
: "가입한 이메일 주소를 입력하세요"}
</p>
</div>
<div className="neuro-flat p-8 mb-6">
{!isSent ? (
<form onSubmit={handleResetPassword}>
<div className="space-y-6">
<div className="space-y-2">
<Label htmlFor="email" className="text-base"></Label>
<div className="relative">
<Mail className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-500 h-5 w-5" />
<Input
id="email"
type="email"
placeholder="your@email.com"
value={email}
onChange={e => setEmail(e.target.value)}
className="pl-10 neuro-pressed"
/>
</div>
</div>
<Button
type="submit"
disabled={isLoading || !email}
className="w-full bg-neuro-income hover:bg-neuro-income/80 text-white py-6 h-auto"
>
{isLoading ? "처리 중..." : "재설정 이메일 전송"} {!isLoading && <ArrowRight className="ml-2 h-5 w-5" />}
</Button>
</div>
</form>
) : (
<div className="text-center py-4 space-y-6">
<p className="text-gray-700">
<strong>{email}</strong> .
</p>
<p className="text-gray-500">
. .
</p>
<Button
onClick={() => setIsSent(false)}
variant="outline"
className="mt-4"
>
</Button>
</div>
)}
</div>
<div className="text-center">
<Link to="/login" className="text-neuro-income font-medium hover:underline inline-flex items-center">
<ArrowLeft className="mr-2 h-4 w-4" />
</Link>
</div>
</div>
</div>
);
};
export default ForgotPassword;