diff --git a/src/components/Dropdown.tsx b/src/components/Dropdown.tsx index 8564272..2efce4f 100644 --- a/src/components/Dropdown.tsx +++ b/src/components/Dropdown.tsx @@ -50,7 +50,7 @@ interface DropdownProps { } export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: DropdownProps) => { - const { courses, selectBasketNames, addCourseToBasket } = useContext(coursesContext)!; + const { courses, selectBasketNames, addCourseToBasket,getUserTimetable } = useContext(coursesContext)!; const { users } = useContext(usersContext)!; const basketNames = useMemo(() => selectBasketNames(), [selectBasketNames]); const [filteredCourses, setFilteredCourses] = useState>([]); @@ -65,6 +65,15 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D } }; + const onUserClick = (event: MouseEvent) => { + const target = event.currentTarget; + if (target.id && target.textContent) { + console.log(target.id,target.textContent); + getUserTimetable(target.id); + handleCloseDropdown(); + } + }; + useEffect(() => { const filterCourses = (input: string) => { const filteredCourses = courses.filter( @@ -111,7 +120,7 @@ export const Dropdown = ({ open, input, handleCloseDropdown, selectedOption }: D {selectedOption === 'studenci' ? (
{filteredUsers.map(({ name, surname, id }, index) => ( - +

{name} {surname}{' '}

diff --git a/src/contexts/CoursesProvider.tsx b/src/contexts/CoursesProvider.tsx index 4f1eb54..347df5d 100644 --- a/src/contexts/CoursesProvider.tsx +++ b/src/contexts/CoursesProvider.tsx @@ -28,6 +28,7 @@ interface CourseContext { selectBasketNames: () => Array; selectBasketCourses: () => Array; selectBasketCourseGroups: (courseId: number) => { lecture: Group | undefined; classes: Group | undefined }; + getUserTimetable: (userID: string) => Promise; } export const coursesContext = createContext(undefined); @@ -165,6 +166,17 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { } }; + const getUserTimetable = async (userID:string) => { + try { + const {data} = await axiosInstance.get( + `${process.env.REACT_APP_API_URL}/api/v1/commisions/user/${userID}`, + ); + console.log(data); + } catch (e) { + console.log(e); + } + } + const fetchCourses = async () => { try { const { data: courses } = await axiosInstance.get>( @@ -200,6 +212,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => { selectBasketNames, selectBasketCourses, selectBasketCourseGroups, + getUserTimetable, }} > {children}