chore(deps): Update dependencies and refactor API routes for improved error handling

- Updated various dependencies in package.json and pnpm-lock.yaml, including '@clerk/nextjs' to version 6.7.1 and several others for better performance and security.
- Refactored API routes to use Promise.resolve for context parameters, enhancing reliability in asynchronous contexts.
- Improved error handling in the dashboard and studies components, ensuring better user experience during data fetching.
- Removed unused favicon.ico file to clean up the project structure.
- Enhanced the dashboard components to utilize a new utility function for API URL fetching, promoting code reusability.
This commit is contained in:
2024-12-05 11:52:22 -05:00
parent 29ce631901
commit 207f4d7fb8
25 changed files with 719 additions and 682 deletions

View File

@@ -1,6 +1,6 @@
'use client';
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { useParams } from "next/navigation";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "~/components/ui/card";
import { Button } from "~/components/ui/button";
@@ -14,6 +14,7 @@ import {
} from "lucide-react";
import { useToast } from "~/hooks/use-toast";
import Link from "next/link";
import { getApiUrl } from "~/lib/fetch-utils";
interface StudyStats {
participantCount: number;
@@ -31,13 +32,9 @@ export default function StudyDashboard() {
const { id } = useParams();
const { toast } = useToast();
useEffect(() => {
fetchStudyStats();
}, [id]);
const fetchStudyStats = async () => {
const fetchStudyStats = useCallback(async () => {
try {
const response = await fetch(`/api/studies/${id}/stats`);
const response = await fetch(getApiUrl(`/api/studies/${id}/stats`));
if (!response.ok) throw new Error("Failed to fetch study statistics");
const data = await response.json();
setStats(data.data);
@@ -51,7 +48,11 @@ export default function StudyDashboard() {
} finally {
setLoading(false);
}
};
}, [toast, id]);
useEffect(() => {
fetchStudyStats();
}, [fetchStudyStats]);
if (loading) {
return (