UNPKG

@etsoo/smarterp-core

Version:
34 lines (33 loc) 1.3 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { ButtonPopupCheckbox } from "@etsoo/materialui"; import { useRequiredAppContext } from "../../ICoreServiceApp"; import React from "react"; export function ButtonCurrencies(props) { // App const app = useRequiredAppContext(); // Labels const labels = app.getLabels("clickToChoose", "currencies"); // Destruct const { inputName = "currencies", label = labels.currencies, labelEnd = labels.clickToChoose, ...rest } = props; const defaultCurrencies = [ "USD", "CNY", "EUR", "GBP", "JPY", "AUD", "CAD", "SGD", "HKD", "NZD" ]; defaultCurrencies.sort((a) => (a.startsWith(app.region) ? -1 : 0)); // Load data const loadData = React.useCallback(async () => (await app.core.publicApi.getCurrencies(defaultCurrencies)) ?? [], []); return (_jsx(ButtonPopupCheckbox, { inputName: inputName, label: label, labelFormatter: (data) => `${data.name} (${data.id})`, labelEnd: labelEnd, labelField: "name", loadData: loadData, onAdd: async (ids) => { const data = await app.core.publicApi.getCurrencies(ids); if (data == null) return false; return data; }, ...rest })); }