fix(disconnect from map issue): require to be connected to reach /map

This commit is contained in:
Laurian-Dufrechou
2023-05-18 17:31:54 +02:00
parent b1b5c8720c
commit 61df566dcf
4 changed files with 65 additions and 49 deletions
+28 -22
View File
@@ -6,65 +6,71 @@ import {
Button,
Image,
Link,
} from '@chakra-ui/react';
import {useRouter} from 'next/router';
import {signOut, useSession} from 'next-auth/react';
} from "@chakra-ui/react";
import { useRouter } from "next/router";
import { signOut, useSession } from "next-auth/react";
type Props = {
variant: 'static' | 'fixed';
variant: "static" | "fixed";
};
export default function Navbar({variant = 'fixed'}: Props) {
export default function Navbar({ variant = "fixed" }: Props) {
const router = useRouter();
const { data: session, status } = useSession();
const MiddleSection = () => {
const authenticatedLinks = (
<>
<Link href={'/dashboard'}>Tableau de bord</Link>
<Link href={'/profile'}>Profile</Link>
<Link href={'/map'}>Carte</Link>
<Link href={"/dashboard"}>Tableau de bord</Link>
<Link href={"/profile"}>Profile</Link>
<Link href={"/map"}>Carte</Link>
</>
);
return (
<Flex gap={5} justify={'center'} flexBasis={'100%'}>
{status === 'authenticated' && authenticatedLinks}
<Flex gap={5} justify={"center"} flexBasis={"100%"}>
{status === "authenticated" && authenticatedLinks}
</Flex>
);
};
const RightSection = () => {
const authenticatedButtons = (
<Button onClick={() => signOut()}>Déconnexion</Button>
);
const unauthenticatedButtons = (
<>
<Button onClick={() => router.push('/register')}>Inscription</Button>
<Button onClick={() => router.push('/login')}>Connexion</Button>
<Button onClick={() => router.push("/register")}>Inscription</Button>
<Button onClick={() => router.push("/login")}>Connexion</Button>
</>
);
return (
<Flex justify={'right'} flexBasis={'100%'}>
<Flex justify={"right"} flexBasis={"100%"}>
<ButtonGroup>
{status === 'authenticated'
{status === "authenticated"
? authenticatedButtons
: unauthenticatedButtons
}
: unauthenticatedButtons}
</ButtonGroup>
</Flex>
);
};
return (
<Box position={variant} zIndex={9999} top={0} width={'100vw'}
backdropFilter={'auto'} backdropBlur={'20px'} px={10} py={2}>
<Flex align={'center'}>
<Box flexBasis={'100%'}>
<Image src={'/logo.svg'} h={'3rem'} objectFit={'contain'}/>
<Box
position={variant}
zIndex={9999}
top={0}
width={"100vw"}
backdropFilter={"auto"}
backdropBlur={"20px"}
px={10}
py={2}
>
<Flex align={"center"}>
<Box flexBasis={"100%"}>
<Image src={"/logo.svg"} h={"3rem"} objectFit={"contain"} />
</Box>
<MiddleSection />
@@ -5,7 +5,8 @@ import {
FormHelperText,
FormLabel,
UseEditableProps,
} from '@chakra-ui/react';
Link,
} from "@chakra-ui/react";
type CustomEditableProps = {
id: string;
@@ -14,16 +15,25 @@ type CustomEditableProps = {
} & UseEditableProps;
export default function CustomEditable(props: CustomEditableProps) {
const {label, id, helperText = '', ...UseEditableProps} = props;
const { label, id, helperText = "", ...UseEditableProps } = props;
return (
<FormControl>
<FormLabel as="legend" htmlFor={id}>{label}</FormLabel>
<Editable{...UseEditableProps} fontWeight="bold" isDisabled={true}
placeholder={'Non renseigné'} color={'gray.500'}>
<FormLabel as="legend" htmlFor={id}>
{label}
</FormLabel>
<Editable
{...UseEditableProps}
fontWeight="bold"
isDisabled={true}
placeholder={"Non renseigné"}
color={"gray.500"}
>
<EditablePreview />
</Editable>
<Link href={"/map"}>
<FormHelperText>{helperText}</FormHelperText>
</Link>
</FormControl>
);
}
+1 -1
View File
@@ -23,7 +23,7 @@ export default function Map() {
]);
const [geolocationError, setGeolocationError] = useState(false);
const { data: session, status } = useSession();
const { data: session, status } = useSession({ required: true });
const [listBars, setListBars] = useState({} as unknown as any);
const {
+1 -1
View File
@@ -244,7 +244,7 @@ export default function UserProfile() {
}
label={"Adresse :"}
helperText={
"Ce champ est modifié automatiquement depuis la carte"
"Ce champ est automatiquement modifié depuis la carte"
}
/>
</Box>