Update Formularium
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { Corporate } from '@/@types/corporates';
|
||||
import axios from '@/utils/axios';
|
||||
import { ReactNode, createContext, useState, useEffect } from 'react';
|
||||
import { useParams } from 'react-router';
|
||||
// hooks
|
||||
import useResponsive from '../hooks/useResponsive';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
export type ConfiguredCorporateContextProps = {
|
||||
currentCorporate?: Corporate | null;
|
||||
};
|
||||
|
||||
const initialState: ConfiguredCorporateContextProps = {
|
||||
currentCorporate: null,
|
||||
};
|
||||
|
||||
const ConfiguredCorporateContext = createContext(initialState);
|
||||
|
||||
type ConfiguredCorporateProviderProps = {
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
function ConfiguredCorporateProvider({ children }: ConfiguredCorporateProviderProps) {
|
||||
const { corporate_id } = useParams();
|
||||
const [corporate, setCorporate] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
axios.get(`corporates/${corporate_id}`)
|
||||
.then((res) => {
|
||||
setCorporate(res.data)
|
||||
})
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ConfiguredCorporateContext.Provider
|
||||
value={{
|
||||
currentCorporate: corporate,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</ConfiguredCorporateContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export { ConfiguredCorporateProvider, ConfiguredCorporateContext };
|
||||
Reference in New Issue
Block a user