diff --git a/src/components/ui/dashboard/dynamic-api-select.tsx b/src/components/ui/dashboard/dynamic-api-select.tsx index 3d02955..12884b8 100644 --- a/src/components/ui/dashboard/dynamic-api-select.tsx +++ b/src/components/ui/dashboard/dynamic-api-select.tsx @@ -1,6 +1,8 @@ import React, { useState } from 'react'; import { useApiData } from '@/hooks/use-api-data'; -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { CoachingSession, isCoachingSession } from '@/types/coaching-session'; +import { DateTime } from 'ts-luxon'; interface DynamicApiSelectProps { url: string; @@ -24,11 +26,11 @@ export function DynamicApiSelect({ method = 'GET', params = {}, onChange, - placeholder = "Select an organization", + placeholder = "Select an option", getOptionLabel, getOptionValue, elementId, - groupByDate + groupByDate = false }: DynamicApiSelectProps) { const { data: response, isLoading, error } = useApiData>(url, { method, params }); const [value, setValue] = useState(''); @@ -38,26 +40,63 @@ export function DynamicApiSelect({ onChange(newValue); } - if (isLoading) return

Loading...

- if (error) return

Error: {error.message}

- if (!response || response.status_code !== 200) return

Error: Invalid response

+ if (isLoading) return

Loading...

; + if (error) return

Error: {error.message}

; + if (!response || response.status_code !== 200) return

Error: Invalid response

; const items = response.data; - return ( - + + + + {groupByDate && coachingSessions.length > 0 + ? renderCoachingSessions(coachingSessions) + : renderOtherItems(items)} ); -} +} \ No newline at end of file diff --git a/src/components/ui/dashboard/join-coaching-session.tsx b/src/components/ui/dashboard/join-coaching-session.tsx index c654834..113d3fb 100644 --- a/src/components/ui/dashboard/join-coaching-session.tsx +++ b/src/components/ui/dashboard/join-coaching-session.tsx @@ -73,6 +73,7 @@ export function JoinCoachingSession({ userId: userId }: CoachingSessionCardProps getOptionLabel={(session) => session.date.toString()} getOptionValue={(session) => session.id.toString()} elementId='session-selector' + groupByDate={true} /> )} @@ -88,4 +89,7 @@ export function JoinCoachingSession({ userId: userId }: CoachingSessionCardProps ) -} \ No newline at end of file +} + +// godot +//asesprint diff --git a/src/hooks/use-api-data.ts b/src/hooks/use-api-data.ts index 03387da..fdd4298 100644 --- a/src/hooks/use-api-data.ts +++ b/src/hooks/use-api-data.ts @@ -12,7 +12,6 @@ const baseUrl = siteConfig.url; const fetcher = async ({ url, method = 'POST', params }: FetcherOptions) => { const fullUrl = `${baseUrl}${url}`; - console.log(fullUrl); const headers: HeadersInit = { 'Content-Type': 'application/json', @@ -24,7 +23,6 @@ const fetcher = async ({ url, method = 'POST', params }: FetcherOptions) => { headers, credentials: 'include', }; - console.log(JSON.stringify(fetchOptions)); const response = await fetch(fullUrl, fetchOptions); if (!response.ok) { @@ -42,7 +40,7 @@ export function useApiData( body?: Record } = {} ) { - const { method = 'POST', params = {}, body = {} || undefined } = options + const { method = 'POST', params = {}, body = {} } = options const { data, error, isLoading, mutate } = useSWR( { url, method, params, body }, @@ -53,8 +51,6 @@ export function useApiData( } ) - console.log(data); - return { data, isLoading,