Added query for chnage item
This commit is contained in:
Binary file not shown.
@@ -9,7 +9,7 @@ import {useTranslation} from "react-i18next";
|
||||
import Item from "../../components/Item";
|
||||
import { mapValueToColor } from "../../util/ColorUtil.tsx";
|
||||
import { useAccount } from "../AccountProvider.tsx";
|
||||
import {deleteItemQuery, fetchItems} from "../query/Queries.tsx";
|
||||
import { deleteItemQuery, fetchItems, updateItemAdmin } from "../query/Queries.tsx";
|
||||
import ItemImageDialog from "./ItemImageDialog.tsx";
|
||||
import NewItemDialog from "./NewItemDialog.tsx";
|
||||
|
||||
@@ -79,6 +79,18 @@ export default function ItemsInfo() {
|
||||
setRows(rows.filter((row) => !selectedRows.has(row.id)));
|
||||
};
|
||||
|
||||
const updateItem = useMutation({
|
||||
mutationFn: (item: Item) =>
|
||||
updateItemAdmin(item),
|
||||
|
||||
});
|
||||
|
||||
const handleRowUpdate = async (updatedRow: Item) => {
|
||||
setRows(rows.map(row => row.id === updatedRow.id ? updatedRow : row));
|
||||
await updateItem.mutateAsync(updatedRow);
|
||||
return updatedRow;
|
||||
}
|
||||
|
||||
const columns: GridColDef<(typeof rows)[number]>[] = [
|
||||
{ field: 'id', headerName: 'ID', width: 60 },
|
||||
{
|
||||
@@ -86,7 +98,7 @@ export default function ItemsInfo() {
|
||||
headerName: t('uuid'),
|
||||
type: "string",
|
||||
width: 120,
|
||||
editable: true
|
||||
editable: false
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
@@ -221,11 +233,7 @@ export default function ItemsInfo() {
|
||||
)
|
||||
}}
|
||||
showToolbar
|
||||
processRowUpdate={(updatedRow) => {
|
||||
setRows(rows.map(row => row.id === updatedRow.id ? updatedRow : row));
|
||||
//TODO: make REST callback
|
||||
return updatedRow;
|
||||
}}
|
||||
processRowUpdate={handleRowUpdate}
|
||||
/>
|
||||
{selectedItem && (
|
||||
<ItemImageDialog
|
||||
|
||||
@@ -299,7 +299,7 @@ export const deleteItemQuery = async (uuid: string) => {
|
||||
};
|
||||
|
||||
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, {
|
||||
const response = await fetch('http://localhost:8085/account/admin?email=' + user.email + "&uuid=" + user.session + "&id=" + account.id + "&admin=" + account.admin, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (!response.ok) {
|
||||
@@ -307,3 +307,17 @@ export const updateAccountAdmin = async (account: AccountType, user: User) => {
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export const updateItemAdmin = async (item: Item) => {
|
||||
const response = await fetch('http://localhost:8085/article?uuid=' + item.uuid, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(item),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error('Fehler beim Ändern des Items');
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user