@@ -15,6 +15,10 @@ import NumberInput from 'components/input/number-input';
1515import Checkbox from 'components/input/checkbox' ;
1616import DatePicker from 'components/input/date-picker' ;
1717import DateTimePicker from 'components/input/datetime-picker' ;
18+ import { api } from 'trpc/react' ;
19+ import MultiSelect from 'components/multi-select' ;
20+ import { lang } from 'utils/language' ;
21+ import { detailedName } from 'utils/corps' ;
1822
1923interface GigFormProps {
2024 gig ?: Gig & { type : { name : string } } & { hiddenFor : { corpsId : string } [ ] } ;
@@ -51,17 +55,16 @@ const GigForm = ({ gig, gigTypes }: GigFormProps) => {
5155
5256 const router = useRouter ( ) ;
5357
54- // const { data: corpsii } = api.corps.search.useQuery({});
55- // const corpsiiOptions = corpsii?.map((c) => ({
56- // label:
57- // (c.number ? `#${c.number}` : 'p.e.') +
58- // ' ' +
59- // c.firstName +
60- // ' ' +
61- // (c.nickName ? '"' + c.nickName + '" ' : '') +
62- // c.lastName,
63- // value: c.id,
64- // }));
58+ // Only fetch corps if user presses the button or if hiddenFor is populated
59+ // to prevent having to fetch all corps every time. The fetch is about 30KB
60+ // (as of 2025)
61+ const [ hideFor , setHideFor ] = useState ( ( gig ?. hiddenFor . length ?? 0 ) !== 0 ) ;
62+ const { data : corpsii } = api . corps . search . useQuery ( { } , { enabled : hideFor } ) ;
63+
64+ const corpsiiOptions = corpsii ?. map ( ( c ) => ( {
65+ label : detailedName ( c ) ,
66+ value : c . id ,
67+ } ) ) ;
6568
6669 const form = useForm < FormValues > ( {
6770 initialValues : newGig
@@ -220,18 +223,31 @@ const GigForm = ({ gig, gigTypes }: GigFormProps) => {
220223 description = 'Lämna tom för att inte visa kryssruta'
221224 { ...form . getInputProps ( 'checkbox2' ) }
222225 />
223- { /*
224- <div className='col-span-1 flex flex-col focus-visible:ring-red-600 md:col-span-2'>
225- <div>Dölj spelning</div>
226- <MultiSelect
227- placeholder='Välj corps...'
228- className='outline-none focus-visible:outline-none'
229- options={corpsiiOptions ?? []}
230- defaultValue={form.values.hiddenFor}
231- {...form.getInputProps('hiddenFor')}
232- />
233- </div>
234- */ }
226+ < div className = 'col-span-1 flex flex-col focus-visible:ring-red-600 md:col-span-2' >
227+ { hideFor ? (
228+ < >
229+ < div > { lang ( 'Dölj spelning för' , 'Hide gig from' ) } </ div >
230+ < MultiSelect
231+ placeholder = 'Välj corps...'
232+ className = 'outline-none focus-visible:outline-none'
233+ options = { corpsiiOptions ?? [ ] }
234+ defaultValue = { form . values . hiddenFor }
235+ { ...form . getInputProps ( 'hiddenFor' ) }
236+ />
237+ </ >
238+ ) : (
239+ < Button
240+ color = 'no-fill'
241+ compact
242+ fullWidth
243+ onClick = { ( ) => {
244+ setHideFor ( ! hideFor ) ;
245+ } }
246+ >
247+ { lang ( 'Dölj spelning för corps...' , 'Hide gig from corps...' ) } { ' ' }
248+ </ Button >
249+ ) }
250+ </ div >
235251 < div className = 'flex space-x-4 whitespace-nowrap' >
236252 < Checkbox
237253 label = 'Allmän spelning?'
0 commit comments