From 0043f536eea01e4a6b8f050064d39073362f4bb2 Mon Sep 17 00:00:00 2001 From: Donkie Date: Sun, 30 Jul 2023 10:20:46 +0200 Subject: [PATCH] Client: Translations for qr code stuff Also added error if no spools were selected --- client/public/locales/en/common.json | 31 +++++++++++++++++++ client/public/locales/sv/common.json | 31 +++++++++++++++++++ .../components/printing/printingDialog.tsx | 27 +++++++++------- .../printing/qrCodePrintingDialog.tsx | 11 ++++--- .../src/components/selectAndPrintDialog.tsx | 7 +++-- client/src/components/spoolSelectModal.tsx | 23 ++++++++++---- 6 files changed, 107 insertions(+), 23 deletions(-) diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 549f7ea..21abefa 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -53,6 +53,37 @@ "dashboard": { "title": "Dashboard" }, + "printing": { + "generic": { + "title": "Printing", + "print": "Print", + "columns": "Columns", + "paperSize": "Paper Size", + "rowHeight": "Row Height", + "showBorder": "Show Border", + "previewScale": "Preview Scale", + "marginLeft": "Left Margin", + "marginRight": "Right Margin", + "marginTop": "Top Margin", + "marginBottom": "Bottom Margin" + }, + "qrcode": { + "button": "Print QR Codes", + "title": "QR Code Printing", + "textSize": "Content Text Size", + "showSpoolmanIcon": "Show Spoolman Icon", + "showContent": "Show QR Code Content" + }, + "spoolSelect": { + "title": "Select Spools", + "description": "Select spools to print QR codes for.", + "showArchived": "Show Archived", + "noSpoolsSelected": "You have not selected any spools.", + "selectAll": "Select/Unselect All", + "selectedTotal_one": "{{count}} spool selected", + "selectedTotal_other": "{{count}} spools selected" + } + }, "spool": { "spool": "Spools", "fields": { diff --git a/client/public/locales/sv/common.json b/client/public/locales/sv/common.json index fc5d19e..37a25fb 100644 --- a/client/public/locales/sv/common.json +++ b/client/public/locales/sv/common.json @@ -53,6 +53,37 @@ "dashboard": { "title": "Hem" }, + "printing": { + "generic": { + "title": "Utskrift", + "print": "Skriv ut", + "columns": "Kolumner", + "paperSize": "Papperstyp", + "rowHeight": "Radhöjd", + "showBorder": "Visa ram", + "previewScale": "Skala förhandsgranskning", + "marginLeft": "Marginal - vänster", + "marginRight": "Marginal - höger", + "marginTop": "Marginal - topp", + "marginBottom": "Marginal - botten" + }, + "qrcode": { + "button": "Skriv ut QR-koder", + "title": "QR-kod utskrift", + "textSize": "Textstorlek", + "showSpoolmanIcon": "Visa Spoolman-ikon", + "showContent": "Visa QR-kodsinnehåll" + }, + "spoolSelect": { + "title": "Välj spolar", + "description": "Välj spolar att skriva ut QR-koder för.", + "showArchived": "Tillåt arkiverade", + "noSpoolsSelected": "Du har inte valt några spolar.", + "selectAll": "Markera/avmarkera alla", + "selectedTotal_one": "{{count}} spole vald", + "selectedTotal_other": "{{count}} spolar valda" + } + }, "spool": { "spool": "Spolar", "fields": { diff --git a/client/src/components/printing/printingDialog.tsx b/client/src/components/printing/printingDialog.tsx index a0df3af..2778d34 100644 --- a/client/src/components/printing/printingDialog.tsx +++ b/client/src/components/printing/printingDialog.tsx @@ -12,6 +12,7 @@ import { } from "antd"; import ReactToPrint from "react-to-print"; import { useSavedState } from "../../utils/saveload"; +import { useTranslate } from "@refinedev/core"; interface PrintingDialogProps { items: JSX.Element[]; @@ -62,6 +63,8 @@ const PrintingDialog: React.FC = ({ onCancel, title, }) => { + const t = useTranslate(); + const [marginLeft, setMarginLeft] = useSavedState("print-marginLeft", 10); const [marginTop, setMarginTop] = useSavedState("print-marginTop", 10); const [marginRight, setMarginRight] = useSavedState("print-marginRight", 10); @@ -140,12 +143,14 @@ const PrintingDialog: React.FC = ({ return ( } + trigger={() => ( + + )} content={() => printRef.current} />, ]} @@ -203,7 +208,7 @@ const PrintingDialog: React.FC = ({ labelCol={{ span: 14 }} wrapperCol={{ span: 10 }} > - + = ({ }} /> - + = ({ }} /> - + = ({ }} /> - + = ({ }} /> - + = ({ }} /> - + - + = ({ }} /> - + setShowBorder(checked)} @@ -289,7 +294,7 @@ const PrintingDialog: React.FC = ({ {extraSettings && } {extraSettings} - + = ({ items, onCancel, }) => { + const t = useTranslate(); + const [showContent, setShowContent] = useSavedState( "print-showContent", true @@ -55,17 +58,17 @@ const QRCodePrintingDialog: React.FC = ({ return ( - + setShowContent(checked)} /> - + `${value} mm` }} @@ -78,7 +81,7 @@ const QRCodePrintingDialog: React.FC = ({ }} /> - + setShowSpoolmanIcon(checked)} diff --git a/client/src/components/selectAndPrintDialog.tsx b/client/src/components/selectAndPrintDialog.tsx index 6a812e0..455e915 100644 --- a/client/src/components/selectAndPrintDialog.tsx +++ b/client/src/components/selectAndPrintDialog.tsx @@ -6,8 +6,11 @@ import QRCodePrintingDialog from "./printing/qrCodePrintingDialog"; import { Button } from "antd"; import { ISpool } from "../pages/spools/model"; import { PrinterOutlined } from "@ant-design/icons"; +import { useTranslate } from "@refinedev/core"; const SelectAndPrint: React.FC = () => { + const t = useTranslate(); + const [step, setStep] = React.useState(0); const [selectedSpools, setSelectedSpools] = React.useState([]); return ( @@ -19,11 +22,11 @@ const SelectAndPrint: React.FC = () => { setStep(1); }} > - Print QR Codes + {t("printing.qrcode.button")} { setStep(0); }} diff --git a/client/src/components/spoolSelectModal.tsx b/client/src/components/spoolSelectModal.tsx index 8d158a5..71faed9 100644 --- a/client/src/components/spoolSelectModal.tsx +++ b/client/src/components/spoolSelectModal.tsx @@ -1,11 +1,12 @@ import React, { useState } from "react"; -import { Modal, Table, Checkbox, Space, Row, Col } from "antd"; +import { Modal, Table, Checkbox, Space, Row, Col, message } from "antd"; import { ISpool } from "../pages/spools/model"; import { FilteredColumn, SortedColumn, SpoolIconColumn } from "./column"; import { TableState } from "../utils/saveload"; import { useTable } from "@refinedev/antd"; import { genericSorter, typeSorters } from "../utils/sorting"; import { genericFilterer, typeFilters } from "../utils/filtering"; +import { t } from "i18next"; interface Props { visible: boolean; @@ -27,6 +28,7 @@ const SpoolSelectModal: React.FC = ({ }) => { const [selectedItems, setSelectedItems] = useState([]); const [showArchived, setShowArchived] = useState(false); + const [messageApi, contextHolder] = message.useMessage(); const { tableProps, sorters, filters, current, pageSize } = useTable({ meta: { @@ -112,16 +114,24 @@ const SpoolSelectModal: React.FC = ({ return ( { + if (selectedItems.length === 0) { + messageApi.open({ + type: "error", + content: t("printing.spoolSelect.noSpoolsSelected"), + }); + return; + } onContinue( dataSource.filter((spool) => selectedItems.includes(spool.id)) ); }} width={600} > + {contextHolder} {description &&
{description}
} = ({ selectUnselectFiltered(e.target.checked); }} > - Select/Unselect All + {t("printing.spoolSelect.selectAll")}
- {selectedItems.length} spool - {selectedItems.length === 1 ? "" : "s"} selected + {t("printing.spoolSelect.selectedTotal", { + count: selectedItems.length, + })}
@@ -194,7 +205,7 @@ const SpoolSelectModal: React.FC = ({ } }} > - Show Archived + {t("printing.spoolSelect.showArchived")}