forked from cerc-io/snowballtools-base
Nabarun Gogoi
413ed03eb8
* Implement dropdown for organizations switcher * Add dynamic route for organization id * Update routes for organization slug * Use organization slug for adding project * Refactor to fetch organizations at sidebar component * Update organization switcher based on searched project * Refactor types in frontend --------- Co-authored-by: neeraj <neeraj.rtly@gmail.com>
32 lines
810 B
TypeScript
32 lines
810 B
TypeScript
import React, { 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;
|