Added change admin status query

This commit is contained in:
FlorianSpeicher
2025-06-18 23:50:45 +02:00
parent 739a5aa8af
commit b44909c9ca
2 changed files with 23 additions and 3 deletions

View File

@@ -7,7 +7,7 @@ import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import AccountType, { AdminAccountOperation, CustomerType } from "../../components/Account";
import { useAccount } from "../AccountProvider";
import { deleteAccountAdmin, fetchAccounts } from "../query/Queries";
import { deleteAccountAdmin, fetchAccounts, updateAccountAdmin } from "../query/Queries";
import CustomerEditDialog from "./CustomerEditDialog";
export default function AccountsInfo() {
@@ -63,6 +63,12 @@ export default function AccountsInfo() {
setRows(rows.filter((row) => !selectedRows.has(row.id)));
};
const updateAdmin = useMutation({
mutationFn: (account: AccountType) =>
updateAccountAdmin(account, loginData ? loginData : { email: "", password: "", session: "", customerId: -1, isAdmin: false }),
});
const columns: GridColDef<(typeof rows)[number]>[] = [
{ field: 'id', headerName: 'ID', width: 60 },
{
@@ -137,7 +143,11 @@ export default function AccountsInfo() {
)
}}
showToolbar
processRowUpdate={(updatedRow) => {
processRowUpdate={async (updatedRow) => {
const originalRow = rows.find(row => row.id === updatedRow.id);
if (originalRow && originalRow.admin !== updatedRow.admin) {
await updateAdmin.mutateAsync(updatedRow);
}
setRows(rows.map(row => row.id === updatedRow.id ? updatedRow : row));
return updatedRow;
}}

View File

@@ -297,3 +297,13 @@ export const deleteItemQuery = async (uuid: string) => {
}
return response.json();
};
export const updateAccountAdmin = async (account: AccountType, user: User) => {
const response = await fetch('http://localhost:8085/account/admin?email=' + user.email + "&password=" + user.password + "&id=" + account.id + "&admin=" + account.admin, {
method: 'POST',
});
if (!response.ok) {
throw new Error('Fehler beim Ändern des Customers');
}
return await response.json();
}