fix and update
This commit is contained in:
@@ -19,23 +19,24 @@ export default function HomePage() {
|
||||
const router = useRouter();
|
||||
const { user, token, isPinLocked } = useAuth();
|
||||
const { isReady } = useRequireAuth();
|
||||
const userId = user?.id;
|
||||
const contactLine = [user?.phone, user?.username ?? user?.email].filter(Boolean).join(' · ');
|
||||
const [documents, setDocuments] = useState<UserDocument[]>([]);
|
||||
const [activeDocumentType, setActiveDocumentType] = useState<DocumentTypeCode | null>(null);
|
||||
|
||||
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 {
|
||||
setDocuments([]);
|
||||
// Фоновая ошибка не должна очищать уже показанные документы.
|
||||
}
|
||||
}, [isPinLocked, token, user]);
|
||||
}, [isPinLocked, token, userId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isReady && user && !isPinLocked) void loadDocuments();
|
||||
}, [isPinLocked, isReady, loadDocuments, user]);
|
||||
if (isReady && userId && !isPinLocked) void loadDocuments();
|
||||
}, [isPinLocked, isReady, loadDocuments, userId]);
|
||||
|
||||
const documentsByType = useMemo(() => indexDocumentsByType(documents), [documents]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user