diff --git a/client/src/components/otherModels.tsx b/client/src/components/otherModels.tsx index 02feebb..0bd5beb 100644 --- a/client/src/components/otherModels.tsx +++ b/client/src/components/otherModels.tsx @@ -3,10 +3,10 @@ import { IFilament } from "../pages/filaments/model"; import { IVendor } from "../pages/vendors/model"; import { ColumnFilterItem } from "antd/es/table/interface"; -export function useSpoolmanFilamentFilter() { +export function useSpoolmanFilamentFilter(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["filaments"], queryFn: async () => { const response = await fetch(apiEndpoint + "/filament"); @@ -44,10 +44,10 @@ export function useSpoolmanFilamentFilter() { }); } -export function useSpoolmanFilamentNames() { +export function useSpoolmanFilamentNames(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["filaments"], queryFn: async () => { const response = await fetch(apiEndpoint + "/filament"); @@ -73,10 +73,10 @@ export function useSpoolmanFilamentNames() { }); } -export function useSpoolmanVendors() { +export function useSpoolmanVendors(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["vendors"], queryFn: async () => { const response = await fetch(apiEndpoint + "/vendor"); @@ -95,10 +95,10 @@ export function useSpoolmanVendors() { }); } -export function useSpoolmanMaterials() { +export function useSpoolmanMaterials(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["materials"], queryFn: async () => { const response = await fetch(apiEndpoint + "/material"); @@ -113,10 +113,10 @@ export function useSpoolmanMaterials() { }); } -export function useSpoolmanArticleNumbers() { +export function useSpoolmanArticleNumbers(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["articleNumbers"], queryFn: async () => { const response = await fetch(apiEndpoint + "/article-number"); @@ -131,10 +131,10 @@ export function useSpoolmanArticleNumbers() { }); } -export function useSpoolmanLotNumbers() { +export function useSpoolmanLotNumbers(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["lotNumbers"], queryFn: async () => { const response = await fetch(apiEndpoint + "/lot-number"); @@ -149,10 +149,10 @@ export function useSpoolmanLotNumbers() { }); } -export function useSpoolmanLocations() { +export function useSpoolmanLocations(enabled: boolean = false) { const apiEndpoint = import.meta.env.VITE_APIURL; return useQuery({ - enabled: false, + enabled: enabled, queryKey: ["locations"], queryFn: async () => { const response = await fetch(apiEndpoint + "/location"); diff --git a/client/src/pages/spools/create.tsx b/client/src/pages/spools/create.tsx index 937fabb..8ef22e3 100644 --- a/client/src/pages/spools/create.tsx +++ b/client/src/pages/spools/create.tsx @@ -1,12 +1,13 @@ import React, { useState } from "react"; import { IResourceComponentsProps, useTranslate } from "@refinedev/core"; import { Create, useForm, useSelect } from "@refinedev/antd"; -import { Form, Input, DatePicker, Select, InputNumber, Radio } from "antd"; +import { Form, Input, DatePicker, Select, InputNumber, Radio, Divider } from "antd"; import dayjs from "dayjs"; import TextArea from "antd/es/input/TextArea"; import { IFilament } from "../filaments/model"; import { ISpool } from "./model"; import { numberFormatter, numberParser } from "../../utils/parsing"; +import { useSpoolmanLocations } from "../../components/otherModels"; interface CreateOrCloneProps { mode: "create" | "clone"; @@ -91,6 +92,14 @@ export const SpoolCreate: React.FC - - {t("spool.fields.used_weight")} - - + {t("spool.fields.used_weight")} + {t("spool.fields.remaining_weight")} - + {t("spool.fields.measured_weight")} @@ -246,7 +245,21 @@ export const SpoolCreate: React.FC - + setNewLocation(event.target.value)} + /> + + )} + loading={locations.isLoading} + options={allLocations.map((item) => ({ label: item, value: item }))} + /> = () => { const t = useTranslate(); @@ -77,15 +78,23 @@ export const SpoolEdit: React.FC = () => { }); }; + const locations = useSpoolmanLocations(true); + const [newLocation, setNewLocation] = useState(""); + + const allLocations = [...(locations.data || [])]; + if (newLocation.trim() && !allLocations.includes(newLocation)) { + allLocations.push(newLocation.trim()); + } + if (formProps.initialValues) { formProps.initialValues["filament_id"] = formProps.initialValues["filament"].id; } useEffect(() => { if (formProps.initialValues && usedWeight != formProps.initialValues["used_weight"]) { - setUsedWeight(formProps.initialValues["used_weight"]) + setUsedWeight(formProps.initialValues["used_weight"]); } - }, []); + }, [formProps.initialValues, usedWeight]); return ( @@ -166,7 +175,6 @@ export const SpoolEdit: React.FC = () => { - { @@ -175,32 +183,16 @@ export const SpoolEdit: React.FC = () => { defaultValue={1} value={weightToEnter} > - - {t("spool.fields.used_weight")} - - + {t("spool.fields.used_weight")} + {t("spool.fields.remaining_weight")} - + {t("spool.fields.measured_weight")} - - + = () => { }} /> - + = () => { }} /> - + = () => { }, ]} > - + setNewLocation(event.target.value)} + /> + + )} + loading={locations.isLoading} + options={allLocations.map((item) => ({ label: item, value: item }))} + />