diff --git a/frontend/src/components/logistics/helperCommands/commands/RemoveAsNonReusable.tsx b/frontend/src/components/logistics/helperCommands/commands/RemoveAsNonReusable.tsx new file mode 100644 index 0000000..67a825f --- /dev/null +++ b/frontend/src/components/logistics/helperCommands/commands/RemoveAsNonReusable.tsx @@ -0,0 +1,138 @@ +import { LstCard } from "@/components/extendedUI/LstCard"; +import { Button } from "@/components/ui/button"; +import { CardContent, CardHeader } from "@/components/ui/card"; +import { Input } from "@/components/ui/input"; +import { Label } from "@/components/ui/label"; +import { Textarea } from "@/components/ui/textarea"; +import { useForm } from "@tanstack/react-form"; +import axios from "axios"; +import { useState } from "react"; +import { toast } from "sonner"; + +export default function RemoveAsNonReusable() { + const [stockOut, setStockOut] = useState(false); + const form = useForm({ + defaultValues: { runningNr: " ", reason: " " }, + onSubmit: async ({ value }) => { + // Do something with form data + setStockOut(true); + + //console.log(value); + + try { + const res = await axios.post( + "/api/logistics/removeasreusable", + + value // this is basically the data field + ); + + if (res.data.success) { + toast.success(res.data.message); + form.reset(); + setStockOut(false); + } else { + console.log(res.data); + toast.error(res.data?.message); + form.reset(); + setStockOut(false); + } + } catch (error: any) { + console.log(error); + toast.error(error.message); + setStockOut(false); + } + }, + }); + return ( + + +

Remove a pallet as non reusable

+
+
{ + e.preventDefault(); + e.stopPropagation(); + }} + > + + + value.length > 2 + ? undefined + : "Please enter a valid running number", + }} + children={(field) => { + return ( +
+ + + field.handleChange(e.target.value) + } + /> + {field.state.meta.errors.length ? ( + + {field.state.meta.errors.join(",")} + + ) : null} +
+ ); + }} + /> + + value.length > 10 + ? undefined + : "Please enter a valid reason on why you needed to remove this pallet", + }} + children={(field) => { + return ( +
+ +