aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx')
-rw-r--r--packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx36
1 files changed, 21 insertions, 15 deletions
diff --git a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx
index e0e0ba7ed..9514ed0dc 100644
--- a/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx
+++ b/packages/merchant-backoffice-ui/src/paths/instance/accounts/update/UpdatePage.tsx
@@ -49,8 +49,14 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode {
const [state, setState] = useState<Partial<MerchantBackend.BankAccounts.AccountPatchDetails>>(account);
+ // @ts-expect-error "unedit" is fine since is part of the accountAuthType values
+ if (state.credit_facade_credentials?.type === "unedit") {
+ // we use this to set creds to undefined but server don't get this type
+ state.credit_facade_credentials = undefined
+ }
+
const errors: FormErrors<MerchantBackend.BankAccounts.AccountPatchDetails> = {
- credit_facade_url: !state.credit_facade_url ? i18n.str`required` : !isValidURL(state.credit_facade_url) ? i18n.str`invalid url` : undefined,
+ credit_facade_url: !state.credit_facade_url ? undefined : !isValidURL(state.credit_facade_url) ? i18n.str`invalid url` : undefined,
credit_facade_credentials: undefinedIfEmpty({
username: state.credit_facade_credentials?.type !== "basic" ? undefined
@@ -73,19 +79,19 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode {
const submitForm = () => {
if (hasErrors) return Promise.reject();
- const creds: typeof state.credit_facade_credentials =
- state.credit_facade_credentials?.type === "basic" ? {
- type: "basic",
- password: state.credit_facade_credentials.password,
- username: state.credit_facade_credentials.username,
- } : state.credit_facade_credentials?.type === "none" ? {
- type: "none"
- } : undefined;
-
- return onUpdate({
- credit_facade_credentials: creds,
- credit_facade_url: state.credit_facade_url,
- });
+ const credit_facade_url = !state.credit_facade_url ? undefined : new URL("/", state.credit_facade_url).href
+
+ const credit_facade_credentials: MerchantBackend.BankAccounts.FacadeCredentials | undefined =
+ credit_facade_url == undefined || state.credit_facade_credentials === undefined ? undefined :
+ state.credit_facade_credentials.type === "basic" ? {
+ type: "basic",
+ password: state.credit_facade_credentials.password,
+ username: state.credit_facade_credentials.username,
+ } : {
+ type: "none"
+ };
+
+ return onUpdate({ credit_facade_credentials, credit_facade_url });
};
return (
@@ -187,7 +193,7 @@ export function UpdatePage({ account, onUpdate, onBack }: Props): VNode {
function isValidURL(s: string): boolean {
try {
- const u = new URL(s)
+ const u = new URL("/", s)
return true;
} catch (e) {
return false;