From 11827c30c154287834305af65f7bdb979ffedf41 Mon Sep 17 00:00:00 2001 From: Martin Dimitrov Date: Sun, 8 Jun 2025 11:49:53 -0700 Subject: [PATCH] fix misc --- .../doorman-client/src/utils/DoormanUtils.ts | 2 +- packages/doorman-ui/src/pages/EditPage.tsx | 42 +++++++++++-------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/packages/doorman-client/src/utils/DoormanUtils.ts b/packages/doorman-client/src/utils/DoormanUtils.ts index 367aed1..57268c4 100644 --- a/packages/doorman-client/src/utils/DoormanUtils.ts +++ b/packages/doorman-client/src/utils/DoormanUtils.ts @@ -9,7 +9,7 @@ export async function getConfig(context: TwilioContext, buzzer: string): Promise .then(res => res.json()) .catch(err => { return undefined; - }); + }) as InfoResponseClient; } export async function notifyDiscord(context: TwilioContext, msg: string[], u: string[], optionalJsonStr: string[], metricsRegistry: Registry){ diff --git a/packages/doorman-ui/src/pages/EditPage.tsx b/packages/doorman-ui/src/pages/EditPage.tsx index 4b1af6f..c64873a 100644 --- a/packages/doorman-ui/src/pages/EditPage.tsx +++ b/packages/doorman-ui/src/pages/EditPage.tsx @@ -6,6 +6,7 @@ import { InputTokenGroup } from "../components/InputTokenGroup"; import { ReactNode, useState } from "react"; import CInput from "react-hook-form-cloudscape/components/input"; import CTextArea from "react-hook-form-cloudscape/components/textarea"; +import { fetchUrlEncoded } from "../helpers/FetchHelper"; export type DoorEditForm = DoorResponse & { pin: string, fallbackNumber: string, discordUser: string, isConfirmed: boolean }; @@ -107,25 +108,30 @@ export const EditPage = ({ isOnboarding }: EditPageProps) => { timeout: parseInt("" + getValues("timeout")) }; - fetch(apiRoute + `?door=${door}&newConfig=${encodeURIComponent(JSON.stringify(form))}`) - .then(res => res.json()) - .then(res => { - if (res.err) { - addAlert("error", res.err); - return; - } - if (!isOnboarding) { - addAlert("success", `Created approval, check Discord notifcation from Doorman to confirm and approve the changes`); - } else if (res.redirect) { - // redirect for discord login - addAlert("in-progress", `Created Door, you will now be redirected to Discord login to complete the onboarding`); + const body = { + door, + newConfig: JSON.stringify(form), + }; - // redirect in 2 seconds - setTimeout(() => { - window.location = res.redirect; - }, 2_000); - } - }) + fetchUrlEncoded(apiRoute, body) + .then(res => res.json()) + .then(res => { + if (res.err) { + addAlert("error", res.err); + return; + } + if (!isOnboarding) { + addAlert("success", `Created approval, check Discord notifcation from Doorman to confirm and approve the changes`); + } else if (res.redirect) { + // redirect for discord login + addAlert("in-progress", `Created Door, you will now be redirected to Discord login to complete the onboarding`); + + // redirect in 2 seconds + setTimeout(() => { + window.location = res.redirect; + }, 2_000); + } + }); }} > Submit