From 9ac3c56bbf4c909c431d1231f00b17a4375ff912 Mon Sep 17 00:00:00 2001 From: Donkie Date: Sun, 25 Jun 2023 17:25:02 +0200 Subject: [PATCH] Client: Added spool clone button --- client/public/locales/en/common.json | 3 +- client/src/App.tsx | 10 ++- client/src/pages/spools/clone.tsx | 130 +++++++++++++++++++++++++++ client/src/pages/spools/index.ts | 1 + client/src/pages/spools/list.tsx | 2 + 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 client/src/pages/spools/clone.tsx diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index fd5823d..ae191c2 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -69,7 +69,8 @@ "list": "List", "create": "Create", "edit": "Edit", - "show": "Show" + "show": "Show", + "clone": "Clone" }, "buttons": { "create": "Create", diff --git a/client/src/App.tsx b/client/src/App.tsx index cd349d2..ad355e5 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -19,7 +19,13 @@ import { useTranslation } from "react-i18next"; import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom"; import { Header } from "./components/header"; import { ColorModeContextProvider } from "./contexts/color-mode"; -import { SpoolCreate, SpoolEdit, SpoolList, SpoolShow } from "./pages/spools"; +import { + SpoolClone, + SpoolCreate, + SpoolEdit, + SpoolList, + SpoolShow, +} from "./pages/spools"; import { FilamentCreate, FilamentEdit, @@ -82,6 +88,7 @@ function App() { name: "spool", list: "/spool", create: "/spool/create", + clone: "/spool/clone/:id", edit: "/spool/edit/:id", show: "/spool/show/:id", meta: { @@ -146,6 +153,7 @@ function App() { } /> } /> + } /> } /> } /> diff --git a/client/src/pages/spools/clone.tsx b/client/src/pages/spools/clone.tsx new file mode 100644 index 0000000..f27125e --- /dev/null +++ b/client/src/pages/spools/clone.tsx @@ -0,0 +1,130 @@ +import React from "react"; +import { IResourceComponentsProps } from "@refinedev/core"; +import { Create, useForm, useSelect } from "@refinedev/antd"; +import { Form, Input, DatePicker, Select, InputNumber } from "antd"; +import dayjs from "dayjs"; +import TextArea from "antd/es/input/TextArea"; +import { IFilament } from "../filaments/model"; + +export const SpoolClone: React.FC = () => { + const { formProps, saveButtonProps, formLoading } = useForm(); + + if (formProps.initialValues) { + formProps.initialValues.first_used = null; + formProps.initialValues.last_used = null; + formProps.initialValues.used_weight = 0; + formProps.initialValues.filament_id = formProps.initialValues.filament.id; + } + + const { queryResult } = useSelect({ + resource: "filament", + }); + + const filamentOptions = queryResult.data?.data.map((item) => { + let label; + if (item.vendor) { + label = `${item.vendor.name} - ${item.name}`; + } else { + label = item.name; + } + + return { + label: label, + value: item.id, + }; + }); + + return ( + +
+ ({ + value: value ? dayjs(value) : undefined, + })} + > + + + ({ + value: value ? dayjs(value) : undefined, + })} + > + + + + + + + + + +