import { useState } from "react"; import { Link, Redirect, useParams } from "react-router-dom"; import Nav from "../../sections/Nav"; import { useAuth } from "../../useAuth"; import { useAuthenticatedRequest, authenticatedEndpoint, RoundedPicture, } from "../../util"; import { BoxSeam } from "react-bootstrap-icons"; import ErrorPage from "../ErrorPage"; import Members from "./Members"; import ReactPlaceholder from "react-placeholder"; interface OrganisationDetails { possible_permissions?: string[]; crates: Crate[]; members: Member[]; description: string; } interface Crate { name: string; description?: string; } interface Member { uuid: string; display_name: string; permissions: string[]; } interface UrlParams { organisation: string; } export default function ShowOrganisation() { const tabs = { crates: "Crates", members: "Members", }; const { organisation } = useParams(); const auth = useAuth(); const [activeTab, setActiveTab] = useState(Object.keys(tabs)[0]); if (!auth) { return ; } const [reload, setReload] = useState(0); const { response: organisationDetails, error } = useAuthenticatedRequest( { auth, endpoint: `organisations/${organisation}`, }, [reload] ); if (error) { return ; } const ready = !!organisationDetails; return (
); } function ListCrates({ organisation, crates, }: { organisation: string; crates: Crate[]; }) { if (crates.length === 0) { return (
This organisation doesn't have any crates yet.
); } return (
{crates.map((v, i) => ( ))}
{organisation}/ {v.name}
{v.description}
); } interface ListMemberParams { organisation: string; members: Member[]; possiblePermissions?: string[]; reload: () => any; } function ListMembers({ organisation, members, possiblePermissions, reload, }: ListMemberParams) { const auth = useAuth(); if (!auth) { return <>; } const saveMemberPermissions = async ( prospectiveMember: boolean, uuid: string, selectedPermissions: string[] ) => { let res = await fetch( authenticatedEndpoint(auth, `organisations/${organisation}/members`), { method: prospectiveMember ? "PUT" : "PATCH", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ user_uuid: uuid, permissions: selectedPermissions, }), } ); let json = await res.json(); if (json.error) { throw new Error(json.error); } reload(); }; const deleteMember = async (uuid: string) => { let res = await fetch( authenticatedEndpoint(auth, `organisations/${organisation}/members`), { method: "DELETE", headers: { Accept: "application/json", "Content-Type": "application/json", }, body: JSON.stringify({ user_uuid: uuid, }), } ); let json = await res.json(); if (json.error) { throw new Error(json.error); } reload(); }; return ( ); }