From c65bc4201be66358eee6bf112258f100c9191a5d Mon Sep 17 00:00:00 2001 From: Donkie Date: Fri, 2 Feb 2024 23:06:06 +0100 Subject: [PATCH] Currency setting is now utilized in filament/spool lists, edit pages etc --- client/public/locales/en/common.json | 4 ++-- client/src/components/column.tsx | 1 + client/src/pages/filaments/create.tsx | 9 ++++++++- client/src/pages/filaments/edit.tsx | 9 ++++++++- client/src/pages/filaments/list.tsx | 10 ++++++++++ client/src/pages/filaments/show.tsx | 12 +++++++++++- client/src/pages/spools/create.tsx | 9 ++++++++- client/src/pages/spools/edit.tsx | 9 ++++++++- client/src/pages/spools/list.tsx | 10 ++++++++++ client/src/pages/spools/show.tsx | 12 +++++++++++- client/src/utils/settings.ts | 19 +++++++++++++++++++ 11 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 client/src/utils/settings.ts diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index d688b5f..53160f8 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -153,7 +153,7 @@ "archived": "Archived" }, "fields_help": { - "price": "Price of a full spool in the system configured currency. If not set, the price of the filament will be assumed instead.", + "price": "Price of a full spool. If not set, the price of the filament will be assumed instead.", "weight_to_use": "Select what weight value to enter. Measured weight is only available if the spool weight is set for the selected filament.", "used_weight": "How much filament has been used from the spool. A new spool should have 0g used.", "remaining_weight": "How much filament is left on the spool. For a new spool this should match the spool weight.", @@ -202,7 +202,7 @@ "fields_help": { "name": "Filament name, to distinguish this filament type among others from the same vendor. Should contain the color for example.", "material": "E.g. PLA, ABS, PETG, etc.", - "price": "Price of a full spool in the system configured currency.", + "price": "Price of a full spool.", "weight": "The filament weight of a full spool (net weight). This should not include the weight of the spool itself, only the filament. It is what is usually written on the packaging.", "spool_weight": "The weight of an empty spool. Used to determine measured weight of a spool.", "article_number": "E.g. EAN, UPC, etc." diff --git a/client/src/components/column.tsx b/client/src/components/column.tsx index a773e3d..8a194d9 100644 --- a/client/src/components/column.tsx +++ b/client/src/components/column.tsx @@ -53,6 +53,7 @@ interface BaseColumnProps { width?: number; actions?: (record: Obj) => Action[]; transform?: (value: unknown) => unknown; + render?: (rawValue: string | undefined, record: Obj) => React.ReactNode; } interface FilteredColumnProps { diff --git a/client/src/pages/filaments/create.tsx b/client/src/pages/filaments/create.tsx index 664391d..6de8a79 100644 --- a/client/src/pages/filaments/create.tsx +++ b/client/src/pages/filaments/create.tsx @@ -10,6 +10,7 @@ import { EntityType, useGetFields } from "../../utils/queryFields"; import { ExtraFieldFormItem, StringifiedExtras } from "../../components/extraFields"; import dayjs from "dayjs"; import utc from "dayjs/plugin/utc"; +import { getCurrencySymbol, useCurrency } from "../../utils/settings"; dayjs.extend(utc); @@ -20,6 +21,7 @@ interface CreateOrCloneProps { export const FilamentCreate: React.FC = (props) => { const t = useTranslate(); const extraFields = useGetFields(EntityType.filament); + const currency = useCurrency(); const { form, formProps, formLoading, onFinish, redirect } = useForm< IFilament, @@ -149,7 +151,12 @@ export const FilamentCreate: React.FC - + = () => { const [messageApi, contextHolder] = message.useMessage(); const [hasChanged, setHasChanged] = useState(false); const extraFields = useGetFields(EntityType.filament); + const currency = useCurrency(); const { formProps, saveButtonProps } = useForm({ liveMode: "manual", @@ -168,7 +170,12 @@ export const FilamentEdit: React.FC = () => { }, ]} > - + = () => { const invalidate = useInvalidate(); const navigate = useNavigate(); const extraFields = useGetFields(EntityType.filament); + const currency = useCurrency(); const allColumnsWithExtraFields = [...allColumns, ...(extraFields.data?.map((field) => "extra." + field.key) ?? [])]; @@ -253,6 +255,14 @@ export const FilamentList: React.FC = () => { id: "price", i18ncat: "filament", width: 80, + render: (_, obj: IFilamentCollapsed) => { + return obj.price?.toLocaleString(undefined, { + style: "currency", + currencyDisplay: "narrowSymbol", + currency: currency, + notation: "compact", + }); + }, }), NumberColumn({ ...commonProps, diff --git a/client/src/pages/filaments/show.tsx b/client/src/pages/filaments/show.tsx index 6c6f002..567cafb 100644 --- a/client/src/pages/filaments/show.tsx +++ b/client/src/pages/filaments/show.tsx @@ -10,6 +10,7 @@ import { enrichText } from "../../utils/parsing"; import { useNavigate } from "react-router-dom"; import { EntityType, useGetFields } from "../../utils/queryFields"; import { ExtraFieldDisplay } from "../../components/extraFields"; +import { useCurrency } from "../../utils/settings"; dayjs.extend(utc); const { Title } = Typography; @@ -18,6 +19,7 @@ export const FilamentShow: React.FC = () => { const t = useTranslate(); const navigate = useNavigate(); const extraFields = useGetFields(EntityType.filament); + const currency = useCurrency(); const { queryResult } = useShow({ liveMode: "auto", }); @@ -82,7 +84,15 @@ export const FilamentShow: React.FC = () => { {t("filament.fields.material")} {t("filament.fields.price")} - + {t("filament.fields.density")} = (props) => { const t = useTranslate(); const extraFields = useGetFields(EntityType.spool); + const currency = useCurrency(); const { form, formProps, formLoading, onFinish, redirect } = useForm< ISpool, @@ -245,7 +247,12 @@ export const SpoolCreate: React.FC - +