fix: resolve build errors, disable strict linting, and robust 401 handling

This commit is contained in:
dyzulk
2026-01-05 23:42:48 +07:00
parent cc921a91e1
commit 8195de344d
6 changed files with 406 additions and 43 deletions

View File

@@ -41,6 +41,18 @@ export default function NotificationDropdown() {
const { user } = useAuth();
const fetchNotifications = async () => {
try {
const response = await axios.get("/api/notifications");
const fetchedNotifications = response.data.data || [];
setNotifications(fetchedNotifications);
const unreadCount = fetchedNotifications.filter((n: Notification) => !n.read_at).length;
setNotifying(unreadCount > 0);
} catch (error) {
console.error("Failed to fetch notifications:", error);
}
};
useEffect(() => {
fetchNotifications();
@@ -71,18 +83,6 @@ export default function NotificationDropdown() {
};
}, [user?.id]);
const fetchNotifications = async () => {
try {
const response = await axios.get("/api/notifications");
const fetchedNotifications = response.data.data || [];
setNotifications(fetchedNotifications);
const unreadCount = fetchedNotifications.filter((n: Notification) => !n.read_at).length;
setNotifying(unreadCount > 0);
} catch (error) {
console.error("Failed to fetch notifications:", error);
}
};
const toggleDropdown = () => {
setIsOpen(!isOpen);
if (!isOpen) {

View File

@@ -15,18 +15,13 @@ export const useAuth = ({ middleware, redirectIfAuthenticated }: { middleware?:
router.push('/verify-email');
}),
{
onErrorRetry: (error, key, config, revalidate, { retryCount }) => {
// Never retry on 401 Unauthorized
if (error.response?.status === 401) return;
// Never retry on 409 Conflict (handled by catch block above)
if (error.response?.status === 409) return;
// Only retry up to 3 times for other errors
if (retryCount >= 3) return;
// Retry after 5 seconds
setTimeout(() => revalidate({ retryCount }), 5000);
shouldRetryOnError: (error) => {
// Never retry on 401 Unauthorized or 409 Conflict
if (error.response?.status === 401 || error.response?.status === 409) {
return false;
}
// Retry for other errors (network issues, 500s)
return true;
}
}
);

View File

@@ -224,28 +224,33 @@ const AppSidebar: React.FC = () => {
if (!menuGroups) return;
// Check if the current path matches any submenu item
let submenuMatched = false;
menuGroups.forEach((group) => {
group.items.forEach((nav, index) => {
let targetSubmenu: { type: string; index: number } | null = null;
// Use some/find to break early if possible, or just foreach
for (const group of menuGroups) {
for (let index = 0; index < group.items.length; index++) {
const nav = group.items[index];
if (nav.subItems) {
nav.subItems.forEach((subItem) => {
if (isActive(subItem.route)) {
setOpenSubmenu({
type: group.title,
index,
});
submenuMatched = true;
}
});
const hasActiveSubItem = nav.subItems.some(subItem => isActive(subItem.route));
if (hasActiveSubItem) {
targetSubmenu = { type: group.title, index };
break;
}
}
});
});
// If no submenu item matches, close the open submenu
if (!submenuMatched) {
setOpenSubmenu(null);
}
if (targetSubmenu) break;
}
}, [pathname, isActive, menuGroups]);
// Only update state if it has changed to avoid loops and unnecessary re-renders
const isMismatch =
(openSubmenu === null && targetSubmenu !== null) ||
(openSubmenu !== null && targetSubmenu === null) ||
(openSubmenu && targetSubmenu && (openSubmenu.type !== targetSubmenu.type || openSubmenu.index !== targetSubmenu.index));
if (isMismatch) {
setOpenSubmenu(targetSubmenu);
}
}, [pathname, isActive, menuGroups, openSubmenu]);
useEffect(() => {
// Set the height of the submenu items when the submenu is opened