Added change admin status query
This commit is contained in:
@@ -7,7 +7,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import AccountType, { AdminAccountOperation, CustomerType } from "../../components/Account";
|
import AccountType, { AdminAccountOperation, CustomerType } from "../../components/Account";
|
||||||
import { useAccount } from "../AccountProvider";
|
import { useAccount } from "../AccountProvider";
|
||||||
import { deleteAccountAdmin, fetchAccounts } from "../query/Queries";
|
import { deleteAccountAdmin, fetchAccounts, updateAccountAdmin } from "../query/Queries";
|
||||||
import CustomerEditDialog from "./CustomerEditDialog";
|
import CustomerEditDialog from "./CustomerEditDialog";
|
||||||
|
|
||||||
export default function AccountsInfo() {
|
export default function AccountsInfo() {
|
||||||
@@ -63,6 +63,12 @@ export default function AccountsInfo() {
|
|||||||
setRows(rows.filter((row) => !selectedRows.has(row.id)));
|
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]>[] = [
|
const columns: GridColDef<(typeof rows)[number]>[] = [
|
||||||
{ field: 'id', headerName: 'ID', width: 60 },
|
{ field: 'id', headerName: 'ID', width: 60 },
|
||||||
{
|
{
|
||||||
@@ -137,7 +143,11 @@ export default function AccountsInfo() {
|
|||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
showToolbar
|
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));
|
setRows(rows.map(row => row.id === updatedRow.id ? updatedRow : row));
|
||||||
return updatedRow;
|
return updatedRow;
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -297,3 +297,13 @@ export const deleteItemQuery = async (uuid: string) => {
|
|||||||
}
|
}
|
||||||
return response.json();
|
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();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user