Files
full-stack-fastapi-template/frontend/src/routes/_layout/settings.tsx

59 lines
1.6 KiB
TypeScript
Raw Normal View History

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"
import { useQueryClient } from "@tanstack/react-query"
2024-04-08 15:49:22 -05:00
import { createFileRoute } from "@tanstack/react-router"
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"
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-03-17 17:28:45 +01:00
export const Route = createFileRoute("/_layout/settings")({
2024-03-08 14:58:36 +01:00
component: UserSettings,
})
function UserSettings() {
2024-03-08 14:58:36 +01:00
const queryClient = useQueryClient()
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-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>
)
}