snowballtools-base/packages/frontend/src/pages/index.tsx
2024-04-11 21:49:14 -05:00

32 lines
803 B
TypeScript

import { useCallback, useEffect, useState } from 'react';
import { Navigate } from 'react-router-dom';
import { useGQLClient } from '../context/GQLClientContext';
import { Organization } from 'gql-client';
const Index = () => {
const client = useGQLClient();
const [organization, setOrganization] = useState<Organization>();
const fetchUserOrganizations = useCallback(async () => {
const { organizations } = await client.getOrganizations();
// By default information of first organization displayed
setOrganization(organizations[0]);
}, []);
useEffect(() => {
fetchUserOrganizations();
}, []);
return (
<>
{Boolean(organization) ? (
<Navigate to={organization!.slug} />
) : (
<>Loading</>
)}
</>
);
};
export default Index;