2024-02-12 16:46:51 -05:00
|
|
|
import { Container, Heading, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react';
|
2024-03-07 19:16:23 +01:00
|
|
|
import { createFileRoute } from '@tanstack/react-router';
|
|
|
|
import { useQueryClient } from 'react-query';
|
|
|
|
|
|
|
|
import { UserOut } from '../../client';
|
|
|
|
import Appearance from '../../components/UserSettings/Appearance';
|
|
|
|
import ChangePassword from '../../components/UserSettings/ChangePassword';
|
|
|
|
import DeleteAccount from '../../components/UserSettings/DeleteAccount';
|
|
|
|
import UserInformation from '../../components/UserSettings/UserInformation';
|
2024-02-26 09:39:09 -05:00
|
|
|
|
|
|
|
const tabsConfig = [
|
|
|
|
{ title: 'My profile', component: UserInformation },
|
|
|
|
{ title: 'Password', component: ChangePassword },
|
|
|
|
{ title: 'Appearance', component: Appearance },
|
|
|
|
{ title: 'Danger zone', component: DeleteAccount },
|
|
|
|
];
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-07 19:16:23 +01:00
|
|
|
export const Route = createFileRoute('/_layout/settings')({
|
|
|
|
component: UserSettings,
|
|
|
|
})
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-07 19:16:23 +01:00
|
|
|
function UserSettings() {
|
|
|
|
const queryClient = useQueryClient();
|
|
|
|
const currentUser = queryClient.getQueryData<UserOut>('currentUser');
|
|
|
|
const finalTabs = currentUser?.is_superuser ? tabsConfig.slice(0, 3) : tabsConfig;
|
2024-02-12 16:46:51 -05:00
|
|
|
|
|
|
|
return (
|
2024-02-26 09:39:09 -05:00
|
|
|
<Container maxW='full'>
|
|
|
|
<Heading size='lg' textAlign={{ base: 'center', md: 'left' }} py={12}>
|
|
|
|
User Settings
|
|
|
|
</Heading>
|
|
|
|
<Tabs variant='enclosed'>
|
|
|
|
<TabList>
|
|
|
|
{finalTabs.map((tab, index) => (
|
|
|
|
<Tab key={index}>{tab.title}</Tab>
|
|
|
|
))}
|
|
|
|
</TabList>
|
|
|
|
<TabPanels>
|
|
|
|
{finalTabs.map((tab, index) => (
|
|
|
|
<TabPanel key={index}>
|
|
|
|
<tab.component />
|
2024-02-12 16:46:51 -05:00
|
|
|
</TabPanel>
|
2024-02-26 09:39:09 -05:00
|
|
|
))}
|
|
|
|
</TabPanels>
|
|
|
|
</Tabs>
|
|
|
|
</Container>
|
2024-02-12 16:46:51 -05:00
|
|
|
);
|
2024-03-07 19:16:23 +01:00
|
|
|
}
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-02-26 09:39:09 -05:00
|
|
|
export default UserSettings;
|