Now goes back to loc page on edit submit
This commit is contained in:
@@ -61,8 +61,6 @@ const dataProvider = (
|
||||
params: queryParams,
|
||||
});
|
||||
|
||||
// console.log(url, requestMethod, queryParams, data, headers)
|
||||
|
||||
return {
|
||||
data,
|
||||
total: parseInt(headers["x-total-count"]) ?? 100,
|
||||
|
||||
@@ -52,7 +52,6 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
|
||||
// Update colorType state
|
||||
useEffect(() => {
|
||||
console.log(formProps.initialValues?.multi_color_hexes);
|
||||
if (formProps.initialValues?.multi_color_hexes) {
|
||||
setColorType("multi");
|
||||
} else {
|
||||
@@ -325,13 +324,13 @@ export const FilamentEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
<Input maxLength={64} />
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("filament.fields.external_id")}
|
||||
name={["external_id"]}
|
||||
rules={[
|
||||
{
|
||||
required: false,
|
||||
},
|
||||
]}
|
||||
label={t("filament.fields.external_id")}
|
||||
name={["external_id"]}
|
||||
rules={[
|
||||
{
|
||||
required: false,
|
||||
},
|
||||
]}
|
||||
>
|
||||
<Input maxLength={64} />
|
||||
</Form.Item>
|
||||
|
||||
@@ -141,7 +141,6 @@ export function LocationContainer() {
|
||||
useEffect(() => {
|
||||
// Check if they're not the same
|
||||
if (JSON.stringify(locationsList) !== JSON.stringify(settingsLocations)) {
|
||||
console.log("Updating locations settings", locationsList, settingsLocations);
|
||||
setLocationsSetting.mutate(locationsList);
|
||||
}
|
||||
}, [spoolLocations]);
|
||||
|
||||
@@ -164,7 +164,7 @@ export function SpoolCard({
|
||||
#{spool.id} {filament_name}
|
||||
</span>
|
||||
<div>
|
||||
<Link to={editUrl("spool", spool.id)}>
|
||||
<Link to={`/spool/edit/${spool.id}?return=` + encodeURIComponent(window.location.pathname)}>
|
||||
<Button icon={<EditOutlined />} title={t("buttons.edit")} size="small" type="text" />
|
||||
</Link>
|
||||
<Link to={showUrl("spool", spool.id)}>
|
||||
|
||||
@@ -100,17 +100,13 @@ export function renderLabelContents(template: string, spool: ISpool): JSX.Elemen
|
||||
// Find all {tags} in the template string and loop over them
|
||||
// let matches = [...template.matchAll(/(?:{(.*?))?{(.*?)}(.*?)(?:}(.*?))?/gs)];
|
||||
let matches = [...template.matchAll(/{(?:[^}{]|{[^}{]*})*}/gs)];
|
||||
// console.log(matches){(?:[^}{]|{[^}{]*})*}
|
||||
let label_text = template;
|
||||
matches.forEach((match) => {
|
||||
// console.log(match)
|
||||
if ((match[0].match(/{/g)||[]).length == 1) {
|
||||
if ((match[0].match(/{/g) || []).length == 1) {
|
||||
let tag = match[0].replace(/[{}]/g, "");
|
||||
// console.log(tag)
|
||||
let tagValue = getTagValue(tag, spool)
|
||||
let tagValue = getTagValue(tag, spool);
|
||||
label_text = label_text.replace(match[0], tagValue);
|
||||
}
|
||||
else if ((match[0].match(/{/g)||[]).length == 2) {
|
||||
} else if ((match[0].match(/{/g) || []).length == 2) {
|
||||
let structure = match[0].match(/{(.*?){(.*?)}(.*?)}/);
|
||||
if (structure != null) {
|
||||
const tag = structure[2];
|
||||
|
||||
@@ -5,6 +5,7 @@ import TextArea from "antd/es/input/TextArea";
|
||||
import { message } from "antd/lib";
|
||||
import dayjs from "dayjs";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||
import { ExtraFieldFormItem, ParsedExtras, StringifiedExtras } from "../../components/extraFields";
|
||||
import { useSpoolmanLocations } from "../../components/otherModels";
|
||||
import { searchMatches } from "../../utils/filtering";
|
||||
@@ -32,6 +33,8 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
const [hasChanged, setHasChanged] = useState(false);
|
||||
const extraFields = useGetFields(EntityType.spool);
|
||||
const currency = useCurrency();
|
||||
const [searchParams, _] = useSearchParams();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { form, formProps, saveButtonProps } = useForm<ISpool, HttpError, ISpoolRequest, ISpool>({
|
||||
liveMode: "manual",
|
||||
@@ -40,6 +43,17 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
messageApi.warning(t("spool.form.spool_updated"));
|
||||
setHasChanged(true);
|
||||
},
|
||||
|
||||
// Custom redirect logic
|
||||
redirect: false,
|
||||
onMutationSuccess: () => {
|
||||
const returnUrl = searchParams.get("return");
|
||||
if (returnUrl) {
|
||||
navigate(returnUrl, { relative: "path" });
|
||||
} else {
|
||||
navigate("/spool");
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const initialWeightValue = Form.useWatch("initial_weight", form);
|
||||
@@ -118,7 +132,6 @@ export const SpoolEdit: React.FC<IResourceComponentsProps> = () => {
|
||||
useEffect(() => {
|
||||
const newFilamentWeight = selectedFilament?.weight || 0;
|
||||
const newSpoolWeight = selectedFilament?.spool_weight || 0;
|
||||
console.log("selectedFilament", selectedFilament, newFilamentWeight, newSpoolWeight);
|
||||
if (newFilamentWeight > 0) {
|
||||
form.setFieldValue("initial_weight", newFilamentWeight);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {InboxOutlined, PrinterOutlined, ToTopOutlined} from "@ant-design/icons";
|
||||
import { InboxOutlined, PrinterOutlined, ToTopOutlined } from "@ant-design/icons";
|
||||
import { DateField, NumberField, Show, TextField } from "@refinedev/antd";
|
||||
import {IResourceComponentsProps, useInvalidate, useShow, useTranslate} from "@refinedev/core";
|
||||
import {Button, Modal, Typography} from "antd";
|
||||
import { IResourceComponentsProps, useInvalidate, useShow, useTranslate } from "@refinedev/core";
|
||||
import { Button, Modal, Typography } from "antd";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import React from "react";
|
||||
@@ -12,8 +12,8 @@ import { enrichText } from "../../utils/parsing";
|
||||
import { EntityType, useGetFields } from "../../utils/queryFields";
|
||||
import { useCurrency } from "../../utils/settings";
|
||||
import { IFilament } from "../filaments/model";
|
||||
import { setSpoolArchived } from "./functions";
|
||||
import { ISpool } from "./model";
|
||||
import {setSpoolArchived} from "./functions";
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
@@ -52,9 +52,9 @@ export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
|
||||
});
|
||||
};
|
||||
|
||||
const archiveSpoolPopup = async (spool: ISpool|undefined) => {
|
||||
const archiveSpoolPopup = async (spool: ISpool | undefined) => {
|
||||
if (spool === undefined) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
// If the spool has no remaining weight, archive it immediately since it's likely not a mistake
|
||||
if (spool.remaining_weight != undefined && spool.remaining_weight <= 0) {
|
||||
@@ -116,27 +116,20 @@ export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
|
||||
headerButtons={({ defaultButtons }) => (
|
||||
<>
|
||||
<Button
|
||||
type="primary"
|
||||
icon={<PrinterOutlined />}
|
||||
href={"/spool/print?spools=" + record?.id + "&return=" + encodeURIComponent(window.location.pathname)}
|
||||
type="primary"
|
||||
icon={<PrinterOutlined />}
|
||||
href={"/spool/print?spools=" + record?.id + "&return=" + encodeURIComponent(window.location.pathname)}
|
||||
>
|
||||
{t("printing.qrcode.button")}
|
||||
</Button>
|
||||
{record?.archived ? (
|
||||
<Button
|
||||
icon={<ToTopOutlined />}
|
||||
onClick={() => archiveSpool(record, false)}
|
||||
>
|
||||
{t("buttons.unArchive")}
|
||||
</Button>
|
||||
<Button icon={<ToTopOutlined />} onClick={() => archiveSpool(record, false)}>
|
||||
{t("buttons.unArchive")}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
danger
|
||||
icon={<InboxOutlined />}
|
||||
onClick={() => archiveSpoolPopup(record)}
|
||||
>
|
||||
{t("buttons.archive")}
|
||||
</Button>
|
||||
<Button danger icon={<InboxOutlined />} onClick={() => archiveSpoolPopup(record)}>
|
||||
{t("buttons.archive")}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{defaultButtons}
|
||||
|
||||
Reference in New Issue
Block a user