Add an initial organisation flow

This commit is contained in:
Ana Custura 2026-06-11 09:53:30 +01:00
parent 3bd1a5007a
commit ac733af3b5
12 changed files with 432 additions and 99 deletions

View file

@ -5,19 +5,20 @@ import React, {useState} from 'react';
import {
SettingOutlined,
UserOutlined,
DeploymentUnitOutlined,
} from '@ant-design/icons';
import {Breadcrumb, type MenuProps} from 'antd';
import { Layout, Menu, theme } from 'antd';
import Home from "./Home.tsx";
import {Route, Routes, useLocation, useNavigate} from "react-router";
import Profile from "./Profile.tsx";
import {type UserContextType} from './UserContext.tsx';
import {UserContext} from './UserContext.tsx';
import type {userObject} from "./UserContext.tsx";
import {type UserContextType} from './hooks/UserContext.ts';
import {UserContext} from './hooks/UserContext.ts';
import type {userObject} from "./hooks/UserContext.ts";
import {type OrgContextType} from './OrgContext.tsx';
import {OrgContext} from './OrgContext.tsx';
import type {orgObject} from "./OrgContext.tsx";
import Organisations from "./Organisations.tsx";
import {RefreshContext} from "./hooks/RefreshContext.ts";
import Bridges from "./Bridges.tsx";
const { Header, Content, Sider } = Layout;
@ -66,28 +67,16 @@ const App: React.FC = () => {
first_name: "",
last_name: "",
email: "",
organisations: []
organisations: [],
id: -1
},
setCurrentUser: () => {}
}
const defaultOrg: OrgContextType = {
currentOrg: {
billing_contact: "",
owner_contact: "",
name: "",
status: "",
root_user: "",
security_contact: "",
},
setCurrentOrg: () => {}
}
const [currentUser, setCurrentUser] = useState<userObject>(defaultUser.currentUser);
const [currentOrg, setCurrentOrg] = useState<orgObject>(defaultOrg.currentOrg);
const [refreshKey, setRefreshKey] = useState<number>(1);
// STRILL NEEDS SOMETHING TO get CURRENT USER ORGS and map first one to a CURRENT ORG fetched from the API
// STILL NEEDS THE WRAPPER IN THE RETURN STATEMETNS
/*****************************
GETTING CURRENT USER FROM API
*****************************/
@ -108,7 +97,7 @@ const App: React.FC = () => {
console.error(e);
}
})();
}, [auth]);
}, [auth, refreshKey]);
if (!currentUser) {
@ -142,8 +131,14 @@ const App: React.FC = () => {
case 'profile':
navigate('/profile');
break;
case 'orgs':
navigate('/organisations');
break;
case 'logout':
auth.removeUser().then(r => navigate('/profile'));
auth.removeUser().then(() => navigate('/profile'));
break;
case 'bridges':
navigate('/bridges');
break;
default:
console.log('Clicked item:', e.key);
@ -151,19 +146,26 @@ const App: React.FC = () => {
};
//const organisations: [] = current_user.organisations;
const side_nav_items: MenuItem[] = currentUser.organisations && [
getItem('Files', '9', <SettingOutlined />),
];
let side_nav_items: MenuItem[] = []
const top_nav_items = [
getItem(currentUser.first_name + " " +currentUser.last_name , 'account', <UserOutlined />, [getItem('Account details', 'profile'), getItem('Log out', 'logout')]),
getItem("Organisation Settings", 'orgsettings', <SettingOutlined />),
];
if (currentUser.organisations.length > 0) {
side_nav_items = [ getItem('My organisations', 'orgs', <SettingOutlined />),
getItem('Bridges', 'bridges', <DeploymentUnitOutlined />), ];
const currentOrg = currentUser.organisations[0]['name']
top_nav_items.push(getItem(currentOrg +" Settings", 'orgsettings', <SettingOutlined />));
}
return (
<UserContext.Provider value={{ currentUser, setCurrentUser }}>
<Layout>
<RefreshContext.Provider value={{ refreshKey, setRefreshKey }}>
<Layout>
<Header style={{ display: 'flex', alignItems: 'right' }}>
<div className="demo-logo" >
<h1>SR22</h1>
@ -206,12 +208,15 @@ const App: React.FC = () => {
<Routes>
<Route path="/" element={<Home/>}/>
{currentUser && <Route path="/profile" element={<Profile/>}/> }
{currentUser && <Route path="/organisations" element={<Organisations/>}/> }
{currentUser && <Route path="/bridges" element={<Bridges/>}/> }
</Routes>
</Content>
</Layout>
</Layout>
</Layout>
</RefreshContext.Provider>
</UserContext.Provider>
);