| 5 | const ConfigContext = createContext() |
| 6 | |
| 7 | export const ConfigProvider = ({ children }) => { |
| 8 | const [config, setConfig] = useState({}) |
| 9 | const [loading, setLoading] = useState(true) |
| 10 | const [isEnterpriseLicensed, setEnterpriseLicensed] = useState(false) |
| 11 | const [isCloud, setCloudLicensed] = useState(false) |
| 12 | const [isOpenSource, setOpenSource] = useState(false) |
| 13 | |
| 14 | useEffect(() => { |
| 15 | const userSettings = platformsettingsApi.getSettings() |
| 16 | Promise.all([userSettings]) |
| 17 | .then(([currentSettingsData]) => { |
| 18 | const finalData = { |
| 19 | ...currentSettingsData.data |
| 20 | } |
| 21 | setConfig(finalData) |
| 22 | if (finalData.PLATFORM_TYPE) { |
| 23 | if (finalData.PLATFORM_TYPE === 'enterprise') { |
| 24 | setEnterpriseLicensed(true) |
| 25 | setCloudLicensed(false) |
| 26 | setOpenSource(false) |
| 27 | } else if (finalData.PLATFORM_TYPE === 'cloud') { |
| 28 | setCloudLicensed(true) |
| 29 | setEnterpriseLicensed(false) |
| 30 | setOpenSource(false) |
| 31 | } else { |
| 32 | setOpenSource(true) |
| 33 | setEnterpriseLicensed(false) |
| 34 | setCloudLicensed(false) |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | setLoading(false) |
| 39 | }) |
| 40 | .catch((error) => { |
| 41 | console.error('Error fetching data:', error) |
| 42 | setLoading(false) |
| 43 | }) |
| 44 | }, []) |
| 45 | |
| 46 | return ( |
| 47 | <ConfigContext.Provider value={{ config, loading, isEnterpriseLicensed, isCloud, isOpenSource }}>{children}</ConfigContext.Provider> |
| 48 | ) |
| 49 | } |
| 50 | |
| 51 | export const useConfig = () => useContext(ConfigContext) |
| 52 | |