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-26 22:45:04 +00:00
|
|
|
import { 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';
|
2024-02-26 23:35:45 +00:00
|
|
|
import {
|
|
|
|
ChevronGrabberHorizontal,
|
|
|
|
FolderIcon,
|
|
|
|
GlobeIcon,
|
|
|
|
LifeBuoyIcon,
|
|
|
|
QuestionMarkRoundIcon,
|
|
|
|
SettingsSlidersIcon,
|
|
|
|
} from './shared/CustomIcon';
|
2024-02-26 22:45:04 +00:00
|
|
|
import { Tabs } from 'components/shared/Tabs';
|
2024-02-07 13:11:54 +00:00
|
|
|
|
|
|
|
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 (
|
2024-02-27 03:24:15 +00:00
|
|
|
<div className="flex flex-col h-full p-4 pt-10">
|
2023-12-12 12:24:20 +00:00
|
|
|
<div className="grow">
|
2024-02-26 22:45:04 +00:00
|
|
|
<Link to={`/${orgSlug}`}>
|
|
|
|
<div className="flex items-center space-x-3 mb-10 ml-2">
|
|
|
|
<img
|
|
|
|
src="/logo.svg"
|
|
|
|
alt="Snowball Logo"
|
|
|
|
className="h-8 w-8 rounded-lg"
|
|
|
|
/>
|
|
|
|
<span className="text-2xl font-bold text-snowball-900">
|
|
|
|
Snowball
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</Link>
|
2024-02-07 13:11:54 +00:00
|
|
|
<AsyncSelect
|
2024-02-27 03:46:42 +00:00
|
|
|
containerProps={{ className: 'h-14 border-none' }}
|
|
|
|
labelProps={{ className: 'before:border-none after:border-none' }}
|
|
|
|
className="bg-white rounded-lg shadow border-none"
|
2024-02-07 13:11:54 +00:00
|
|
|
value={selectedOrgSlug}
|
|
|
|
onChange={(value) => {
|
|
|
|
setSelectedOrgSlug(value!);
|
|
|
|
navigate(`/${value}`);
|
|
|
|
}}
|
|
|
|
selected={(_, index) => (
|
2024-02-26 22:45:04 +00:00
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
<img
|
|
|
|
src="/logo.svg"
|
|
|
|
alt="Application Logo"
|
|
|
|
className="h-8 w-8 rounded-lg"
|
|
|
|
/>
|
2024-02-07 13:11:54 +00:00
|
|
|
<div>
|
2024-02-26 22:45:04 +00:00
|
|
|
<div className="text-sm font-semibold">
|
|
|
|
{organizations[index!]?.name}
|
|
|
|
</div>
|
|
|
|
<div className="text-xs text-gray-500">Organization</div>
|
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
|
|
|
)}
|
2024-02-26 22:45:04 +00:00
|
|
|
arrow={<ChevronGrabberHorizontal className="h-4 w-4 text-gray-500" />}
|
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}>
|
2024-02-26 22:45:04 +00:00
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
<img
|
|
|
|
src="/logo.svg"
|
|
|
|
alt="Application Logo"
|
|
|
|
className="h-8 w-8 rounded-lg"
|
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<div className="text-sm font-semibold">{org.name}</div>
|
|
|
|
<div className="text-xs text-gray-500">Organization</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-07 13:11:54 +00:00
|
|
|
</Option>
|
|
|
|
))}
|
|
|
|
</AsyncSelect>
|
2024-02-26 23:35:45 +00:00
|
|
|
<Tabs defaultValue="Projects" orientation="vertical" className="mt-10">
|
2024-02-26 22:45:04 +00:00
|
|
|
<Tabs.List>
|
2024-02-26 23:35:45 +00:00
|
|
|
{[
|
|
|
|
{ title: 'Projects', icon: <FolderIcon /> },
|
|
|
|
{ title: 'Settings', icon: <SettingsSlidersIcon /> },
|
|
|
|
].map(({ title, icon }, index) => (
|
2024-02-26 22:45:04 +00:00
|
|
|
<NavLink to={`/${orgSlug}/${title}`} key={index}>
|
2024-02-26 23:35:45 +00:00
|
|
|
<Tabs.Trigger icon={icon} value={title}>
|
2024-02-26 22:45:04 +00:00
|
|
|
{title}
|
|
|
|
</Tabs.Trigger>
|
|
|
|
</NavLink>
|
|
|
|
))}
|
|
|
|
</Tabs.List>
|
|
|
|
</Tabs>
|
2023-12-11 14:35:34 +00:00
|
|
|
</div>
|
2024-02-26 23:35:45 +00:00
|
|
|
<div className="grow flex flex-col justify-end mb-8">
|
2024-02-26 22:45:04 +00:00
|
|
|
<Tabs defaultValue="Projects" orientation="vertical">
|
|
|
|
{/* TODO: use proper link buttons */}
|
|
|
|
<Tabs.List>
|
|
|
|
<Tabs.Trigger icon={<GlobeIcon />} value="">
|
|
|
|
<a className="cursor-pointer" onClick={handleLogOut}>
|
|
|
|
Log Out
|
|
|
|
</a>
|
|
|
|
</Tabs.Trigger>
|
2024-02-26 23:35:45 +00:00
|
|
|
<Tabs.Trigger icon={<QuestionMarkRoundIcon />} value="">
|
2024-02-26 22:45:04 +00:00
|
|
|
<a className="cursor-pointer">Documentation</a>
|
|
|
|
</Tabs.Trigger>
|
2024-02-26 23:35:45 +00:00
|
|
|
<Tabs.Trigger icon={<LifeBuoyIcon />} value="">
|
2024-02-26 22:45:04 +00:00
|
|
|
<a className="cursor-pointer">Support</a>
|
|
|
|
</Tabs.Trigger>
|
|
|
|
</Tabs.List>
|
|
|
|
</Tabs>
|
2023-12-11 14:35:34 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Sidebar;
|