import { Group, Stack, Text, Title, useMantineTheme } from '@mantine/core'; import { Dropzone } from '@mantine/dropzone'; import { showNotification } from '@mantine/notifications'; import { IconCheck as Check, IconPhoto, IconUpload, IconX, IconX as X } from '@tabler/icons-react'; import { setCookie } from 'cookies-next'; import { useTranslation } from 'next-i18next'; import { useConfigStore } from '../../config/store'; import { ConfigType } from '../../types/config'; export const LoadConfigComponent = () => { const { addConfig } = useConfigStore(); const theme = useMantineTheme(); const { t } = useTranslation('settings/general/config-changer'); return ( { const fileName = files[0].name.replaceAll('.json', ''); const fileText = await files[0].text(); try { JSON.parse(fileText) as ConfigType; } catch (e) { showNotification({ autoClose: 5000, title: {t('dropzone.notifications.invalidConfig.title')}, color: 'red', icon: , message: t('dropzone.notifications.invalidConfig.message'), }); return; } const newConfig: ConfigType = JSON.parse(fileText); await addConfig(fileName, newConfig, true); showNotification({ autoClose: 5000, radius: 'md', title: ( {t('dropzone.notifications.loadedSuccessfully.title', { configName: fileName, })} ), color: 'green', icon: , message: undefined, }); setCookie('config-name', fileName, { maxAge: 60 * 60 * 24 * 30, sameSite: 'strict', }); }} accept={['application/json']} > {t('dropzone.accept.title')} {t('dropzone.accept.text')} {t('dropzone.reject.title')} {t('dropzone.reject.text')} ); };