summaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx36
1 files changed, 21 insertions, 15 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
index 78d7c83ac..50262be17 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/templates/create/CreatePage.tsx
@@ -70,7 +70,7 @@ interface Props {
export function CreatePage({ onCreate, onBack }: Props): VNode {
const { i18n } = useTranslationContext();
const { config } = useSessionContext();
- const {state:session} = useSessionContext();
+ const { state: session } = useSessionContext();
const devices = useInstanceOtpDevices();
const [state, setState] = useState<Partial<Entity>>({
@@ -100,11 +100,11 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
: undefined,
description: !state.description ? i18n.str`should not be empty` : undefined,
amount: !state.amount
- ? undefined
+ ? state.amount_editable ? undefined : i18n.str`required`
: !parsedPrice
? i18n.str`not valid`
: Amounts.isZero(parsedPrice)
- ? i18n.str`must be greater than 0`
+ ? state.amount_editable ? undefined : i18n.str`must be greater than 0`
: undefined,
minimum_age:
state.minimum_age && state.minimum_age < 0
@@ -125,24 +125,30 @@ export function CreatePage({ onCreate, onBack }: Props): VNode {
(k) => (errors as Record<string, unknown>)[k] !== undefined,
);
+ const zero = Amounts.stringify(Amounts.zeroOfCurrency(config.currency))
+
const submitForm = () => {
if (hasErrors) return Promise.reject();
+ const contract_amount = state.amount_editable ? undefined : state.amount as AmountString
+ const contract_summary = state.summary_editable ? undefined : state.summary
+ const template_contract: TalerMerchantApi.TemplateContractDetails = {
+ minimum_age: state.minimum_age!,
+ pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!),
+ amount: contract_amount,
+ summary: contract_summary,
+ currency:
+ cList.length > 1 && state.currency_editable
+ ? undefined
+ : config.currency,
+ }
return onCreate({
template_id: state.id!,
template_description: state.description!,
- template_contract: {
- minimum_age: state.minimum_age!,
- pay_duration: Duration.toTalerProtocolDuration(state.pay_duration!),
- amount: state.amount_editable ? undefined : state.amount,
- summary: state.summary_editable ? undefined : state.summary,
- currency:
- cList.length > 1 && state.currency_editable
- ? undefined
- : config.currency,
- },
+ template_contract,
+ required_currency: contract_amount !== undefined ? undefined : config.currency,
editable_defaults: {
- amount: !state.amount_editable ? undefined : state.amount,
- summary: !state.summary_editable ? undefined : state.summary,
+ amount: !state.amount_editable ? undefined : (state.amount ?? zero),
+ summary: !state.summary_editable ? undefined : (state.summary ?? ""),
currency:
cList.length === 1 || !state.currency_editable
? undefined