|
1 | | -"use client" |
| 1 | +"use client"; |
2 | 2 |
|
3 | | -import { useState } from "react" |
4 | | -import { motion } from "framer-motion" |
5 | | -import Image from "next/image" |
6 | | -import { useRouter } from "next/navigation" |
| 3 | +import { useState } from "react"; |
| 4 | +import { motion } from "framer-motion"; |
| 5 | +import Image from "next/image"; |
| 6 | +import { useRouter } from "next/navigation"; |
7 | 7 |
|
8 | 8 | export default function ForgotPassword() { |
9 | | - const [email, setEmail] = useState("") |
10 | | - const [error, setError] = useState("") |
11 | | - const [success, setSuccess] = useState("") |
12 | | - const [isLoading, setIsLoading] = useState(false) |
13 | | - const router = useRouter() |
| 9 | + const [email, setEmail] = useState(""); |
| 10 | + const [error, setError] = useState(""); |
| 11 | + const [success, setSuccess] = useState(""); |
| 12 | + const [isLoading, setIsLoading] = useState(false); |
| 13 | + const router = useRouter(); |
14 | 14 |
|
15 | | - const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { |
16 | | - e.preventDefault() |
17 | | - setError("") |
18 | | - setSuccess("") |
19 | | - setIsLoading(true) |
| 15 | + const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { |
| 16 | + e.preventDefault(); |
| 17 | + setError(""); |
| 18 | + setSuccess(""); |
| 19 | + setIsLoading(true); |
20 | 20 |
|
21 | | - try { |
22 | | - const response = await fetch("/api/auth/forgot-password", { |
23 | | - method: "POST", |
24 | | - headers: { "Content-Type": "application/json" }, |
25 | | - body: JSON.stringify({ email }), |
26 | | - }) |
| 21 | + try { |
| 22 | + const response = await fetch("/api/auth/forgot-password", { |
| 23 | + method: "POST", |
| 24 | + headers: { "Content-Type": "application/json" }, |
| 25 | + body: JSON.stringify({ email }), |
| 26 | + }); |
27 | 27 |
|
28 | | - if (response.ok) { |
29 | | - setSuccess("Password reset link sent to your email.") |
30 | | - } else { |
31 | | - const data = await response.json() |
32 | | - setError(data.message || "Failed to send reset link.") |
33 | | - } |
34 | | - } catch (error) { |
35 | | - setError(`An error occurred. Please try again: ${error instanceof Error ? error.message : String(error)}`) |
36 | | - } finally { |
37 | | - setIsLoading(false) |
38 | | - } |
39 | | - } |
| 28 | + if (response.ok) { |
| 29 | + setSuccess("Password reset link sent to your email."); |
| 30 | + } else { |
| 31 | + const data = await response.json(); |
| 32 | + setError(data.message || "Failed to send reset link."); |
| 33 | + } |
| 34 | + } catch (error) { |
| 35 | + setError( |
| 36 | + `An error occurred. Please try again: ${error instanceof Error ? error.message : String(error)}`, |
| 37 | + ); |
| 38 | + } finally { |
| 39 | + setIsLoading(false); |
| 40 | + } |
| 41 | + }; |
40 | 42 |
|
41 | | - return ( |
42 | | - <div className="min-h-screen flex items-center justify-center bg-[#dffce8] py-12 px-4 sm:px-6 lg:px-8"> |
43 | | - <div className="max-w-md w-full space-y-6 bg-white p-8 rounded-lg shadow-lg"> |
44 | | - <div className="flex flex-col items-center"> |
45 | | - <Image src="/logo.svg" alt="Boundless" width={180} height={180} className="mb-4" /> |
46 | | - <h2 className="mt-2 text-center text-3xl font-extrabold text-[#194247]">Forgot Password</h2> |
47 | | - <p className="mt-2 text-center text-sm text-gray-600">Enter your email to receive a password reset link.</p> |
48 | | - </div> |
| 43 | + return ( |
| 44 | + <div className="min-h-screen flex items-center justify-center bg-[#dffce8] py-12 px-4 sm:px-6 lg:px-8"> |
| 45 | + <div className="max-w-md w-full space-y-6 bg-white p-8 rounded-lg shadow-lg"> |
| 46 | + <div className="flex flex-col items-center"> |
| 47 | + <Image |
| 48 | + src="/logo.svg" |
| 49 | + alt="Boundless" |
| 50 | + width={180} |
| 51 | + height={180} |
| 52 | + className="mb-4" |
| 53 | + /> |
| 54 | + <h2 className="mt-2 text-center text-3xl font-extrabold text-[#194247]"> |
| 55 | + Forgot Password |
| 56 | + </h2> |
| 57 | + <p className="mt-2 text-center text-sm text-gray-600"> |
| 58 | + Enter your email to receive a password reset link. |
| 59 | + </p> |
| 60 | + </div> |
49 | 61 |
|
50 | | - <form onSubmit={handleSubmit} className="mt-8 space-y-6"> |
51 | | - <div> |
52 | | - <label htmlFor="email" className="block text-sm font-medium text-gray-700">Email address</label> |
53 | | - <input |
54 | | - id="email" |
55 | | - name="email" |
56 | | - type="email" |
57 | | - autoComplete="email" |
58 | | - required |
59 | | - value={email} |
60 | | - onChange={(e) => setEmail(e.target.value)} |
61 | | - className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-[#194247] focus:border-[#194247]" |
62 | | - /> |
63 | | - </div> |
| 62 | + <form onSubmit={handleSubmit} className="mt-8 space-y-6"> |
| 63 | + <div> |
| 64 | + <label |
| 65 | + htmlFor="email" |
| 66 | + className="block text-sm font-medium text-gray-700" |
| 67 | + > |
| 68 | + Email address |
| 69 | + </label> |
| 70 | + <input |
| 71 | + id="email" |
| 72 | + name="email" |
| 73 | + type="email" |
| 74 | + autoComplete="email" |
| 75 | + required |
| 76 | + value={email} |
| 77 | + onChange={(e) => setEmail(e.target.value)} |
| 78 | + className="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-[#194247] focus:border-[#194247]" |
| 79 | + /> |
| 80 | + </div> |
64 | 81 |
|
65 | | - {error && <p className="text-red-500 text-sm text-center">{error}</p>} |
66 | | - {success && <p className="text-green-500 text-sm text-center">{success}</p>} |
| 82 | + {error && <p className="text-red-500 text-sm text-center">{error}</p>} |
| 83 | + {success && ( |
| 84 | + <p className="text-green-500 text-sm text-center">{success}</p> |
| 85 | + )} |
67 | 86 |
|
68 | | - <motion.button |
69 | | - whileTap={{ scale: 0.95 }} |
70 | | - type="submit" |
71 | | - className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-[#194247] hover:bg-[#153a3f] focus:outline-none" |
72 | | - disabled={isLoading} |
73 | | - > |
74 | | - {isLoading ? "Sending..." : "Send Reset Link"} |
75 | | - </motion.button> |
76 | | - </form> |
| 87 | + <motion.button |
| 88 | + whileTap={{ scale: 0.95 }} |
| 89 | + type="submit" |
| 90 | + className="w-full flex justify-center py-2 px-4 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-[#194247] hover:bg-[#153a3f] focus:outline-none" |
| 91 | + disabled={isLoading} |
| 92 | + > |
| 93 | + {isLoading ? "Sending..." : "Send Reset Link"} |
| 94 | + </motion.button> |
| 95 | + </form> |
77 | 96 |
|
78 | | - <div className="text-center"> |
79 | | - <button |
80 | | - onClick={() => router.push("/auth/signin")} |
81 | | - className="text-sm text-[#194247] hover:underline" |
82 | | - > |
83 | | - Back to Sign In |
84 | | - </button> |
85 | | - </div> |
86 | | - </div> |
87 | | - </div> |
88 | | - ) |
| 97 | + <div className="text-center"> |
| 98 | + <button |
| 99 | + type="button" |
| 100 | + onClick={() => router.push("/auth/signin")} |
| 101 | + className="text-sm text-[#194247] hover:underline" |
| 102 | + > |
| 103 | + Back to Sign In |
| 104 | + </button> |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + ); |
89 | 109 | } |
0 commit comments