prolif löschen

This commit is contained in:
2023-03-02 22:02:38 +01:00
parent 5c7f9b3b03
commit c3e5b151b0
5 changed files with 76 additions and 13 deletions

View File

@ -87,7 +87,7 @@ const App: React.FC = () =>
padding={0}
fixed
navbarOffsetBreakpoint="sm"
navbar={<DogNavbar hidden={!opened} hasUser={user ? true : false} onLogout={userLogout}/>}
navbar={<DogNavbar qr_id={user ? user.qr_id : null} hidden={!opened} hasUser={user ? true : false} onLogout={userLogout}/>}
header={
<Header height={'44px'} p="md" className='w-16 bg-orange-500'>

View File

@ -4,6 +4,9 @@ import React, { useState } from 'react'
import { Link } from 'react-router-dom'
import { ModalsProvider, openConfirmModal } from '@mantine/modals';
import './DogNavbar.css';
import { deleteProfil } from '../services/PhpApi';
import { notificationError, notificationSuccess } from '../services/Notifications';
import { ResponseT } from '../context/UserContext';
const NaveBarIcon = ({ icon, href, text = 'tooltip 💡'}: {icon: JSX.Element, href: string, text: string}) =>
(
@ -20,7 +23,7 @@ const NaveBarIcon = ({ icon, href, text = 'tooltip 💡'}: {icon: JSX.Element, h
const Divider = () => <hr className="sidebar-hr" />;
const openDeleteModal = () =>
const openDeleteModal = (qr_id: string | null) =>
openConfirmModal({
title: 'Account löschen!',
centered: true,
@ -32,10 +35,27 @@ const openDeleteModal = () =>
),
labels: { confirm: 'Account löschen', cancel: "Behalten, nicht löschen" },
onCancel: () => console.log('Cancel'),
onConfirm: () => console.log('Confirmed')
onConfirm: () =>
{
console.log('Confirmed');
if(qr_id)
{
const data = deleteProfil({qr_id: qr_id}) as ResponseT;
if(data.success)
{
notificationSuccess('Profil gelöscht!');
}
else if(!data.success && data.message)
{
notificationError(data.message);
}
window.location.href = '/dog/';
}
}
});
function DogNavbar({hasUser, hidden, onLogout}:{hasUser: boolean, hidden: boolean, onLogout: () => void})
function DogNavbar({hasUser, qr_id, hidden, onLogout}:
{hasUser: boolean, qr_id: string | null, hidden: boolean, onLogout: () => void})
{
return (
<>
@ -79,7 +99,7 @@ function DogNavbar({hasUser, hidden, onLogout}:{hasUser: boolean, hidden: boolea
<Divider/>
<Navbar.Section className='InputForm' >
{hasUser &&
<div onClick={openDeleteModal}>
<div onClick={() => openDeleteModal(qr_id)}>
<NaveBarIcon icon={<Icons.UserMinus size={32}/>} href={''} text={'Account löschen'}/>
</div>
}

View File

@ -299,6 +299,21 @@ export const wantNewPw = async ({email}:{email: string}) =>
}
}
export const deleteProfil = async ({qr_id}:{qr_id: string}) =>
{
try
{
const {data} = await Axios.post('deleteProfil.php', {qr_id});
console.log('Api deleteProfil');
console.log(data);
return data;
}
catch(err)
{
return {success:0, message:'Password Request Server Error!'};
}
}
// export const sleep = (ms: number) =>
// {