All files / frontend/src/pages Profile.tsx

65.53% Statements 213/325
18.18% Branches 2/11
11.76% Functions 2/17
65.53% Lines 213/325

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 3711x 1x   1x 19x 19x 19x     19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x 19x 19x 19x 19x 19x     19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x             19x               19x 19x   19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x   19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x 19x 19x 19x   19x 19x 19x 19x 19x 19x 19x         19x   19x 19x 19x 19x 19x         19x   19x 19x 19x 19x 19x         19x   19x 19x 19x 19x 19x     19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x   19x           19x 19x   19x   19x 19x 19x       19x                                                                                                                                               19x                                                             19x 19x 19x 19x 19x   19x   1x  
import React, { useState } from 'react';
import { useAuthStore } from '../store';
 
const Profile: React.FC = () => {
    const { user } = useAuthStore();
    const [activeTab, setActiveTab] = useState<'profile' | 'security' | 'activity'>('profile');
    const [isSaving, setIsSaving] = useState(false);
 
    // Profile state (TODO: Connect to backend user API)
    const [profile, setProfile] = useState({
        firstName: 'Admin',
        lastName: 'User',
        email: user?.email || 'admin@heimdall.local',
        phone: '+39 123 456 7890',
        organization: 'Heimdall SDR',
        role: 'System Administrator',
        location: 'Turin, Italy',
        bio: 'RF localization specialist',
    });
 
    const [security, setSecurity] = useState({
        currentPassword: '',
        newPassword: '',
        confirmPassword: '',
        twoFactorEnabled: false,
    });
 
    // Mock activity data
    const recentActivity = [
        {
            id: 1,
            action: 'Logged in',
            timestamp: new Date().toISOString(),
            ip: '192.168.1.100',
            device: 'Chrome on Windows',
        },
        {
            id: 2,
            action: 'Updated settings',
            timestamp: new Date(Date.now() - 3600000).toISOString(),
            ip: '192.168.1.100',
            device: 'Chrome on Windows',
        },
        {
            id: 3,
            action: 'Created recording session',
            timestamp: new Date(Date.now() - 7200000).toISOString(),
            ip: '192.168.1.100',
            device: 'Chrome on Windows',
        },
    ];
 
    const handleSaveProfile = async () => {
        setIsSaving(true);
        // TODO: Save to backend API
        await new Promise(resolve => setTimeout(resolve, 1000));
        setIsSaving(false);
    };
 
    const handleChangePassword = async () => {
        setIsSaving(true);
        // TODO: Change password via API
        await new Promise(resolve => setTimeout(resolve, 1000));
        setSecurity({ ...security, currentPassword: '', newPassword: '', confirmPassword: '' });
        setIsSaving(false);
    };
 
    return (
        <>
            {/* Breadcrumb */}
            <div className="page-header">
                <div className="page-block">
                    <div className="row align-items-center">
                        <div className="col-md-12">
                            <ul className="breadcrumb">
                                <li className="breadcrumb-item"><a href="/dashboard">Home</a></li>
                                <li className="breadcrumb-item"><a href="#">Settings</a></li>
                                <li className="breadcrumb-item" aria-current="page">Profile</li>
                            </ul>
                        </div>
                        <div className="col-md-12">
                            <div className="page-header-title">
                                <h2 className="mb-0">User Profile</h2>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
 
            <div className="row">
                {/* Profile Sidebar */}
                <div className="col-lg-3">
                    <div className="card">
                        <div className="card-body text-center">
                            <div className="avtar avtar-xl bg-primary mx-auto mb-3">
                                <i className="ph ph-user f-40"></i>
                            </div>
                            <h5 className="mb-1">{profile.firstName} {profile.lastName}</h5>
                            <p className="text-muted f-12 mb-3">{profile.role}</p>
                            <div className="d-grid">
                                <button className="btn btn-outline-primary btn-sm mb-2">
                                    <i className="ph ph-image me-1"></i>
                                    Change Avatar
                                </button>
                            </div>
                        </div>
                    </div>
 
                    <div className="card">
                        <div className="card-body">
                            <div className="list-group list-group-flush">
                                <a
                                    href="#!"
                                    className={`list-group-item list-group-item-action ${activeTab === 'profile' ? 'active' : ''}`}
                                    onClick={(e) => {
                                        e.preventDefault();
                                        setActiveTab('profile');
                                    }}
                                >
                                    <i className="ph ph-user me-2"></i>
                                    Profile Info
                                </a>
                                <a
                                    href="#!"
                                    className={`list-group-item list-group-item-action ${activeTab === 'security' ? 'active' : ''}`}
                                    onClick={(e) => {
                                        e.preventDefault();
                                        setActiveTab('security');
                                    }}
                                >
                                    <i className="ph ph-shield me-2"></i>
                                    Security
                                </a>
                                <a
                                    href="#!"
                                    className={`list-group-item list-group-item-action ${activeTab === 'activity' ? 'active' : ''}`}
                                    onClick={(e) => {
                                        e.preventDefault();
                                        setActiveTab('activity');
                                    }}
                                >
                                    <i className="ph ph-activity me-2"></i>
                                    Activity Log
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
 
                {/* Profile Content */}
                <div className="col-lg-9">
                    <div className="card">
                        <div className="card-header">
                            <h5 className="mb-0">
                                {activeTab === 'profile' && 'Profile Information'}
                                {activeTab === 'security' && 'Security Settings'}
                                {activeTab === 'activity' && 'Recent Activity'}
                            </h5>
                        </div>
                        <div className="card-body">
                            {/* Profile Tab */}
                            {activeTab === 'profile' && (
                                <div className="row g-3">
                                    <div className="col-md-6">
                                        <label className="form-label">First Name</label>
                                        <input
                                            type="text"
                                            className="form-control"
                                            value={profile.firstName}
                                            onChange={(e) => setProfile({ ...profile, firstName: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Last Name</label>
                                        <input
                                            type="text"
                                            className="form-control"
                                            value={profile.lastName}
                                            onChange={(e) => setProfile({ ...profile, lastName: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Email</label>
                                        <input
                                            type="email"
                                            className="form-control"
                                            value={profile.email}
                                            onChange={(e) => setProfile({ ...profile, email: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Phone</label>
                                        <input
                                            type="tel"
                                            className="form-control"
                                            value={profile.phone}
                                            onChange={(e) => setProfile({ ...profile, phone: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Organization</label>
                                        <input
                                            type="text"
                                            className="form-control"
                                            value={profile.organization}
                                            onChange={(e) => setProfile({ ...profile, organization: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Role</label>
                                        <input
                                            type="text"
                                            className="form-control"
                                            value={profile.role}
                                            disabled
                                        />
                                    </div>
                                    <div className="col-12">
                                        <label className="form-label">Location</label>
                                        <input
                                            type="text"
                                            className="form-control"
                                            value={profile.location}
                                            onChange={(e) => setProfile({ ...profile, location: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-12">
                                        <label className="form-label">Bio</label>
                                        <textarea
                                            className="form-control"
                                            rows={3}
                                            value={profile.bio}
                                            onChange={(e) => setProfile({ ...profile, bio: e.target.value })}
                                        ></textarea>
                                    </div>
                                    <div className="col-12">
                                        <button
                                            className="btn btn-primary"
                                            onClick={handleSaveProfile}
                                            disabled={isSaving}
                                        >
                                            {isSaving ? (
                                                <>
                                                    <span className="spinner-border spinner-border-sm me-2"></span>
                                                    Saving...
                                                </>
                                            ) : (
                                                <>
                                                    <i className="ph ph-check me-2"></i>
                                                    Save Changes
                                                </>
                                            )}
                                        </button>
                                    </div>
                                </div>
                            )}
 
                            {/* Security Tab */}
                            {activeTab === 'security' && (
                                <div className="row g-3">
                                    <div className="col-12">
                                        <h6>Change Password</h6>
                                    </div>
                                    <div className="col-12">
                                        <label className="form-label">Current Password</label>
                                        <input
                                            type="password"
                                            className="form-control"
                                            value={security.currentPassword}
                                            onChange={(e) => setSecurity({ ...security, currentPassword: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">New Password</label>
                                        <input
                                            type="password"
                                            className="form-control"
                                            value={security.newPassword}
                                            onChange={(e) => setSecurity({ ...security, newPassword: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-md-6">
                                        <label className="form-label">Confirm New Password</label>
                                        <input
                                            type="password"
                                            className="form-control"
                                            value={security.confirmPassword}
                                            onChange={(e) => setSecurity({ ...security, confirmPassword: e.target.value })}
                                        />
                                    </div>
                                    <div className="col-12">
                                        <button
                                            className="btn btn-primary"
                                            onClick={handleChangePassword}
                                            disabled={isSaving}
                                        >
                                            {isSaving ? (
                                                <>
                                                    <span className="spinner-border spinner-border-sm me-2"></span>
                                                    Updating...
                                                </>
                                            ) : (
                                                <>
                                                    <i className="ph ph-lock-key me-2"></i>
                                                    Update Password
                                                </>
                                            )}
                                        </button>
                                    </div>
                                    <div className="col-12">
                                        <hr />
                                        <h6>Two-Factor Authentication</h6>
                                        <div className="form-check form-switch mt-3">
                                            <input
                                                className="form-check-input"
                                                type="checkbox"
                                                id="twoFactor"
                                                checked={security.twoFactorEnabled}
                                                onChange={(e) => setSecurity({ ...security, twoFactorEnabled: e.target.checked })}
                                            />
                                            <label className="form-check-label" htmlFor="twoFactor">
                                                Enable Two-Factor Authentication
                                            </label>
                                        </div>
                                        <small className="text-muted">Add an extra layer of security to your account</small>
                                    </div>
                                </div>
                            )}
 
                            {/* Activity Tab */}
                            {activeTab === 'activity' && (
                                <div className="table-responsive">
                                    <table className="table table-hover mb-0">
                                        <thead>
                                            <tr>
                                                <th>Action</th>
                                                <th>Timestamp</th>
                                                <th>IP Address</th>
                                                <th>Device</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {recentActivity.map((activity) => (
                                                <tr key={activity.id}>
                                                    <td>
                                                        <div className="d-flex align-items-center">
                                                            <div className="avtar avtar-xs bg-light-primary">
                                                                <i className="ph ph-activity"></i>
                                                            </div>
                                                            <span className="ms-2">{activity.action}</span>
                                                        </div>
                                                    </td>
                                                    <td>{new Date(activity.timestamp).toLocaleString()}</td>
                                                    <td>{activity.ip}</td>
                                                    <td>{activity.device}</td>
                                                </tr>
                                            ))}
                                        </tbody>
                                    </table>
                                </div>
                            )}
                        </div>
                    </div>
                </div>
            </div>
        </>
    );
};
 
export default Profile;