mirror of
https://github.com/BarkProductions/barkman.git
synced 2026-06-12 22:11:54 +00:00
added notifications and redirect to edit item page
This commit is contained in:
@@ -74,7 +74,8 @@ function AddItem() {
|
|||||||
wrap="wrap">
|
wrap="wrap">
|
||||||
|
|
||||||
<Title order={1}>Add Item</Title>
|
<Title order={1}>Add Item</Title>
|
||||||
|
<NumberInput withAsterisk size="md" key={newItemForm.key('barcode')} label="Barcode"
|
||||||
|
placeholder="Barcode" {...newItemForm.getInputProps('barcode')}/>
|
||||||
<TextInput withAsterisk key={newItemForm.key('brand')} size="md" label="Brand"
|
<TextInput withAsterisk key={newItemForm.key('brand')} size="md" label="Brand"
|
||||||
placeholder="Brand" {...newItemForm.getInputProps('brand')}/>
|
placeholder="Brand" {...newItemForm.getInputProps('brand')}/>
|
||||||
<TextInput withAsterisk key={newItemForm.key('name')} size="md" label="Name"
|
<TextInput withAsterisk key={newItemForm.key('name')} size="md" label="Name"
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import {Button, Group, TextInput, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core';
|
import {Button, Group, TextInput, Textarea, NumberInput, Container, Title, Flex} from '@mantine/core';
|
||||||
import {useForm} from '@mantine/form';
|
import {useForm} from '@mantine/form';
|
||||||
import {useParams} from "react-router";
|
import {useNavigate, useParams} from "react-router";
|
||||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||||
import {InventoryItem} from "./types.ts";
|
import {InventoryItem} from "./types.ts";
|
||||||
import {useEffect} from "react";
|
import {useEffect} from "react";
|
||||||
|
import {notifications} from "@mantine/notifications";
|
||||||
|
import {IconCheck, IconX} from "@tabler/icons-react";
|
||||||
|
|
||||||
type EditableInventoryItem = Omit<InventoryItem, 'id'>;
|
type EditableInventoryItem = Omit<InventoryItem, 'id'>;
|
||||||
|
|
||||||
function EditItem() {
|
function EditItem() {
|
||||||
const params = useParams();
|
const params = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const editItemForm = useForm<EditableInventoryItem>({
|
const editItemForm = useForm<EditableInventoryItem>({
|
||||||
mode: 'uncontrolled',
|
mode: 'uncontrolled',
|
||||||
@@ -54,7 +57,26 @@ function EditItem() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (result.ok) {
|
||||||
|
notifications.show({
|
||||||
|
icon: <IconCheck size={20} />,
|
||||||
|
color:"teal",
|
||||||
|
title: "All good!",
|
||||||
|
message: "Item Updated",
|
||||||
|
position: 'top-center',
|
||||||
|
});
|
||||||
|
navigate("/inventory");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (!result.ok) {
|
if (!result.ok) {
|
||||||
|
notifications.show({
|
||||||
|
icon: <IconX size={20} />,
|
||||||
|
color:"red",
|
||||||
|
title: "Bummer!",
|
||||||
|
message: "Something went wrong",
|
||||||
|
position: 'top-center',
|
||||||
|
});
|
||||||
throw new Error('Failed to update inventory item');
|
throw new Error('Failed to update inventory item');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user