wip
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useEffectiveDriverId } from '@/lib/currentDriver';
|
||||
import { getSendNotificationUseCase } from '@/lib/di-container';
|
||||
import { getSendNotificationUseCase, getRaceRepository, getLeagueRepository } from '@/lib/di-container';
|
||||
import type { NotificationUrgency } from '@gridpilot/notifications/application';
|
||||
import {
|
||||
Bell,
|
||||
@@ -170,38 +170,64 @@ export default function DevToolbar() {
|
||||
setSending(true);
|
||||
try {
|
||||
const sendNotification = getSendNotificationUseCase();
|
||||
|
||||
|
||||
const raceRepository = getRaceRepository();
|
||||
const leagueRepository = getLeagueRepository();
|
||||
|
||||
const [allRaces, allLeagues] = await Promise.all([
|
||||
raceRepository.findAll(),
|
||||
leagueRepository.findAll(),
|
||||
]);
|
||||
|
||||
const completedRaces = allRaces.filter((race: any) => race.status === 'completed');
|
||||
const scheduledRaces = allRaces.filter((race: any) => race.status === 'scheduled');
|
||||
|
||||
const primaryRace = completedRaces[0] ?? allRaces[0];
|
||||
const secondaryRace = scheduledRaces[0] ?? allRaces[1] ?? primaryRace;
|
||||
const primaryLeague = allLeagues[0];
|
||||
|
||||
let title: string;
|
||||
let body: string;
|
||||
let notificationType: 'protest_filed' | 'protest_defense_requested' | 'protest_vote_required';
|
||||
let actionUrl: string;
|
||||
|
||||
switch (selectedType) {
|
||||
case 'protest_filed':
|
||||
case 'protest_filed': {
|
||||
const raceId = primaryRace?.id;
|
||||
title = '🚨 Protest Filed Against You';
|
||||
body = 'Max Verstappen has filed a protest against you for unsafe rejoining at Turn 3, Lap 12 during the Spa-Francorchamps race.';
|
||||
body =
|
||||
'A protest has been filed against you for unsafe rejoining during a recent race. Please review the incident details.';
|
||||
notificationType = 'protest_filed';
|
||||
actionUrl = '/races/race-1/stewarding';
|
||||
actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
|
||||
break;
|
||||
case 'defense_requested':
|
||||
}
|
||||
case 'defense_requested': {
|
||||
const raceId = secondaryRace?.id ?? primaryRace?.id;
|
||||
title = '⚖️ Defense Requested';
|
||||
body = 'A steward has requested your defense regarding the incident at Turn 1 in the Monza race. Please provide your side of the story within 48 hours.';
|
||||
body =
|
||||
'A steward has requested your defense regarding a recent incident. Please provide your side of the story within 48 hours.';
|
||||
notificationType = 'protest_defense_requested';
|
||||
actionUrl = '/races/race-2/stewarding';
|
||||
actionUrl = raceId ? `/races/${raceId}/stewarding` : '/races';
|
||||
break;
|
||||
case 'vote_required':
|
||||
}
|
||||
case 'vote_required': {
|
||||
const leagueId = primaryLeague?.id;
|
||||
title = '🗳️ Your Vote Required';
|
||||
body = 'As a league steward, you are required to vote on the protest: Driver A vs Driver B - Causing a collision at Eau Rouge.';
|
||||
body =
|
||||
'As a league steward, you are required to vote on an open protest. Please review the case and cast your vote.';
|
||||
notificationType = 'protest_vote_required';
|
||||
actionUrl = '/leagues/league-1/stewarding';
|
||||
actionUrl = leagueId ? `/leagues/${leagueId}/stewarding` : '/leagues';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// For modal urgency, add actions
|
||||
const actions = selectedUrgency === 'modal' ? [
|
||||
{ label: 'View Protest', type: 'primary' as const, href: actionUrl, actionId: 'view' },
|
||||
{ label: 'Dismiss', type: 'secondary' as const, actionId: 'dismiss' },
|
||||
] : undefined;
|
||||
const actions =
|
||||
selectedUrgency === 'modal'
|
||||
? [
|
||||
{ label: 'View Protest', type: 'primary' as const, href: actionUrl, actionId: 'view' },
|
||||
{ label: 'Dismiss', type: 'secondary' as const, actionId: 'dismiss' },
|
||||
]
|
||||
: undefined;
|
||||
|
||||
await sendNotification.execute({
|
||||
recipientId: currentDriverId,
|
||||
@@ -214,9 +240,12 @@ export default function DevToolbar() {
|
||||
actions,
|
||||
data: {
|
||||
protestId: `demo-protest-${Date.now()}`,
|
||||
raceId: 'race-1',
|
||||
leagueId: 'league-1',
|
||||
deadline: selectedUrgency === 'modal' ? new Date(Date.now() + 48 * 60 * 60 * 1000) : undefined,
|
||||
raceId: primaryRace?.id,
|
||||
leagueId: primaryLeague?.id,
|
||||
deadline:
|
||||
selectedUrgency === 'modal'
|
||||
? new Date(Date.now() + 48 * 60 * 60 * 1000)
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user