diff options
author | Christian Blättler <blatc2@bfh.ch> | 2024-05-22 21:12:37 +0200 |
---|---|---|
committer | Christian Blättler <blatc2@bfh.ch> | 2024-05-22 21:12:37 +0200 |
commit | 635d710203bd88843ba16bbee7ab43ad02d295ca (patch) | |
tree | df9c36c59c102cf66592fb1fed3f1808d60e91ac /packages/merchant-backoffice-ui/src/paths/instance | |
parent | a9daad793cf66061e14fa4a847e1b595e26493e5 (diff) | |
download | wallet-core-635d710203bd88843ba16bbee7ab43ad02d295ca.tar.xz |
convert token family duration
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance')
-rw-r--r-- | packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx index 7ad18c01b..184e37b9c 100644 --- a/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx +++ b/packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx @@ -30,20 +30,29 @@ import { Input } from "../../../../components/form/Input.js"; import { InputDate } from "../../../../components/form/InputDate.js"; import { InputDuration } from "../../../../components/form/InputDuration.js"; import { AsyncButton } from "../../../../components/exception/AsyncButton.js"; -import { TalerMerchantApi } from "@gnu-taler/taler-util"; +import { Duration, TalerMerchantApi } from "@gnu-taler/taler-util"; -type Entity = TalerMerchantApi.TokenFamilyUpdateRequest; +type Entity = Omit<TalerMerchantApi.TokenFamilyUpdateRequest, "duration"> & { + duration: Duration, +}; interface Props { - onUpdate: (d: Entity) => Promise<void>; + onUpdate: (d: TalerMerchantApi.TokenFamilyUpdateRequest) => Promise<void>; onBack?: () => void; - tokenFamily: Entity; + tokenFamily: TalerMerchantApi.TokenFamilyUpdateRequest; +} + +function convert(from: TalerMerchantApi.TokenFamilyUpdateRequest) { + const { duration, ...rest } = from; + + const converted = { + duration: Duration.fromTalerProtocolDuration(duration), + }; + return { ...converted, ...rest }; } export function UpdatePage({ onUpdate, onBack, tokenFamily }: Props) { - const [value, valueHandler] = useState<Partial<Entity>>({ - ...tokenFamily, - }); + const [value, valueHandler] = useState<Partial<Entity>>(convert(tokenFamily)); let errors: FormErrors<Entity> = {}; try { @@ -67,7 +76,13 @@ export function UpdatePage({ onUpdate, onBack, tokenFamily }: Props) { const submitForm = () => { if (hasErrors) return Promise.reject(); - return onUpdate(value as Entity); + const { duration, ...rest } = value as Required<Entity>; + const result: TalerMerchantApi.TokenFamilyUpdateRequest = { + ...rest, + duration: Duration.toTalerProtocolDuration(duration), + }; + + return onUpdate(result); } const { i18n } = useTranslationContext(); |