From a4455f7450b0653f36b696208e4677d9e04b44c2 Mon Sep 17 00:00:00 2001 From: Peter Hoppe Date: Fri, 24 Feb 2023 15:14:06 +0100 Subject: [PATCH] navbar --- src/App.tsx | 45 +++++++++++++++++++++++------------- src/components/DogNavbar.tsx | 41 +++++++++++++++++++++----------- src/components/Profil.tsx | 5 ++++ src/services/PhpApi.ts | 4 ++-- 4 files changed, 64 insertions(+), 31 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6fef147..9d7ad9b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import './App.css'; import { BrowserRouter, Routes, Route } from 'react-router-dom'; import Login from './components/Login'; @@ -12,7 +12,7 @@ import "bootstrap/dist/css/bootstrap.min.css"; import FileUpload from './components/FileUpload'; import Profil from './components/Profil'; import useSWR from 'swr'; -import {getUser} from './services/PhpApi' +import {getUser, logOut} from './services/PhpApi' import { TUser } from './context/UserContext'; import PasswordReset from './components/PasswordReset'; import WantNewPw from './components/WantNewPw'; @@ -21,21 +21,33 @@ import MantineProvider, AppShell, Navbar, - Header, + Text, Aside, Footer } from '@mantine/core'; import { NotificationsProvider } from '@mantine/notifications'; -import { notificationError } from './services/Notifications'; +import { notificationAlert, notificationError, notificationSuccess } from './services/Notifications'; import DogNavbar from './components/DogNavbar'; const App: React.FC = () => { - const {data, error, isLoading} = useSWR("/user", getUser); + const {data, error, isLoading, mutate} = useSWR("/user", getUser); console.log('App getUser'); console.log(data); + + async function userLogout() + { + await logOut(); + mutate(); + notificationSuccess('Abgemeldet!'); + console.log('userLogout'); + + window.location.href = '/dog/'; + } + + if (error) { notificationError(error.message); @@ -47,26 +59,29 @@ const App: React.FC = () => if (isLoading) return (
loading...
); let user: TUser | null; + let hasUser: boolean; if(data.success) { user = data.data; + hasUser = true; } else { user = null; + hasUser = false; } return ( - - } - > +
-
+ } + > {user && } />} {/* {user && } />} */} @@ -82,12 +97,10 @@ const App: React.FC = () => {user && } />} {user && } />} +
- -
-
-
+
); } diff --git a/src/components/DogNavbar.tsx b/src/components/DogNavbar.tsx index aa2b063..ae8c778 100644 --- a/src/components/DogNavbar.tsx +++ b/src/components/DogNavbar.tsx @@ -1,25 +1,40 @@ -import { Navbar, Text } from '@mantine/core' -import React from 'react' +import { Button, Navbar, Text } from '@mantine/core' +import React, { useState } from 'react' +import { Link } from 'react-router-dom' +import { logOut } from '../services/PhpApi' import Footer2 from './Footer2' -function DogNavbar({hasUser}:{hasUser: boolean}) +function DogNavbar({hasUser, onLogout}:{hasUser: boolean, onLogout: () => void}) { return ( ) } diff --git a/src/components/Profil.tsx b/src/components/Profil.tsx index b0947a8..cd431e2 100644 --- a/src/components/Profil.tsx +++ b/src/components/Profil.tsx @@ -33,6 +33,10 @@ function Profil() const edit = useRef(false); const formDataSave = useRef(formData); // just to fill it // data ist dogdata, logindata holt sich getProfilData.php aus $_SESSION + + const WWW_ROOT: string = process.env.REACT_APP_WWW_ROOT!; + + if (error) return (
failed to load
); if (isLoading) return (
loading...
); @@ -177,6 +181,7 @@ function Profil() Bild ändern
+ {WWW_ROOT + data.data.qr_id} {data.data && }
diff --git a/src/services/PhpApi.ts b/src/services/PhpApi.ts index 5de2ecc..b3fbaf2 100644 --- a/src/services/PhpApi.ts +++ b/src/services/PhpApi.ts @@ -229,9 +229,9 @@ export const upload = (file: File, qr: string = '', onUploadProgress: any = null // return data; // } -export const logOut = () => +export const logOut = async () => { - Axios.post('logout.php') + await Axios.post('logout.php') .then((res) => { console.log('Header logout');