source: src/app/page.tsx@ 997d094

Last change on this file since 997d094 was 90f7842, checked in by Stefan-Saveski <stefansaveski19@…>, 9 months ago

fix: Update API endpoints to use production URL for user data retrieval and authentication

  • Property mode set to 100644
File size: 9.2 KB
Line 
1"use client"
2
3import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
4import {
5 faUser,
6 faLock,
7 faEye,
8 faEyeSlash,
9 faSignInAlt,
10 faGraduationCap
11} from '@fortawesome/free-solid-svg-icons';
12import { useState } from 'react';
13import { login } from '@/lib/auth';
14
15export default function LoginPage() {
16 const [showPassword, setShowPassword] = useState(false);
17 const [isSubmitting, setIsSubmitting] = useState(false);
18 const [errorMessage, setErrorMessage] = useState<string | null>(null);
19 const [formData, setFormData] = useState({
20 email: '',
21 password: ''
22 });
23
24 const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
25 const { name, value } = e.target;
26 setFormData(prev => ({
27 ...prev,
28 [name]: value
29 }));
30 };
31
32 const handleSubmit = async (e: React.FormEvent) => {
33 e.preventDefault();
34 setErrorMessage(null);
35 setIsSubmitting(true);
36 try {
37 await login({ email: formData.email, password: formData.password });
38 window.location.href = '/students/profile';
39 } catch (err) {
40 setErrorMessage(err instanceof Error ? err.message : 'Login failed.');
41 } finally {
42 setIsSubmitting(false);
43 }
44 };
45
46 return (
47 <div className="container mx-auto px-4">
48 <div className="min-h-screen ">
49 {/* Login Form */}
50 <div className="flex items-center justify-center min-h-[calc(100vh-160px)] p-4">
51 <div className="w-full max-w-5xl">
52 <div className="grid grid-cols-1 gap-6 lg:grid-cols-[24rem_28rem_24rem] lg:items-start lg:justify-center">
53 {/* Sticky Notes */}
54 <div className="w-full flex flex-col gap-4">
55 <div className="bg-yellow-100 border border-yellow-200 rounded-xl shadow-sm p-5">
56 <div className="text-sm font-bold text-gray-900 mb-2">Login for Student</div>
57 <div className="text-xs text-gray-800 whitespace-pre-wrap font-mono">
58 {`"email":"boris@example.com",
59"password":"your-password-here",`}
60 </div>
61 <div className="mt-3 text-xs text-gray-700">
62 may take up to 30 seconds afte long inactivity
63 </div>
64 </div>
65
66 <div className="bg-yellow-100 border border-yellow-200 rounded-xl shadow-sm p-5">
67 <div className="text-sm font-bold text-gray-900 mb-2">Login for Professor</div>
68 <div className="text-xs text-gray-800 whitespace-pre-wrap font-mono">
69 {`"email":"andonov@gmail.com",
70"password":"123lol456",`}
71 </div>
72 </div>
73 </div>
74
75 {/* Login Card Column */}
76 <div className="w-full max-w-md lg:max-w-none lg:w-[28rem] mx-auto">
77 {/* Login Card */}
78 <div className="bg-white rounded-2xl shadow-xl border border-gray-100 overflow-hidden">
79 {/* Header */}
80 <div className="bg-primary text-white px-8 py-6 text-center">
81 <div className="mb-4">
82 <div className="inline-flex items-center justify-center w-16 h-16 bg-white bg-opacity-20 rounded-full">
83 <FontAwesomeIcon icon={faUser} className="text-2xl text-primary" />
84 </div>
85 </div>
86 <h1 className="text-2xl font-bold mb-2">Добредојде</h1>
87 <p className="text-blue-100 text-sm">
88 Најавете се во вашиот IKnow акаунт
89 </p>
90 </div>
91
92 {/* Form */}
93 <div className="p-8">
94 <form onSubmit={handleSubmit} className="space-y-6">
95 {/* Email Field */}
96 <div>
97 <label htmlFor="email" className="block text-sm font-medium text-gray-700 mb-2">
98 Внесете е-пошта
99 </label>
100 <div className="relative">
101 <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
102 <FontAwesomeIcon icon={faUser} className="h-4 w-4 text-gray-400" />
103 </div>
104 <input
105 id="email"
106 name="email"
107 type="email"
108 required
109 value={formData.email}
110 onChange={handleInputChange}
111 className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary transition-colors"
112 placeholder="Внесете е-пошта"
113 />
114 </div>
115 </div>
116
117 {/* Password Field */}
118 <div>
119 <label htmlFor="password" className="block text-sm font-medium text-gray-700 mb-2">
120 Лозинка
121 </label>
122 <div className="relative">
123 <div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
124 <FontAwesomeIcon icon={faLock} className="h-4 w-4 text-gray-400" />
125 </div>
126 <input
127 id="password"
128 name="password"
129 type={showPassword ? "text" : "password"}
130 required
131 value={formData.password}
132 onChange={handleInputChange}
133 className="w-full pl-10 pr-12 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary focus:border-primary transition-colors"
134 placeholder="Внесете лозинка"
135 />
136 <button
137 type="button"
138 onClick={() => setShowPassword(!showPassword)}
139 className="absolute inset-y-0 right-0 pr-3 flex items-center text-gray-400 hover:text-gray-600 transition-colors"
140 >
141 <FontAwesomeIcon
142 icon={showPassword ? faEyeSlash : faEye}
143 className="h-4 w-4"
144 />
145 </button>
146 </div>
147 </div>
148
149 {/* Remember Me & Forgot Password */}
150 <div className="flex items-center justify-between">
151 <div className="flex items-center">
152 <input
153 id="remember"
154 name="remember"
155 type="checkbox"
156 className="h-4 w-4 text-primary focus:ring-primary border-gray-300 rounded"
157 />
158 <label htmlFor="remember" className="ml-2 block text-sm text-gray-700">
159 Запомни ме
160 </label>
161 </div>
162 <button
163 type="button"
164 className="text-sm text-primary hover:text-blue-700 font-medium transition-colors"
165 >
166 Заборавена лозинка?
167 </button>
168 </div>
169
170 {errorMessage && (
171 <div className="rounded-lg border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700">
172 {errorMessage}
173 </div>
174 )}
175
176 {/* Submit Button */}
177 <button
178 type="submit"
179 disabled={isSubmitting}
180 className="w-full bg-primary hover:bg-blue-700 disabled:opacity-60 disabled:hover:bg-primary text-white font-medium py-3 px-4 rounded-lg transition-colors duration-200 flex items-center justify-center gap-2 shadow-lg hover:shadow-xl"
181 >
182 <FontAwesomeIcon icon={faSignInAlt} className="h-4 w-4" />
183 {isSubmitting ? 'Најави се...' : 'Најави се'}
184 </button>
185 </form>
186 </div>
187
188 {/* Footer */}
189 <div className="bg-gray-50 px-8 py-4 border-t border-gray-100">
190 <p className="text-center text-sm text-gray-600">
191 Немате акаунт?{' '}
192 <button className="text-primary hover:text-blue-700 font-medium transition-colors">
193 Контактирајте ја администрацијата
194 </button>
195 </p>
196 </div>
197 </div>
198
199 {/* Additional Info */}
200 <div className="mt-6 text-center">
201 <div className="inline-flex items-center gap-2 px-4 py-2 bg-white bg-opacity-80 rounded-lg shadow-sm">
202 <FontAwesomeIcon icon={faGraduationCap} className="text-primary" />
203 <span className="text-sm text-gray-600">
204 Студентски информационен систем
205 </span>
206 </div>
207 </div>
208 </div>
209
210 {/* Right spacer column (keeps login centered) */}
211 <div className="hidden lg:block" />
212 </div>
213 </div>
214 </div>
215 </div>
216 </div>
217 );
218}
Note: See TracBrowser for help on using the repository browser.