Add org context, and page to submit a new organisation if none exist for a user

This commit is contained in:
Ana Custura 2026-06-02 15:40:46 +01:00
parent 2a399fc397
commit 3bd1a5007a
5 changed files with 151 additions and 10 deletions

View file

@ -9,12 +9,16 @@ import {
import {Breadcrumb, type MenuProps} from 'antd';
import { Layout, Menu, theme } from 'antd';
import Home from "./Home.tsx";
import { Route, Routes, useNavigate} from "react-router";
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 OrgContextType} from './OrgContext.tsx';
import {OrgContext} from './OrgContext.tsx';
import type {orgObject} from "./OrgContext.tsx";
const { Header, Content, Sider } = Layout;
type MenuItem = Required<MenuProps>['items'][number];
@ -37,6 +41,7 @@ function getItem(
const App: React.FC = () => {
const navigate = useNavigate();
const location = useLocation();
const {
token: {colorBgContainer, borderRadiusLG},
} = theme.useToken();
@ -66,7 +71,23 @@ const App: React.FC = () => {
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);
// 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
*****************************/
@ -76,7 +97,6 @@ const App: React.FC = () => {
(async () => {
if (!auth.user) { return }
try {
console.log(auth.user);
const token = auth.user.access_token;
const response = await fetch("/api/v1/user/self/db", {
headers: {
@ -90,8 +110,6 @@ const App: React.FC = () => {
})();
}, [auth]);
// const [current_orgs, set_current_orgs] = useState<Organisation | null>(null);
if (!currentUser) {
return(
@ -121,7 +139,7 @@ const App: React.FC = () => {
const onClick: MenuProps['onClick'] = (e) => {
switch (e.key) {
case 'account':
case 'profile':
navigate('/profile');
break;
case 'logout':
@ -140,7 +158,7 @@ const App: React.FC = () => {
];
const top_nav_items = [
getItem(currentUser.first_name + " " +currentUser.last_name , 'account1', <UserOutlined />, [getItem('Account details', 'account'), getItem('Log out', 'logout')]),
getItem(currentUser.first_name + " " +currentUser.last_name , 'account', <UserOutlined />, [getItem('Account details', 'profile'), getItem('Log out', 'logout')]),
getItem("Organisation Settings", 'orgsettings', <SettingOutlined />),
];
return (
@ -172,7 +190,7 @@ const App: React.FC = () => {
</Sider>
<Layout style={{ padding: '0 24px 24px' }}>
<Breadcrumb
items={[{ title: 'Home' }, { title: 'List' }, { title: 'App' }]}
items={[{ title: 'Home' }, { title: location.pathname.substring(1) }]}
style={{ margin: '16px 0' }}
/>
<Content
@ -187,7 +205,7 @@ const App: React.FC = () => {
<Routes>
<Route path="/" element={<Home/>}/>
{currentUser && <Route path="/account" element={<Profile/>}/> }
{currentUser && <Route path="/profile" element={<Profile/>}/> }
</Routes>
</Content>