summaryrefslogtreecommitdiff
path: root/packages/frontend/src/paths/admin/create/CreatePage.tsx
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-08-07 21:59:57 -0300
committerSebastian <sebasjm@gmail.com>2021-08-07 21:59:57 -0300
commita3fd3e81dc32df7eedff40e1dcb28fa999898b56 (patch)
tree859c6c657c7138106f69ec36c1d5a25690dbe65a /packages/frontend/src/paths/admin/create/CreatePage.tsx
parent6f892448822638bcd5bea33083d311e83352b552 (diff)
downloadmerchant-backoffice-a3fd3e81dc32df7eedff40e1dcb28fa999898b56.tar.gz
merchant-backoffice-a3fd3e81dc32df7eedff40e1dcb28fa999898b56.tar.bz2
merchant-backoffice-a3fd3e81dc32df7eedff40e1dcb28fa999898b56.zip
add creditor name
Diffstat (limited to 'packages/frontend/src/paths/admin/create/CreatePage.tsx')
-rw-r--r--packages/frontend/src/paths/admin/create/CreatePage.tsx37
1 files changed, 30 insertions, 7 deletions
diff --git a/packages/frontend/src/paths/admin/create/CreatePage.tsx b/packages/frontend/src/paths/admin/create/CreatePage.tsx
index b2e6088..76f02e1 100644
--- a/packages/frontend/src/paths/admin/create/CreatePage.tsx
+++ b/packages/frontend/src/paths/admin/create/CreatePage.tsx
@@ -31,7 +31,12 @@ import { DefaultInstanceFormFields } from "../../../components/instance/DefaultI
import { INSTANCE_ID_REGEX, PAYTO_REGEX } from "../../../utils/constants";
import { Amounts } from "@gnu-taler/taler-util";
-export type Entity = MerchantBackend.Instances.InstanceConfigurationMessage & { auth_token?: string }
+export type Entity = MerchantBackend.Instances.InstanceConfigurationMessage & {
+ payto_uris_base: string[], // field to construct final payto URI
+ creditor_name: string, // name of the receiver for the payto URI
+ auth_token?: string
+}
+
interface Props {
onCreate: (d: Entity) => Promise<void>;
@@ -59,12 +64,23 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode {
const i18n = useTranslator()
+ if (value.payto_uris && value.payto_uris.length > 0) {
+ const payto = new URL(value.payto_uris[0])
+ value.creditor_name = payto.searchParams.get('receiver-name') || undefined
+ value.payto_uris_base = value.payto_uris.map( p => {
+ const payto = new URL(p)
+ payto.searchParams.delete('receiver-name')
+ return payto.toString()
+ })
+ }
+
const errors: FormErrors<Entity> = {
- id: !value.id ? i18n`required` : ( !INSTANCE_ID_REGEX.test(value.id) ? i18n`is not valid` : undefined),
+ id: !value.id ? i18n`required` : (!INSTANCE_ID_REGEX.test(value.id) ? i18n`is not valid` : undefined),
name: !value.name ? i18n`required` : undefined,
- payto_uris:
- !value.payto_uris || !value.payto_uris.length ? i18n`required` : (
- undefinedIfEmpty(value.payto_uris.map(p => {
+ creditor_name: !value.creditor_name ? i18n`required` : undefined,
+ payto_uris_base:
+ !value.payto_uris_base || !value.payto_uris_base.length ? i18n`required` : (
+ undefinedIfEmpty(value.payto_uris_base.map(p => {
return !PAYTO_REGEX.test(p) ? i18n`is not valid` : undefined
}))
),
@@ -107,9 +123,16 @@ export function CreatePage({ onCreate, onBack, forceId }: Props): VNode {
const newToken = value.auth_token;
value.auth_token = undefined;
value.auth = newToken === null || newToken === undefined ? { method: "external" } : { method: "token", token: `secret-token:${newToken}` };
- if (!value.address) value.address = {}
- if (!value.jurisdiction) value.jurisdiction = {}
+ if (!value.address) value.address = {}
+ if (!value.jurisdiction) value.jurisdiction = {}
// remove above use conversion
+ const receiverName = value.creditor_name!
+ value.payto_uris = value.payto_uris_base?.map(p => {
+ const payto = new URL(p)
+ payto.searchParams.set('receiver-name', receiverName)
+ return payto.toString()
+ }) || []
+ value.payto_uris_base = undefined
// schema.validateSync(value, { abortEarly: false })
return onCreate(value as Entity);
}