import { useNavigate } from 'react-router-dom'; import updateUserConfig, { ColourVariants, FileSizeUnits, UserConfigType, } from '../api/actions/updateUserConfig'; import { ColourConstant } from '../configuration/colours/useColours'; import SettingsNavigation from '../components/SettingsNavigation'; import Notifications from '../components/Notifications'; import Button from '../components/Button'; import useIsAdmin from '../functions/useIsAdmin'; import { useUserConfigStore } from '../stores/UserConfigStore'; import { useEffect, useState } from 'react'; import ToggleConfig from '../components/ToggleConfig'; const SettingsUser = () => { const { userConfig, setUserConfig } = useUserConfigStore(); const isAdmin = useIsAdmin(); const navigate = useNavigate(); const [styleSheet, setStyleSheet] = useState(userConfig.stylesheet); const [styleSheetRefresh, setStyleSheetRefresh] = useState(false); const [pageSize, setPageSize] = useState(userConfig.page_size); const [showHelpText, setShowHelpText] = useState(userConfig.show_help_text); const [selectedFileSizeUnit, setSelectedFileSizeUnit] = useState(FileSizeUnits.Binary); useEffect(() => { (async () => { setStyleSheet(userConfig.stylesheet); setPageSize(userConfig.page_size); setShowHelpText(userConfig.show_help_text); setSelectedFileSizeUnit(userConfig.file_size_unit); })(); }, [ userConfig.page_size, userConfig.stylesheet, userConfig.show_help_text, userConfig.file_size_unit, ]); const handleStyleSheetChange = async (selectedStyleSheet: ColourVariants) => { handleUserConfigUpdate({ stylesheet: selectedStyleSheet }); setStyleSheet(selectedStyleSheet); setStyleSheetRefresh(true); }; const handlePageSizeChange = async () => { handleUserConfigUpdate({ page_size: pageSize }); }; const handleShowHelpTextChange = async (configKey: string, configValue: boolean) => { handleUserConfigUpdate({ [configKey]: configValue }); }; const handleFileSizeUnitChange = async (configKey: string, configValue: string) => { handleUserConfigUpdate({ [configKey]: configValue }); }; const handleUserConfigUpdate = async (config: Partial) => { const updatedUserConfig = await updateUserConfig(config); const { data: updatedUserConfigData } = updatedUserConfig; if (updatedUserConfigData) { setUserConfig(updatedUserConfigData); } }; const handlePageRefresh = () => { navigate(0); setStyleSheetRefresh(false); }; return ( <> TA | User Settings

User Configurations

Customize user Interface

Switch your color scheme

{styleSheetRefresh && }

Archive view page size

{ setPageSize(Number(event.target.value)); }} />
{userConfig.page_size !== pageSize && ( <> )}

Show help text

File size units:

{isAdmin && ( <>

User Management

Access the admin interface for basic user management functionality like adding and deleting users, changing passwords and more.

)}
); }; export default SettingsUser;