Commit 62d8d125 by G

add a button in the profile screen to logout the user. currently he's not being…

add a button in the profile screen to logout the user. currently he's not being returned to the authentication screen
parent 424d1dc3
import type { IuserInformations } from "@/utils/requests/types"; import type { IuserInformations } from "@/utils/requests/types";
import { createContext, useContext, useState } from "react"; import { createContext, useCallback, useContext, useState } from "react";
import type { IauthenticationData } from "./Types"; import type { IauthenticationData } from "./Types";
export interface UserAuthenticationContextProps { export interface UserAuthenticationContextProps {
isAuthenticated: boolean; isAuthenticated: boolean;
...@@ -7,6 +7,7 @@ export interface UserAuthenticationContextProps { ...@@ -7,6 +7,7 @@ export interface UserAuthenticationContextProps {
setAuthenticationData: React.Dispatch<React.SetStateAction<IauthenticationData>>; setAuthenticationData: React.Dispatch<React.SetStateAction<IauthenticationData>>;
userInformations: IuserInformations; userInformations: IuserInformations;
setUserInformations: React.Dispatch<React.SetStateAction<IuserInformations>>; setUserInformations: React.Dispatch<React.SetStateAction<IuserInformations>>;
logout: () => void;
} }
export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({ export const UserAuthenticationContext = createContext<UserAuthenticationContextProps>({
...@@ -35,6 +36,7 @@ export const UserAuthenticationContext = createContext<UserAuthenticationContext ...@@ -35,6 +36,7 @@ export const UserAuthenticationContext = createContext<UserAuthenticationContext
}, },
}, },
setUserInformations: () => {}, setUserInformations: () => {},
logout: () => {},
}); });
export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => { export const UserAuthenticationContextProvider = ({ children }: { children: React.ReactNode }) => {
...@@ -65,6 +67,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -65,6 +67,35 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
}, },
}); });
const logout = useCallback(() => {
setIsAuthenticated(false);
setAuthenticationData({
access: "",
refresh: "",
});
setUserInformations({
username: "",
email: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
first_name: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
last_name: "",
marchand: {
// biome-ignore lint/style/useNamingConvention: <explanation>
marchand_id: "",
nom: "",
code: "",
adresse: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_succes: "",
// biome-ignore lint/style/useNamingConvention: <explanation>
url_echec: "",
entreprise: 0,
user: 0,
},
});
}, []);
return ( return (
<UserAuthenticationContext.Provider <UserAuthenticationContext.Provider
value={{ value={{
...@@ -73,6 +104,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac ...@@ -73,6 +104,7 @@ export const UserAuthenticationContextProvider = ({ children }: { children: Reac
setAuthenticationData, setAuthenticationData,
userInformations, userInformations,
setUserInformations, setUserInformations,
logout,
}} }}
> >
{children} {children}
......
...@@ -3,6 +3,7 @@ import {} from "react"; ...@@ -3,6 +3,7 @@ import {} from "react";
import {} from "react-native"; import {} from "react-native";
import { useUserAuthenticationContext } from "@/contexts/UserAuthenticationContext"; import { useUserAuthenticationContext } from "@/contexts/UserAuthenticationContext";
import Button from "@components/Button";
import BackgroundWithBeasyIconAndWhiteContentArea from "@components/backgrounds/BackgroundWithBeasyIconAndWhiteContentArea"; import BackgroundWithBeasyIconAndWhiteContentArea from "@components/backgrounds/BackgroundWithBeasyIconAndWhiteContentArea";
import Text from "@components/bases/Text"; import Text from "@components/bases/Text";
import { LOG } from "@logger"; import { LOG } from "@logger";
...@@ -11,6 +12,8 @@ const log = LOG.extend("UserProfileScreen"); ...@@ -11,6 +12,8 @@ const log = LOG.extend("UserProfileScreen");
const UserProfileScreen = () => { const UserProfileScreen = () => {
log.verbose("UserProfileScreen"); log.verbose("UserProfileScreen");
const { logout } = useUserAuthenticationContext();
const { userInformations } = useUserAuthenticationContext(); const { userInformations } = useUserAuthenticationContext();
return ( return (
...@@ -63,6 +66,13 @@ const UserProfileScreen = () => { ...@@ -63,6 +66,13 @@ const UserProfileScreen = () => {
</Box> </Box>
</Box> </Box>
<Button
label={"Deconnexion"}
onPress={logout}
variant={"danger"}
textVariants={"white"}
/>
<Text fontWeight={"bold"}>Informations sur le marchand</Text> <Text fontWeight={"bold"}>Informations sur le marchand</Text>
<Box <Box
width={"100%"} width={"100%"}
......
...@@ -143,6 +143,9 @@ const theme = createTheme({ ...@@ -143,6 +143,9 @@ const theme = createTheme({
backgroundColor: "secondary", backgroundColor: "secondary",
color: "white", color: "white",
}, },
danger: {
backgroundColor: "softRed",
},
fullError: { fullError: {
backgroundColor: "softRed", backgroundColor: "softRed",
color: "white", color: "white",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment