add Corporate Context Provider
This commit is contained in:
19
frontend/dashboard/src/pages/Corporates/ConfigLayout.tsx
Normal file
19
frontend/dashboard/src/pages/Corporates/ConfigLayout.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Outlet } from 'react-router-dom';
|
||||
// @mui
|
||||
import { Stack } from '@mui/material';
|
||||
import { ConfiguredCorporateProvider } from '@/contexts/ConfiguredCorporateContext';
|
||||
|
||||
export default function ConfigLayout() {
|
||||
return (
|
||||
<Stack
|
||||
sx={{
|
||||
display: { lg: 'flex' },
|
||||
minHeight: { lg: 1 },
|
||||
}}
|
||||
>
|
||||
<ConfiguredCorporateProvider>
|
||||
<Outlet />
|
||||
</ConfiguredCorporateProvider>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export default function CorporateTabNavigations({ position }: Props) {
|
||||
allowScrollButtonsMobile
|
||||
aria-label="scrollable force tabs example"
|
||||
>
|
||||
{mainTabItems.map((tabItem, index) => (<Tab key={index} onClick={() => { navigate("/corporates/"+corporate_id+"/"+mainTabItems[index].path) }}label={tabItem.label}/>))}
|
||||
{mainTabItems.map((tabItem, index) => (<Tab key={index} onClick={() => { navigate("/corporate/"+corporate_id+"/"+mainTabItems[index].path) }}label={tabItem.label}/>))}
|
||||
</Tabs>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Corporate } from "@/@types/corporates";
|
||||
import { ConfiguredCorporateContext } from "@/contexts/ConfiguredCorporateContext";
|
||||
import { Card, Grid } from "@mui/material";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { useParams } from "react-router-dom";
|
||||
import HeaderBreadcrumbs from "../../../components/HeaderBreadcrumbs";
|
||||
import Page from "../../../components/Page";
|
||||
@@ -12,6 +15,14 @@ export default function Divisions() {
|
||||
const { themeStretch } = useSettings();
|
||||
|
||||
const { corporate_id } = useParams();
|
||||
|
||||
const [corporate, setCorporate] = useState<Corporate|null>();
|
||||
|
||||
const configuredCorporateContext = useContext(ConfiguredCorporateContext);
|
||||
|
||||
useEffect(() => {
|
||||
setCorporate(configuredCorporateContext.currentCorporate);
|
||||
}, [configuredCorporateContext])
|
||||
|
||||
return (
|
||||
<Page title="Division">
|
||||
@@ -24,7 +35,7 @@ export default function Divisions() {
|
||||
href: '/corporates',
|
||||
},
|
||||
{
|
||||
name: 'Corporate Name',
|
||||
name: corporate?.name ?? '-',
|
||||
href: '/corporates/'+corporate_id,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -333,7 +333,7 @@ export default function Corporates() {
|
||||
Edit
|
||||
</Button>
|
||||
</Link>
|
||||
<Link to={'/corporates/' + row.id + ''}>
|
||||
<Link to={'/corporate/' + row.id + ''}>
|
||||
<Button variant="outlined" color="primary" size="small">
|
||||
Config
|
||||
</Button>
|
||||
|
||||
@@ -11,26 +11,25 @@ import Page from '../../components/Page';
|
||||
import axios from '../../utils/axios';
|
||||
import useAuth from '../../hooks/useAuth';
|
||||
import { Link , NavLink as RouterLink, useParams } from 'react-router-dom';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import React, { useContext, useEffect, useRef, useState } from 'react';
|
||||
import { Theme, useTheme } from '@mui/material/styles';
|
||||
import { Corporate } from '../../@types/corporates';
|
||||
import { LaravelPaginatedData, LaravelPaginatedDataDefault } from '../../@types/paginated-data';
|
||||
import HeaderBreadcrumbs from '../../components/HeaderBreadcrumbs';
|
||||
import CorporateTabNavigations from './CorporateTabNavigations';
|
||||
import { fCurrency } from '../../utils/formatNumber';
|
||||
import { ConfiguredCorporateContext } from '@/contexts/ConfiguredCorporateContext';
|
||||
|
||||
export default function Corporates() {
|
||||
const { themeStretch } = useSettings();
|
||||
const { corporate_id } = useParams();
|
||||
const [corporate, setCorporate] = useState<Corporate>();
|
||||
const [corporate, setCorporate] = useState<Corporate|null>();
|
||||
|
||||
const configuredCorporateContext = useContext(ConfiguredCorporateContext);
|
||||
|
||||
useEffect(() => {
|
||||
// TODO Use Hooks
|
||||
axios.get(`corporates/${corporate_id}`)
|
||||
.then((res) => {
|
||||
setCorporate(res.data)
|
||||
})
|
||||
}, [])
|
||||
setCorporate(configuredCorporateContext.currentCorporate);
|
||||
}, [configuredCorporateContext])
|
||||
|
||||
const headStyle = {
|
||||
fontWeight: 'bold',
|
||||
@@ -51,8 +50,7 @@ export default function Corporates() {
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
|
||||
|
||||
{/* <Container maxWidth={themeStretch ? false : 'xl'}> */}
|
||||
<Card>
|
||||
<Stack spacing="3">
|
||||
|
||||
Reference in New Issue
Block a user