Added Account delete admin button.
This commit is contained in:
@@ -36,6 +36,12 @@ export type SubmitLoginSession = {
|
||||
session: string;
|
||||
};
|
||||
|
||||
export type AdminAccountOperation = {
|
||||
email: string;
|
||||
session: string;
|
||||
accountId: number;
|
||||
}
|
||||
|
||||
export type User = {
|
||||
password: string;
|
||||
email: string;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import EditIcon from "@mui/icons-material/Edit";
|
||||
import { Box, Button, IconButton, Toolbar, useTheme } from "@mui/material";
|
||||
import AccountType from "../../components/Account";
|
||||
import {useTranslation} from "react-i18next";
|
||||
import { DataGrid, GridColDef, GridRowId, GridRowSelectionModel } from "@mui/x-data-grid";
|
||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { fetchAccounts } from "../query/Queries";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import AccountType, { AdminAccountOperation } from "../../components/Account";
|
||||
import { useAccount } from "../AccountProvider";
|
||||
import { deleteAccountAdmin, fetchAccounts } from "../query/Queries";
|
||||
|
||||
export default function AccountsInfo() {
|
||||
const theme = useTheme();
|
||||
@@ -30,6 +30,11 @@ export default function AccountsInfo() {
|
||||
retryDelay: 1000,
|
||||
});
|
||||
|
||||
const deleteAccount = useMutation({
|
||||
mutationFn: (user: AdminAccountOperation) =>
|
||||
deleteAccountAdmin(user),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (data) {
|
||||
setRows(data);
|
||||
@@ -41,9 +46,9 @@ export default function AccountsInfo() {
|
||||
};
|
||||
|
||||
const handleDeleteSelected = async () => {
|
||||
selectedRows.forEach((row) => {
|
||||
//TODO: send delete command, or send deleteall
|
||||
console.log(row);
|
||||
selectedRows.forEach(async (row) => {
|
||||
|
||||
await deleteAccount.mutateAsync({ email: loginData?.email || '', session: loginData?.session || '', accountId: row.id as number });
|
||||
})
|
||||
|
||||
setRows(rows.filter((row) => !selectedRows.has(row.id)));
|
||||
@@ -96,7 +101,8 @@ export default function AccountsInfo() {
|
||||
checkboxSelection
|
||||
disableRowSelectionOnClick
|
||||
onRowSelectionModelChange={handleSelectionChange}
|
||||
slots={{ toolbar: () => (
|
||||
slots={{
|
||||
toolbar: () => (
|
||||
<Toolbar>
|
||||
<Button
|
||||
variant="contained"
|
||||
@@ -111,7 +117,8 @@ export default function AccountsInfo() {
|
||||
{t('deleteAccount')}
|
||||
</Button>
|
||||
</Toolbar>
|
||||
)}}
|
||||
)
|
||||
}}
|
||||
showToolbar
|
||||
processRowUpdate={(updatedRow) => {
|
||||
setRows(rows.map(row => row.id === updatedRow.id ? updatedRow : row));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// api/queries.js
|
||||
|
||||
import AccountType, { CustomerType, SubmitLogin, User } from "../../components/Account";
|
||||
import AccountType, { AdminAccountOperation, CustomerType, SubmitLogin, User } from "../../components/Account";
|
||||
import OrderType, { OrderPatch } from "../../components/Order";
|
||||
import RatingSubmitType from "../../components/RatingSubmit";
|
||||
|
||||
@@ -151,6 +151,16 @@ export const deleteAccount = async (user: User) => {
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
export const deleteAccountAdmin = async (user: AdminAccountOperation) => {
|
||||
const response = await fetch('http://localhost:8085/account/admin?email=' + user.email + '&session=' + user.session + '&accountId=' + user.accountId, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Fehler beim Löschen des Accounts');
|
||||
}
|
||||
return await response.json();
|
||||
};
|
||||
|
||||
export const fetchOrders = async (customerId: number) => {
|
||||
const response = await fetch('http://localhost:8085/order/all?customerId=' + customerId);
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user