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';
|
|
|
|
|
|
|
|
import { useGQLClient } from '../context/GQLClientContext';
|
|
|
|
import AsyncSelect from './shared/AsyncSelect';
|
|
|
|
|
|
|
|
const Sidebar = () => {
|
|
|
|
const { orgSlug } = useParams();
|
|
|
|
const navigate = useNavigate();
|
|
|
|
const client = useGQLClient();
|
|
|
|
|
|
|
|
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
|
|
|
|
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>
|
|
|
|
<Typography>Organization</Typography>
|
|
|
|
</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' : '')}
|
|
|
|
>
|
2023-12-21 09:29:33 +00:00
|
|
|
<Typography>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' : '')}
|
|
|
|
>
|
2023-12-21 09:29:33 +00:00
|
|
|
<Typography>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">
|
2023-12-11 14:35:34 +00:00
|
|
|
<div>Documentation</div>
|
|
|
|
<div>Support</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Sidebar;
|