Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add archive/un archive button to spool view page #517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/pages/spools/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const SpoolList: React.FC<IResourceComponentsProps> = () => {

const archiveSpoolPopup = async (spool: ISpoolCollapsed) => {
// If the spool has no remaining weight, archive it immediately since it's likely not a mistake
if (spool.remaining_weight && spool.remaining_weight == 0) {
if (spool.remaining_weight != undefined && spool.remaining_weight <= 0) {
await archiveSpool(spool, true);
} else {
confirm({
Expand Down
63 changes: 57 additions & 6 deletions client/src/pages/spools/show.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PrinterOutlined } from "@ant-design/icons";
import {InboxOutlined, PrinterOutlined, ToTopOutlined} from "@ant-design/icons";
import { DateField, NumberField, Show, TextField } from "@refinedev/antd";
import { IResourceComponentsProps, useShow, useTranslate } from "@refinedev/core";
import { Button, 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";
Expand All @@ -13,15 +13,18 @@ import { EntityType, useGetFields } from "../../utils/queryFields";
import { useCurrency } from "../../utils/settings";
import { IFilament } from "../filaments/model";
import { ISpool } from "./model";
import {setSpoolArchived} from "./functions";

dayjs.extend(utc);

const { Title } = Typography;
const { confirm } = Modal;

export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
const t = useTranslate();
const extraFields = useGetFields(EntityType.spool);
const currency = useCurrency();
const invalidate = useInvalidate();

const { queryResult } = useShow<ISpool>({
liveMode: "auto",
Expand All @@ -39,6 +42,37 @@ export const SpoolShow: React.FC<IResourceComponentsProps> = () => {
return item.price;
};

// Function for opening an ant design modal that asks for confirmation for archiving a spool
const archiveSpool = async (spool: ISpool, archive: boolean) => {
await setSpoolArchived(spool, archive);
invalidate({
resource: "spool",
id: spool.id,
invalidates: ["list", "detail"],
});
};

const archiveSpoolPopup = async (spool: ISpool|undefined) => {
if (spool === undefined) {
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) {
await archiveSpool(spool, true);
} else {
confirm({
title: t("spool.titles.archive"),
content: t("spool.messages.archive"),
okText: t("buttons.archive"),
okType: "primary",
cancelText: t("buttons.cancel"),
onOk() {
return archiveSpool(spool, true);
},
});
}
};

const formatFilament = (item: IFilament) => {
let vendorPrefix = "";
if (item.vendor) {
Expand Down Expand Up @@ -82,12 +116,29 @@ 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
danger
icon={<InboxOutlined />}
onClick={() => archiveSpoolPopup(record)}
>
{t("buttons.archive")}
</Button>
)}

{defaultButtons}
</>
)}
Expand Down
Loading