2024-03-08 14:58:36 +01:00
|
|
|
import {
|
|
|
|
Container,
|
|
|
|
Heading,
|
|
|
|
Tab,
|
|
|
|
TabList,
|
|
|
|
TabPanel,
|
|
|
|
TabPanels,
|
|
|
|
Tabs,
|
2024-03-17 17:28:45 +01:00
|
|
|
} from "@chakra-ui/react"
|
2024-04-04 16:30:42 +02:00
|
|
|
import { useQueryClient } from "@tanstack/react-query"
|
2024-04-08 15:49:22 -05:00
|
|
|
import { createFileRoute } from "@tanstack/react-router"
|
2024-03-07 19:16:23 +01:00
|
|
|
|
2024-04-06 18:26:12 -05:00
|
|
|
import type { UserPublic } from "../../client"
|
2024-03-17 17:28:45 +01:00
|
|
|
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 = [
|
2024-03-17 17:28:45 +01:00
|
|
|
{ title: "My profile", component: UserInformation },
|
|
|
|
{ title: "Password", component: ChangePassword },
|
|
|
|
{ title: "Appearance", component: Appearance },
|
|
|
|
{ title: "Danger zone", component: DeleteAccount },
|
2024-03-08 14:58:36 +01:00
|
|
|
]
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-17 17:28:45 +01:00
|
|
|
export const Route = createFileRoute("/_layout/settings")({
|
2024-03-08 14:58:36 +01:00
|
|
|
component: UserSettings,
|
2024-03-07 19:16:23 +01:00
|
|
|
})
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-07 19:16:23 +01:00
|
|
|
function UserSettings() {
|
2024-03-08 14:58:36 +01:00
|
|
|
const queryClient = useQueryClient()
|
2024-04-06 18:26:12 -05:00
|
|
|
const currentUser = queryClient.getQueryData<UserPublic>(["currentUser"])
|
2024-03-08 14:58:36 +01:00
|
|
|
const finalTabs = currentUser?.is_superuser
|
|
|
|
? tabsConfig.slice(0, 3)
|
|
|
|
: tabsConfig
|
2024-02-12 16:46:51 -05:00
|
|
|
|
2024-03-08 14:58:36 +01:00
|
|
|
return (
|
|
|
|
<Container maxW="full">
|
2024-03-17 17:28:45 +01:00
|
|
|
<Heading size="lg" textAlign={{ base: "center", md: "left" }} py={12}>
|
2024-03-08 14:58:36 +01:00
|
|
|
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 />
|
|
|
|
</TabPanel>
|
|
|
|
))}
|
|
|
|
</TabPanels>
|
|
|
|
</Tabs>
|
|
|
|
</Container>
|
|
|
|
)
|
2024-03-07 19:16:23 +01:00
|
|
|
}
|