Now goes back to loc page on edit submit

This commit is contained in:
Donkie
2024-11-24 12:31:38 +01:00
parent 1a55855ce9
commit 755e06c989
7 changed files with 40 additions and 42 deletions

View File

@@ -61,8 +61,6 @@ const dataProvider = (
params: queryParams,
});
// console.log(url, requestMethod, queryParams, data, headers)
return {
data,
total: parseInt(headers["x-total-count"]) ?? 100,

View File

@@ -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 {

View File

@@ -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]);

View File

@@ -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)}>

View File

@@ -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];

View File

@@ -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);
}

View File

@@ -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) {
@@ -123,18 +123,11 @@ export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
{t("printing.qrcode.button")}
</Button>
{record?.archived ? (
<Button
icon={<ToTopOutlined />}
onClick={() => archiveSpool(record, false)}
>
<Button icon={<ToTopOutlined />} onClick={() => archiveSpool(record, false)}>
{t("buttons.unArchive")}
</Button>
) : (
<Button
danger
icon={<InboxOutlined />}
onClick={() => archiveSpoolPopup(record)}
>
<Button danger icon={<InboxOutlined />} onClick={() => archiveSpoolPopup(record)}>
{t("buttons.archive")}
</Button>
)}