Add loader for opportunity applications

cgen-167be79652424f1f9ee00e3c22b7c2e6
This commit is contained in:
Builder.io 2025-10-14 04:21:37 +00:00
parent 3b7ed56d19
commit 366f8d014f

View file

@ -157,6 +157,42 @@ export default function Admin() {
loadProjectApplications().catch(() => undefined);
}, [loadProjectApplications]);
const loadOpportunityApplications = useCallback(async () => {
const email = user?.email?.toLowerCase();
if (!email) return;
setOpportunityApplicationsLoading(true);
try {
const response = await fetch(
`/api/opportunities/applications?email=${encodeURIComponent(email)}`,
);
if (response.ok) {
const data = await response.json();
setOpportunityApplications(Array.isArray(data) ? data : []);
} else {
const message = await response.text().catch(() => "");
if (response.status === 403) {
aethexToast.error({
title: "Access denied",
description:
"You must be signed in as the owner to view opportunity applications.",
});
} else {
console.warn("Opportunity applications request failed:", message);
}
setOpportunityApplications([]);
}
} catch (error) {
console.warn("Failed to load opportunity applications:", error);
setOpportunityApplications([]);
} finally {
setOpportunityApplicationsLoading(false);
}
}, [user?.email]);
useEffect(() => {
loadOpportunityApplications().catch(() => undefined);
}, [loadOpportunityApplications]);
useEffect(() => {
if (!loading) {
if (!user) {