Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

feat(web): validate if primary color and shade are available in mantine #737

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions web/src/providers/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context, createContext, useContext, useEffect, useState } from 'react';
import { MantineColor } from '@mantine/core';
import { MantineColor, DEFAULT_THEME } from '@mantine/core';
import { fetchNui } from '../utils/fetchNui';

interface Config {
Expand All @@ -12,6 +12,7 @@ interface ConfigCtxValue {
setConfig: (config: Config) => void;
}

const availableTheme = DEFAULT_THEME.colors;
const ConfigCtx = createContext<{ config: Config; setConfig: (config: Config) => void } | null>(null);

const ConfigProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
Expand All @@ -21,7 +22,9 @@ const ConfigProvider: React.FC<{ children: React.ReactNode }> = ({ children }) =
});

useEffect(() => {
fetchNui<Config>('getConfig').then((data) => setConfig(data));
fetchNui<Config>('getConfig').then((data) => {
if (availableTheme[data.primaryColor][data.primaryShade]) setConfig(data);
});
}, []);

return <ConfigCtx.Provider value={{ config, setConfig }}>{children}</ConfigCtx.Provider>;
Expand Down