|
1 | 1 | import { Link } from "react-router-dom";
|
2 | 2 | import useLoginForm from "./useLoginForm";
|
3 | 3 | import FieldError from "@/components/core-ui/FieldError";
|
| 4 | +import Alert from "@/components/core-ui/Alert"; |
4 | 5 |
|
5 | 6 | const LoginForm = () => {
|
6 |
| - const { form } = useLoginForm(); |
| 7 | + const { form, loginError } = useLoginForm(); |
7 | 8 |
|
8 | 9 | return (
|
9 |
| - <form className="space-y-6" onSubmit={form.handleSubmit} noValidate> |
10 |
| - <div> |
11 |
| - <label |
12 |
| - htmlFor="email" |
13 |
| - className="block text-sm font-medium leading-6 text-gray-900" |
14 |
| - > |
15 |
| - Email address |
16 |
| - <span className="text-red-500">*</span> |
17 |
| - </label> |
18 |
| - <div className="mt-2"> |
19 |
| - <input |
20 |
| - id="email" |
21 |
| - name="email" |
22 |
| - type="email" |
23 |
| - autoComplete="email" |
24 |
| - required |
25 |
| - className="block w-full rounded-md border-0 py-1.5 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" |
26 |
| - readOnly={form.isSubmitting} |
27 |
| - value={form.values.email} |
28 |
| - onChange={form.handleChange} |
29 |
| - /> |
30 |
| - {form.errors.email && <FieldError error={form.errors.email} />} |
| 10 | + <> |
| 11 | + {loginError && ( |
| 12 | + <div className="mb-4"> |
| 13 | + <Alert type="error" message={loginError} /> |
31 | 14 | </div>
|
32 |
| - </div> |
33 |
| - |
34 |
| - <div> |
35 |
| - <label |
36 |
| - htmlFor="password" |
37 |
| - className="block text-sm font-medium leading-6 text-gray-900" |
38 |
| - > |
39 |
| - Password |
40 |
| - <span className="text-red-500">*</span> |
41 |
| - </label> |
42 |
| - <div className="mt-2"> |
43 |
| - <input |
44 |
| - id="password" |
45 |
| - name="password" |
46 |
| - type="password" |
47 |
| - autoComplete="current-password" |
48 |
| - required |
49 |
| - className="block w-full rounded-md border-0 py-1.5 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" |
50 |
| - readOnly={form.isSubmitting} |
51 |
| - value={form.values.password} |
52 |
| - onChange={form.handleChange} |
53 |
| - /> |
54 |
| - {form.errors.password && <FieldError error={form.errors.password} />} |
| 15 | + )} |
| 16 | + <form className="space-y-6" onSubmit={form.handleSubmit} noValidate> |
| 17 | + <div> |
| 18 | + <label |
| 19 | + htmlFor="email" |
| 20 | + className="block text-sm font-medium leading-6 text-gray-900" |
| 21 | + > |
| 22 | + Email address |
| 23 | + <span className="text-red-500">*</span> |
| 24 | + </label> |
| 25 | + <div className="mt-2"> |
| 26 | + <input |
| 27 | + id="email" |
| 28 | + name="email" |
| 29 | + type="email" |
| 30 | + autoComplete="email" |
| 31 | + required |
| 32 | + className="block w-full rounded-md border-0 py-1.5 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" |
| 33 | + readOnly={form.isSubmitting} |
| 34 | + value={form.values.email} |
| 35 | + onChange={form.handleChange} |
| 36 | + /> |
| 37 | + {form.errors.email && <FieldError error={form.errors.email} />} |
| 38 | + </div> |
55 | 39 | </div>
|
56 |
| - </div> |
57 | 40 |
|
58 |
| - <div className="flex items-center justify-between"> |
59 |
| - <div className="flex items-center"> |
60 |
| - <input |
61 |
| - id="remember-me" |
62 |
| - name="remember-me" |
63 |
| - type="checkbox" |
64 |
| - className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" |
65 |
| - /> |
| 41 | + <div> |
66 | 42 | <label
|
67 |
| - htmlFor="remember-me" |
68 |
| - className="ml-3 block text-sm leading-6 text-gray-700" |
| 43 | + htmlFor="password" |
| 44 | + className="block text-sm font-medium leading-6 text-gray-900" |
69 | 45 | >
|
70 |
| - Remember me |
| 46 | + Password |
| 47 | + <span className="text-red-500">*</span> |
71 | 48 | </label>
|
| 49 | + <div className="mt-2"> |
| 50 | + <input |
| 51 | + id="password" |
| 52 | + name="password" |
| 53 | + type="password" |
| 54 | + autoComplete="current-password" |
| 55 | + required |
| 56 | + className="block w-full rounded-md border-0 py-1.5 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" |
| 57 | + readOnly={form.isSubmitting} |
| 58 | + value={form.values.password} |
| 59 | + onChange={form.handleChange} |
| 60 | + /> |
| 61 | + {form.errors.password && ( |
| 62 | + <FieldError error={form.errors.password} /> |
| 63 | + )} |
| 64 | + </div> |
72 | 65 | </div>
|
73 | 66 |
|
74 |
| - <div className="text-sm leading-6"> |
75 |
| - <Link |
76 |
| - to="/forgot-password" |
77 |
| - className="font-semibold text-indigo-600 hover:text-indigo-500" |
78 |
| - > |
79 |
| - Forgot password? |
80 |
| - </Link> |
| 67 | + <div className="flex items-center justify-between"> |
| 68 | + <div className="flex items-center"> |
| 69 | + <input |
| 70 | + id="remember-me" |
| 71 | + name="remember-me" |
| 72 | + type="checkbox" |
| 73 | + className="h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-600" |
| 74 | + /> |
| 75 | + <label |
| 76 | + htmlFor="remember-me" |
| 77 | + className="ml-3 block text-sm leading-6 text-gray-700" |
| 78 | + > |
| 79 | + Remember me |
| 80 | + </label> |
| 81 | + </div> |
| 82 | + |
| 83 | + <div className="text-sm leading-6"> |
| 84 | + <Link |
| 85 | + to="/forgot-password" |
| 86 | + className="font-semibold text-indigo-600 hover:text-indigo-500" |
| 87 | + > |
| 88 | + Forgot password? |
| 89 | + </Link> |
| 90 | + </div> |
81 | 91 | </div>
|
82 |
| - </div> |
83 | 92 |
|
84 |
| - <div> |
85 |
| - <button |
86 |
| - type="submit" |
87 |
| - className="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" |
88 |
| - disabled={form.isSubmitting} |
89 |
| - > |
90 |
| - Sign in |
91 |
| - </button> |
92 |
| - </div> |
93 |
| - </form> |
| 93 | + <div> |
| 94 | + <button |
| 95 | + type="submit" |
| 96 | + className="flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" |
| 97 | + disabled={form.isSubmitting} |
| 98 | + > |
| 99 | + Sign in |
| 100 | + </button> |
| 101 | + </div> |
| 102 | + </form> |
| 103 | + </> |
94 | 104 | );
|
95 | 105 | };
|
96 | 106 |
|
|
0 commit comments