fix and update

This commit is contained in:
lendry
2026-06-30 23:43:49 +03:00
parent 4b2ade9354
commit deb213bd77
6 changed files with 60 additions and 29 deletions

View File

@@ -76,9 +76,10 @@ function Row({
export default function DataPage() {
const router = useRouter();
const { user, token, refreshProfile } = useAuth();
const { user, token, applyUserPatch } = useAuth();
const { isReady, isPinLocked } = useRequireAuth();
const { showToast } = useToast();
const userId = user?.id;
const [displayName, setDisplayName] = useState('');
const [email, setEmail] = useState('');
const [backupEmail, setBackupEmail] = useState('');
@@ -98,15 +99,15 @@ export default function DataPage() {
const [cancellingDeletion, setCancellingDeletion] = useState(false);
const loadDocuments = useCallback(async () => {
if (!user || !token || isPinLocked) return;
if (!userId || !token || isPinLocked) return;
try {
const response = await apiFetch<{ documents?: UserDocument[] }>(`/documents/users/${user.id}`, {}, token);
const response = await apiFetch<{ documents?: UserDocument[] }>(`/documents/users/${userId}`, {}, token);
setDocuments(response.documents ?? []);
} catch (error) {
const message = getApiErrorMessage(error, 'Не удалось загрузить документы');
if (message) showToast(message);
}
}, [isPinLocked, showToast, token, user]);
}, [isPinLocked, showToast, token, userId]);
useEffect(() => {
if (!user) return;
@@ -124,31 +125,31 @@ export default function DataPage() {
}, [user]);
useEffect(() => {
if (!isReady || !user || !token || isPinLocked) return;
void apiFetch<UserProfileResponse>(`/profile/users/${user.id}`, {}, token)
if (!isReady || !userId || !token || isPinLocked) return;
void apiFetch<UserProfileResponse>(`/profile/users/${userId}`, {}, token)
.then((profile) => {
if (profile.birthDate) setBirthDate(profile.birthDate);
})
.catch(() => undefined);
}, [isPinLocked, isReady, token, user]);
}, [isPinLocked, isReady, token, userId]);
useEffect(() => {
if (isReady && user && !isPinLocked) void loadDocuments();
}, [isPinLocked, isReady, loadDocuments, user]);
if (isReady && userId && !isPinLocked) void loadDocuments();
}, [isPinLocked, isReady, loadDocuments, userId]);
const loadDeletionStatus = useCallback(async () => {
if (!user || !token || isPinLocked) return;
if (!userId || !token || isPinLocked) return;
try {
const status = await fetchAccountDeletionStatus(user.id, token);
const status = await fetchAccountDeletionStatus(userId, token);
setDeletionStatus(status);
} catch {
setDeletionStatus(null);
}
}, [isPinLocked, token, user]);
}, [isPinLocked, token, userId]);
useEffect(() => {
if (isReady && user && !isPinLocked) void loadDeletionStatus();
}, [isPinLocked, isReady, loadDeletionStatus, user]);
if (isReady && userId && !isPinLocked) void loadDeletionStatus();
}, [isPinLocked, isReady, loadDeletionStatus, userId]);
const documentsByType = useMemo(() => indexDocumentsByType(documents), [documents]);
@@ -186,7 +187,13 @@ export default function DataPage() {
}, token);
}
await refreshProfile();
applyUserPatch({
displayName: trimmedName || user.displayName,
email: contacts.email ?? user.email,
phone: contacts.phone ?? user.phone,
backupEmail: contacts.backupEmail ?? user.backupEmail,
backupPhone: contacts.backupPhone ?? user.backupPhone
});
showToast('Профиль обновлён');
} catch (error) {
const message = getApiErrorMessage(error, 'Не удалось обновить профиль');
@@ -244,7 +251,9 @@ export default function DataPage() {
verificationIcon={user.verificationIcon}
className="h-14 w-14"
badgeSize="sm"
onUpdated={refreshProfile}
onUpdated={async () => {
applyUserPatch({ hasAvatar: true });
}}
/>
) : (
<AvatarDisplay userId="" displayName="" hasAvatar={false} token={null} className="h-14 w-14" />