import React, { useState, useEffect } from 'react'; import { pb } from '../lib/pocketbase'; import { useAtom } from 'jotai'; import { updateAuthAtom } from '../atoms/authAtom'; const Profile: React.FC = () => { const [email, setEmail] = useState(''); const [username, setUsername] = useState(''); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [, updateAuth] = useAtom(updateAuthAtom); useEffect(() => { if (pb.authStore.model) { setEmail(pb.authStore.model.email); } }, []); const handleUpdateProfile = async (e: React.FormEvent) => { e.preventDefault(); if (newPassword && newPassword !== confirmPassword) { alert("Hasła nie są takie same"); return; } try { const data: Record = { email, username }; if (newPassword) { data.password = newPassword; data.passwordConfirm = confirmPassword; } await pb.collection('users').update(pb.authStore.model!.id, data); alert('Profile updated successfully'); updateAuth(); } catch (error) { console.error('Profile update error:', error); alert('Failed to update profile'); } }; const handleDeleteAccount = async () => { if (window.confirm('Jesteś pewien, że chcesz usunąć konto? Tej akcji nie da się cofnąć.')) { try { await pb.collection('users').delete(pb.authStore.model!.id); pb.authStore.clear(); updateAuth(); alert('Konto poprawnie usunięte'); } catch (error) { console.error('Błąd z usuwaniem konta:', error); alert('Nie udało się usunąć konta.'); } } }; return (

Profile

setEmail(e.target.value)} required className="w-full px-3 py-2 border rounded" />
setUsername(e.target.value)} required className="w-full px-3 py-2 border rounded" />
setNewPassword(e.target.value)} className="w-full px-3 py-2 border rounded" />
setConfirmPassword(e.target.value)} className="w-full px-3 py-2 border rounded" />
); }; export default Profile; // Formularz zmieniania profilu użytkownika