From 70ebc2fa2cdf6eee04db5967ca465a151dfeaab2 Mon Sep 17 00:00:00 2001 From: lachlanshoesmith <12870244+lachlanshoesmith@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:38:56 +1100 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=91=AF=20list=20all=20societies,=20ad?= =?UTF-8?q?d=20basic=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/App.tsx | 5 ++ .../SettingsNavbar/SettingsNavbar.tsx | 6 ++ .../SearchSocieties/SearchSocieties.tsx | 81 +++++++++++++++++++ frontend/src/TextInput/TextInput.tsx | 16 ++-- 4 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 frontend/src/Settings/SettingsPage/SocietyManagementPage/SearchSocieties/SearchSocieties.tsx diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7cecd74..72227ae 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -19,6 +19,7 @@ import GenerateOTP from './GenerateOTP/GenerateOTP'; import VerifyOTP from './VerifyOTP/VerifyOTP'; import { SocietyManagementPage } from './Settings/SettingsPage/SocietyManagementPage/SocietyManagementPage'; import { CreateNewSocietyPage } from './Settings/SettingsPage/SocietyManagementPage/CreateNewSociety/CreateNewSociety'; +import { SearchSocietiesPage } from './Settings/SettingsPage/SocietyManagementPage/SearchSocieties/SearchSocieties'; function App() { const [user, setUser] = useState(null); @@ -100,6 +101,10 @@ function App() { } /> } /> } /> + } + /> } /> } /> diff --git a/frontend/src/Settings/SettingsNavbar/SettingsNavbar.tsx b/frontend/src/Settings/SettingsNavbar/SettingsNavbar.tsx index 6a4f85f..35ca6e5 100644 --- a/frontend/src/Settings/SettingsNavbar/SettingsNavbar.tsx +++ b/frontend/src/Settings/SettingsNavbar/SettingsNavbar.tsx @@ -2,6 +2,7 @@ import { CalendarIcon, FaceSmileIcon, KeyIcon, + MagnifyingGlassIcon, MegaphoneIcon, StarIcon, UserCircleIcon, @@ -38,6 +39,11 @@ const rows: Row[][] = [ name: 'Create a new society', to: '/settings/societies/new', }, + { + icon: , + name: 'Join a society', + to: '/settings/societies/search', + }, ], [ { diff --git a/frontend/src/Settings/SettingsPage/SocietyManagementPage/SearchSocieties/SearchSocieties.tsx b/frontend/src/Settings/SettingsPage/SocietyManagementPage/SearchSocieties/SearchSocieties.tsx new file mode 100644 index 0000000..0007453 --- /dev/null +++ b/frontend/src/Settings/SettingsPage/SocietyManagementPage/SearchSocieties/SearchSocieties.tsx @@ -0,0 +1,81 @@ +import { UserGroupIcon } from '@heroicons/react/24/outline'; +import Button from '../../../../Button/Button'; +import { ButtonIcons, ButtonVariants } from '../../../../Button/ButtonTypes'; +import { TextInput, TextOptions } from '../../../../TextInput/TextInput'; +import { SettingsPage } from '../../SettingsPage'; +import { useContext, useEffect, useState } from 'react'; +import { + Societies, + Society, + UserContext, +} from '../../../../UserContext/UserContext'; + +export const SearchSocietiesPage = () => { + const [societyName, setSocietyName] = useState(''); + const [foundSocieties, setFoundSocieties] = useState([]); + const [success, setSuccess] = useState(''); + const [error, setError] = useState(''); + const { setSocieties } = useContext(UserContext); + useEffect(() => { + searchSocieties(''); + }, []); + + const searchSocieties = async (societyName: string) => { + const societies = await fetch('http://localhost:5180/societies', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + credentials: 'include', + }); + + const societiesJson = await societies.json(); + + if (societies.ok) { + setError(''); + setFoundSocieties(societiesJson); + if (societyName) { + setFoundSocieties( + societiesJson.filter((society: Society) => + society.name.toLowerCase().includes(societyName.toLowerCase()) + ) + ); + } + } else { + setError(societiesJson.message); + setSuccess(''); + } + }; + + return ( + setSocietyName(name)} + icon={} + error={error !== ''} + noMargin + />, +