add website tests
This commit is contained in:
16
apps/website/app/api/media/avatar/[driverId]/route.ts
Normal file
16
apps/website/app/api/media/avatar/[driverId]/route.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
const ONE_BY_ONE_PNG_BASE64 =
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO0pS0kAAAAASUVORK5CYII=';
|
||||
|
||||
export async function GET(): Promise<Response> {
|
||||
const body = Buffer.from(ONE_BY_ONE_PNG_BASE64, 'base64');
|
||||
|
||||
return new Response(body, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'content-type': 'image/png',
|
||||
'cache-control': 'public, max-age=60',
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import { useServices } from '@/lib/services/ServiceProvider';
|
||||
|
||||
export default function LeaderboardsPage() {
|
||||
const router = useRouter();
|
||||
const { driverService, teamService } = useServices();
|
||||
const [drivers, setDrivers] = useState<DriverLeaderboardItemViewModel[]>([]);
|
||||
const [teams, setTeams] = useState<TeamSummaryViewModel[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
@@ -29,7 +30,6 @@ export default function LeaderboardsPage() {
|
||||
useEffect(() => {
|
||||
const load = async () => {
|
||||
try {
|
||||
const { driverService, teamService } = useServices();
|
||||
const driversViewModel = await driverService.getDriverLeaderboard();
|
||||
const teams = await teamService.getAllTeams();
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ export default function LeagueRulebookPage() {
|
||||
const params = useParams();
|
||||
const leagueId = params.id as string;
|
||||
|
||||
const { leagueService } = useServices();
|
||||
|
||||
const [viewModel, setViewModel] = useState<LeagueDetailPageViewModel | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [activeSection, setActiveSection] = useState<RulebookSection>('scoring');
|
||||
@@ -20,7 +22,6 @@ export default function LeagueRulebookPage() {
|
||||
useEffect(() => {
|
||||
async function loadData() {
|
||||
try {
|
||||
const { leagueService } = useServices();
|
||||
const data = await leagueService.getLeagueDetailPageData(leagueId);
|
||||
if (!data) {
|
||||
setLoading(false);
|
||||
@@ -36,7 +37,7 @@ export default function LeagueRulebookPage() {
|
||||
}
|
||||
|
||||
loadData();
|
||||
}, [leagueId]);
|
||||
}, [leagueId, leagueService]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import OnboardingWizard from '@/components/onboarding/OnboardingWizard';
|
||||
import { useCurrentDriver } from '@/hooks/useDriverService';
|
||||
@@ -12,13 +13,23 @@ export default function OnboardingPage() {
|
||||
const { session } = useAuth();
|
||||
const { data: driver, isLoading } = useCurrentDriver();
|
||||
|
||||
// If user is not authenticated, redirect to login
|
||||
if (!session) {
|
||||
router.replace('/auth/login?returnTo=/onboarding');
|
||||
const shouldRedirectToLogin = !session;
|
||||
const shouldRedirectToDashboard = !isLoading && Boolean(driver);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldRedirectToLogin) {
|
||||
router.replace('/auth/login?returnTo=/onboarding');
|
||||
return;
|
||||
}
|
||||
if (shouldRedirectToDashboard) {
|
||||
router.replace('/dashboard');
|
||||
}
|
||||
}, [router, shouldRedirectToLogin, shouldRedirectToDashboard]);
|
||||
|
||||
if (shouldRedirectToLogin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show loading while checking driver data
|
||||
if (isLoading) {
|
||||
return (
|
||||
<main className="min-h-screen bg-deep-graphite flex items-center justify-center">
|
||||
@@ -27,9 +38,7 @@ export default function OnboardingPage() {
|
||||
);
|
||||
}
|
||||
|
||||
// If driver profile exists, onboarding is complete – go to dashboard
|
||||
if (driver) {
|
||||
router.replace('/dashboard');
|
||||
if (shouldRedirectToDashboard) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -269,10 +269,14 @@ export default function ProfilePage() {
|
||||
const isOwnProfile = true; // This page is always your own profile
|
||||
|
||||
useEffect(() => {
|
||||
if (!effectiveDriverId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const loadData = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const currentDriverId = effectiveDriverId;
|
||||
const profileViewModel = await driverService.getDriverProfile(currentDriverId);
|
||||
const profileViewModel = await driverService.getDriverProfile(effectiveDriverId);
|
||||
setProfileData(profileViewModel);
|
||||
} catch (error) {
|
||||
console.error('Failed to load profile:', error);
|
||||
@@ -280,6 +284,7 @@ export default function ProfilePage() {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
void loadData();
|
||||
}, [effectiveDriverId, driverService]);
|
||||
|
||||
|
||||
@@ -22,7 +22,9 @@ interface EntitySection {
|
||||
|
||||
export default function SponsorshipRequestsPage() {
|
||||
const currentDriverId = useEffectiveDriverId();
|
||||
|
||||
|
||||
const { sponsorshipService, driverService, leagueService, teamService, leagueMembershipService } = useServices();
|
||||
|
||||
const [sections, setSections] = useState<EntitySection[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -32,7 +34,10 @@ export default function SponsorshipRequestsPage() {
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
const { sponsorshipService, driverService, leagueService, teamService, leagueMembershipService } = useServices();
|
||||
if (!currentDriverId) {
|
||||
setSections([]);
|
||||
return;
|
||||
}
|
||||
|
||||
const allSections: EntitySection[] = [];
|
||||
|
||||
@@ -107,20 +112,20 @@ export default function SponsorshipRequestsPage() {
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [currentDriverId]);
|
||||
}, [currentDriverId, sponsorshipService, driverService, leagueService, teamService, leagueMembershipService]);
|
||||
|
||||
useEffect(() => {
|
||||
loadAllRequests();
|
||||
}, [loadAllRequests]);
|
||||
|
||||
const handleAccept = async (requestId: string) => {
|
||||
const { sponsorshipService } = useServices();
|
||||
if (!currentDriverId) return;
|
||||
await sponsorshipService.acceptSponsorshipRequest(requestId, currentDriverId);
|
||||
await loadAllRequests();
|
||||
};
|
||||
|
||||
const handleReject = async (requestId: string, reason?: string) => {
|
||||
const { sponsorshipService } = useServices();
|
||||
if (!currentDriverId) return;
|
||||
await sponsorshipService.rejectSponsorshipRequest(requestId, currentDriverId, reason);
|
||||
await loadAllRequests();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user