2024-02-07 13:11:54 +00:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
import { Link, NavLink, useNavigate, useParams } from 'react-router-dom';
|
2024-02-05 10:51:55 +00:00
|
|
|
import { Organization } from 'gql-client';
|
2023-12-11 14:35:34 +00:00
|
|
|
|
2024-02-07 13:11:54 +00:00
|
|
|
import { Typography, Option } from '@material-tailwind/react';
|
2024-02-22 11:56:26 +00:00
|
|
|
import { useDisconnect } from 'wagmi';
|
2024-02-07 13:11:54 +00:00
|
|
|
|
|
|
|
import { useGQLClient } from '../context/GQLClientContext';
|
|
|
|
import AsyncSelect from './shared/AsyncSelect';
|
|
|
|
|
|
|
|
const Sidebar = () => {
|
|
|
|
const { orgSlug } = useParams();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const client = useGQLClient();
|
2024-02-22 11:56:26 +00:00
|
|
|
const { disconnect } = useDisconnect();
|
2024-02-07 13:11:54 +00:00
|
|
|
|
|
|
|
const [selectedOrgSlug, setSelectedOrgSlug] = useState(orgSlug);
|
|
|
|
const [organizations, setOrganizations] = useState<Organization[]>([]);
|
|
|
|
|
|
|
|
const fetchUserOrganizations = useCallback(async () => {
|
|
|
|
const { organizations } = await client.getOrganizations();
|
|
|
|
setOrganizations(organizations);
|
|
|
|
}, [orgSlug]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetchUserOrganizations();
|
|
|
|
setSelectedOrgSlug(orgSlug);
|
|
|
|
}, [orgSlug]);
|
2023-12-21 09:29:33 +00:00
|
|
|
|
2024-02-22 11:56:26 +00:00
|
|
|
const handleLogOut = useCallback(() => {
|
|
|
|
disconnect();
|
|
|
|
navigate('/login');
|
|
|
|
}, [disconnect, navigate]);
|
|
|
|
|
2023-12-11 14:35:34 +00:00
|
|
|
return (
|
|
|
|
<div className="flex flex-col h-full p-4">
|
2023-12-12 12:24:20 +00:00
|
|
|
<div className="grow">
|
2023-12-11 14:35:34 +00:00
|
|
|
<div>
|
2024-02-07 13:11:54 +00:00
|
|
|
<Link to={`/${orgSlug}`}>
|
2023-12-15 06:43:18 +00:00
|
|
|
<h3 className="text-black text-2xl">Snowball</h3>
|
|
|
|
</Link>
|
2023-12-11 14:35:34 +00:00
|
|
|
</div>
|
2024-02-07 13:11:54 +00:00
|
|
|
<AsyncSelect
|
|
|
|
className="bg-white py-2"
|
|
|
|
value={selectedOrgSlug}
|
|
|
|
onChange={(value) => {
|
|
|
|
setSelectedOrgSlug(value!);
|
|
|
|
navigate(`/${value}`);
|
|
|
|
}}
|
|
|
|
selected={(_, index) => (
|
|
|
|
<div className="flex gap-2">
|
|
|
|
<div>^</div>
|
|
|
|
<div>
|
|
|
|
<span>{organizations[index!]?.name}</span>
|
2024-02-26 16:56:51 +00:00
|
|
|
<Typography placeholder={''}>Organization</Typography>
|
2024-02-07 13:11:54 +00:00
|
|
|
</div>
|
2024-02-05 10:51:55 +00:00
|
|
|
</div>
|
2024-02-07 13:11:54 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
{/* TODO: Show label organization and manage in option */}
|
|
|
|
{organizations.map((org) => (
|
|
|
|
<Option key={org.id} value={org.slug}>
|
|
|
|
^ {org.name}
|
|
|
|
{org.slug === selectedOrgSlug && <p className="float-right">^</p>}
|
|
|
|
</Option>
|
|
|
|
))}
|
|
|
|
</AsyncSelect>
|
2023-12-11 14:35:34 +00:00
|
|
|
<div>
|
|
|
|
<NavLink
|
2024-02-07 13:11:54 +00:00
|
|
|
to={`/${orgSlug}`}
|
2023-12-11 14:35:34 +00:00
|
|
|
className={({ isActive }) => (isActive ? 'text-blue-500' : '')}
|
|
|
|
>
|
2024-02-26 16:56:51 +00:00
|
|
|
<Typography placeholder={''}>Projects</Typography>
|
2023-12-11 14:35:34 +00:00
|
|
|
</NavLink>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<NavLink
|
2024-02-07 13:11:54 +00:00
|
|
|
to={`/${orgSlug}/settings`}
|
2023-12-11 14:35:34 +00:00
|
|
|
className={({ isActive }) => (isActive ? 'text-blue-500' : '')}
|
|
|
|
>
|
2024-02-26 16:56:51 +00:00
|
|
|
<Typography placeholder={''}>Settings</Typography>
|
2023-12-11 14:35:34 +00:00
|
|
|
</NavLink>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-12 12:24:20 +00:00
|
|
|
<div className="grow flex flex-col justify-end">
|
2024-02-22 11:56:26 +00:00
|
|
|
<a className="cursor-pointer" onClick={handleLogOut}>
|
|
|
|
Log Out
|
|
|
|
</a>
|
|
|
|
<a className="cursor-pointer">Documentation</a>
|
|
|
|
<a className="cursor-pointer">Support</a>
|
2023-12-11 14:35:34 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Sidebar;
|