From e2027e5499dc773f976f7a0e8c9c5a873647f3d5 Mon Sep 17 00:00:00 2001 From: David A Date: Fri, 13 Sep 2024 14:56:27 -0400 Subject: [PATCH] wip: loaded selected update --- .../coaching-session-card.tsx | 65 ++++++++++++++++++- src/components/shared/loaded-select.tsx | 28 ++++++-- 2 files changed, 86 insertions(+), 7 deletions(-) diff --git a/src/components/dashboard/coaching-session/coaching-session-card.tsx b/src/components/dashboard/coaching-session/coaching-session-card.tsx index f21626e..358db2b 100644 --- a/src/components/dashboard/coaching-session/coaching-session-card.tsx +++ b/src/components/dashboard/coaching-session/coaching-session-card.tsx @@ -5,6 +5,11 @@ import { Id } from "@/types/general"; import { Select, SelectContent, SelectGroup, SelectLabel, SelectTrigger, SelectValue } from "@radix-ui/react-select"; import LoadedSelect from "@/components/shared/loaded-select"; import { cn } from "@/lib/utils"; +import { useEffect, useState } from "react"; +import { useAppStateStore } from "@/lib/providers/app-state-store-provider"; +import { CoachingSession } from "@/types/coaching-session"; +import { CoachingRelationshipWithUserNames } from "@/types/coaching_relationship_with_user_names"; +import { Organization } from "@/types/organization"; export interface CoachingSessionCardProps { userId: Id @@ -14,7 +19,35 @@ export function CoachingSessionCard({ userId: userId, }: CoachingSessionCardProps) { + const { organizationId, setOrganizationId } = useAppStateStore( + (state) => state + ); + const { relationshipId, setRelationshipId } = useAppStateStore( + (state) => state + ); + const { coachingSessionId, setCoachingSessionId } = useAppStateStore( + (state) => state + ); + const [organizations, setOrganizations] = useState([]); + const [coachingRelationships, setCoachingRelationships] = useState< + CoachingRelationshipWithUserNames[] + >([]); + const [coachingSessions, setCoachingSessions] = useState( + [] + ); + + useEffect(() => { + async function loadCoachingRelationships() { + if (!organizationId) return; + console.debug("organizationId: " + organizationId); + } + loadCoachingRelationships(); + }, [organizationId]); + + function selectOrganization() { + setOrganizationId(organizationId); + } return ( @@ -22,7 +55,6 @@ export function CoachingSessionCard({
- -
+ { + organizationId + ? + (
+ +
) + : + ( +
+ No organization Found +
+ ) + } +
) diff --git a/src/components/shared/loaded-select.tsx b/src/components/shared/loaded-select.tsx index 224af6e..b50e9cc 100644 --- a/src/components/shared/loaded-select.tsx +++ b/src/components/shared/loaded-select.tsx @@ -1,20 +1,28 @@ import useRequest from "@/hooks/use-request"; -import { SelectItem } from "@radix-ui/react-select"; -import { memo, useMemo } from "react"; +import { Select, SelectItem } from "@radix-ui/react-select"; +import { memo, useEffect, useMemo, useState } from "react"; import { SWRResponse } from "swr"; export type SelectListDataType = any; export interface LoadedSelectProps { - url: string, - params?: any, + url: string; + params?: any; + selectedItem?: (value: string) => void; + onSelectedValue?: (value: string) => void; } const LoadedSelect = memo(function LoadedSelect({ url: url, params: params, + selectedItem, + onSelectedValue }: LoadedSelectProps): JSX.Element { + const [selectedValue, setSelectedValue] = useState(""); + + useEffect(() => setSelectedValue(selectedValue), [selectedValue]); + const { data: selectList, error, @@ -37,6 +45,10 @@ const LoadedSelect = memo(function LoadedSelect({ }); }, [selectList]); + const handleValueChange = (value: string) => { + setSelectedValue(value); + }; + if (error) { return
Error: {error.message}
} @@ -45,7 +57,13 @@ const LoadedSelect = memo(function LoadedSelect({ return
Loading...
} - return (
{selectItemList}
) + return ( + ) }); export default LoadedSelect; \ No newline at end of file