snowballtools-base/packages/frontend/src/pages/index.tsx
Nabarun Gogoi 413ed03eb8
Implement organization switcher and use slug in URL (#59)
* 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>
2024-02-07 18:41:54 +05:30

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;