@@ -8,7 +8,7 @@ import { Alert, AlertDescription } from '@/components/ui/alert';
88import { Skeleton } from '@/components/ui/skeleton' ;
99import { Button } from '@/components/ui/button' ;
1010import { toast } from 'sonner' ;
11- import { getFIRConfig } from '@/config/firStations ' ;
11+ import { cptBelongsToFir , CPT_FIR_NAMES } from '@/config/cptFirMapping ' ;
1212import { useUser } from '@/hooks/useUser' ;
1313import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from '@/components/ui/select' ;
1414
@@ -57,21 +57,11 @@ const CPTOverview: React.FC = () => {
5757 const result = await response . json ( ) ;
5858 let filteredData = result . data || [ ] ;
5959
60- // Filter by FIR if specified
60+ // Filter by FIR using prefix-based mapping
6161 if ( fir ) {
62- // Hole die FIR-Konfiguration
63- const firConfig = getFIRConfig ( fir ) ; // z.B. CONFIG['EDMM']
64-
65- if ( firConfig && firConfig . stations ) {
66- // Extrahiere alle Callsigns aus den Stations
67- const validCallsigns = firConfig . stations . map ( station => station . callsign ) ;
68-
69- // Filtere nach Callsigns
70- filteredData = filteredData . filter ( ( cpt : CPTData ) =>
71- validCallsigns . includes ( cpt . position ) || // Exakte Übereinstimmung mit Config
72- cpt . position . startsWith ( fir + '_' ) // Beginnt mit FIR-Code (z.B. EDMM_WLD_CTR, EDGG_CH_CTR)
73- ) ;
74- }
62+ filteredData = filteredData . filter ( ( cpt : CPTData ) =>
63+ cptBelongsToFir ( cpt . position , fir )
64+ ) ;
7565 }
7666
7767 // Sort by date (upcoming first)
@@ -167,22 +157,6 @@ const CPTOverview: React.FC = () => {
167157 } ;
168158
169159
170- const getStationName = ( position : string ) => {
171- // Extract FIR code (first 4 characters)
172- if ( position . length < 4 ) return position ;
173-
174- const fir = position . substring ( 0 , 4 ) ;
175- const firConfig = getFIRConfig ( fir ) ;
176- if ( ! firConfig ) return position ;
177-
178- // Find matching station by checking if position starts with the station's base callsign
179- const station = firConfig . stations . find ( s => {
180- const baseCallsign = s . callsign . replace ( / _ / g, '' ) ;
181- return position . startsWith ( baseCallsign ) ;
182- } ) ;
183-
184- return station ? station . name : position ;
185- } ;
186160
187161 if ( loading ) {
188162 return (
@@ -215,7 +189,7 @@ const CPTOverview: React.FC = () => {
215189 < div className = "flex items-center justify-between" >
216190 < div >
217191 < h2 className = "text-3xl font-bold tracking-tight" >
218- { fir ? getFIRConfig ( fir ) ?. fullName : 'Alle FIRs' }
192+ { fir ? CPT_FIR_NAMES [ fir ] ?? fir : 'Alle FIRs' }
219193 </ h2 >
220194 < p className = "text-muted-foreground mt-1" >
221195 Anstehende Controller Practical Tests
@@ -308,9 +282,7 @@ const CPTOverview: React.FC = () => {
308282 </ div >
309283 < CardDescription className = "flex items-center gap-2 text-sm" >
310284 < MapPin className = "h-4 w-4" />
311- < span className = "font-medium" > { cpt . position . split ( "_" ) [ 0 ] } </ span >
312- < span className = "text-muted-foreground" > •</ span >
313- < span > { getStationName ( cpt . position ) } </ span >
285+ < span className = "font-medium" > { cpt . position } </ span >
314286 </ CardDescription >
315287 </ div >
316288 < div className = "text-right space-y-1" >
0 commit comments