|
1 |
| -import React, { useState } from 'react'; |
| 1 | +import React, { MouseEventHandler, useState } from 'react'; |
2 | 2 | import { Id } from "@/types/general";
|
| 3 | +import Link from 'next/link'; |
3 | 4 | import { DynamicApiSelect } from './dynamic-api-select';
|
4 | 5 | import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
5 | 6 | import { Organization } from '@/types/organization';
|
6 | 7 | import { CoachingRelationshipWithUserNames } from '@/types/coaching_relationship_with_user_names';
|
7 | 8 | import { CoachingSession } from '@/types/coaching-session';
|
8 | 9 | import { DateTime } from 'ts-luxon';
|
| 10 | +import { Label } from "@/components/ui/label"; |
| 11 | +import { Button } from '../button'; |
| 12 | + |
9 | 13 |
|
10 | 14 | export interface CoachingSessionCardProps {
|
11 | 15 | userId: Id;
|
12 | 16 | }
|
13 | 17 |
|
14 | 18 | export function JoinCoachingSession({ userId: userId }: CoachingSessionCardProps) {
|
15 |
| - const [organization, setOrganizations] = useState<string | null>(null); |
16 |
| - const [relationship, setRelationships] = useState<string | null>(null); |
17 |
| - const [sessions, setSessions] = useState<string | null>(null); |
18 |
| - |
19 |
| - const handleOrganizationSelection = (value: string) => { |
20 |
| - setOrganizations(value) |
21 |
| - setRelationships(null) // Reset second selection when first changes |
22 |
| - } |
23 |
| - |
24 |
| - const handleRelationshipSelection = (value: string) => { |
25 |
| - setRelationships(value); |
26 |
| - setSessions(null); |
27 |
| - } |
28 |
| - |
29 |
| - const handleSessionSelection = (value: string) => { |
30 |
| - setSessions(value); |
31 |
| - } |
| 19 | + const [organizationId, setOrganizationId] = useState<string | null>(null); |
| 20 | + const [relationshipId, setRelationshipId] = useState<string | null>(null); |
| 21 | + const [sessionId, setSessionId] = useState<string | null>(null); |
32 | 22 |
|
33 | 23 | return (
|
34 | 24 | <Card className="w-[300px]">
|
35 | 25 | <CardHeader>
|
36 |
| - <CardTitle>Make Your Selection</CardTitle> |
| 26 | + <CardTitle>Join a Coaching Session</CardTitle> |
37 | 27 | </CardHeader>
|
38 |
| - <CardContent> |
39 |
| - <div className="space-y-4"> |
| 28 | + <CardContent className='grid gap-6'> |
| 29 | + <div className="grid gap-2"> |
| 30 | + <Label htmlFor='organization-selector'>Organization</Label> |
| 31 | + |
40 | 32 | <DynamicApiSelect<Organization>
|
41 | 33 | url="/organizations"
|
42 | 34 | params={{ userId }}
|
43 |
| - onChange={handleOrganizationSelection} |
| 35 | + onChange={setOrganizationId} |
44 | 36 | placeholder="Select an organization"
|
45 | 37 | getOptionLabel={(org) => org.name}
|
46 | 38 | getOptionValue={(org) => org.id.toString()}
|
| 39 | + elementId='organization-selector' |
47 | 40 | />
|
48 |
| - {organization && ( |
| 41 | + </div> |
| 42 | + {organizationId && ( |
| 43 | + <div className="grid gap-2"> |
| 44 | + <Label htmlFor='relationship-selector'>Relationship</Label> |
| 45 | + |
49 | 46 | <DynamicApiSelect<CoachingRelationshipWithUserNames>
|
50 |
| - url={`/organizations/${organization}/coaching_relationships`} |
51 |
| - params={{ organization }} |
52 |
| - onChange={handleRelationshipSelection} |
| 47 | + url={`/organizations/${organizationId}/coaching_relationships`} |
| 48 | + params={{ organizationId }} |
| 49 | + onChange={setRelationshipId} |
53 | 50 | placeholder="Select coaching relationship"
|
54 |
| - getOptionLabel={(relationship) => relationship.coach_first_name} |
| 51 | + getOptionLabel={ |
| 52 | + (relationship) => |
| 53 | + `${relationship.coach_first_name} ${relationship.coach_last_name} -> ${relationship.coachee_first_name} ${relationship.coach_last_name}` |
| 54 | + } |
55 | 55 | getOptionValue={(relationship) => relationship.id.toString()}
|
| 56 | + elementId='relationship-selector' |
56 | 57 | />
|
57 |
| - )} |
58 |
| - {relationship && ( |
| 58 | + </div> |
| 59 | + )} |
| 60 | + {relationshipId && ( |
| 61 | + <div className="grid gap-2"> |
| 62 | + <Label htmlFor='session-selector'>Coaching Session</Label> |
| 63 | + |
59 | 64 | <DynamicApiSelect<CoachingSession>
|
60 | 65 | url="/coaching_sessions"
|
61 | 66 | params={{
|
62 |
| - coaching_relationship_id: relationship, |
| 67 | + coaching_relationship_id: relationshipId, |
63 | 68 | from_date: DateTime.now().minus({ month: 1 }).toISODate(),
|
64 | 69 | to_Date: DateTime.now().plus({ month: 1 }).toISODate()
|
65 | 70 | }}
|
66 |
| - onChange={handleRelationshipSelection} |
| 71 | + onChange={setSessionId} |
67 | 72 | placeholder="Select coaching session"
|
68 | 73 | getOptionLabel={(session) => session.date.toString()}
|
69 | 74 | getOptionValue={(session) => session.id.toString()}
|
| 75 | + elementId='session-selector' |
70 | 76 | />
|
71 |
| - )} |
72 |
| - </div> |
| 77 | + </div> |
| 78 | + )} |
| 79 | + {sessionId && ( |
| 80 | + <div className='grid gap-2'> |
| 81 | + <Button variant='outline' className='w-full'> |
| 82 | + <Link href={`/coaching-sessions/${sessionId}`}> |
| 83 | + Join Session |
| 84 | + </Link> |
| 85 | + </Button> |
| 86 | + </div> |
| 87 | + )} |
73 | 88 | </CardContent>
|
74 | 89 | </Card>
|
75 | 90 | )
|
|
0 commit comments