diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/tokenfamilies/update/UpdatePage.tsx')
-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(); |