From 3c6e9aaa639366ebc75c481c502a4e5656715401 Mon Sep 17 00:00:00 2001 From: Imamuzzaki Abu Salam Date: Tue, 6 Aug 2024 18:43:17 +0700 Subject: [PATCH] chore: Refactor CloseComSetup form submission logic (#16062) The commit refactors the form submission logic in the CloseComSetup component to use the URLSearchParams API for constructing the URL and removes unnecessary code. --- .../app-store/closecom/pages/setup/index.tsx | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/app-store/closecom/pages/setup/index.tsx b/packages/app-store/closecom/pages/setup/index.tsx index 789fdd2456..d5711484bd 100644 --- a/packages/app-store/closecom/pages/setup/index.tsx +++ b/packages/app-store/closecom/pages/setup/index.tsx @@ -66,16 +66,15 @@ export default function CloseComSetup() { form={form} handleSubmit={async (values) => { const { returnTo } = query; - const res = await fetch( - `/api/integrations/closecom/add${returnTo ? `?returnTo=${returnTo}` : ""}`, - { - method: "POST", - body: JSON.stringify(values), - headers: { - "Content-Type": "application/json", - }, - } - ); + const url = new URL("/api/integrations/closecom/add"); + if (returnTo) url.searchParams.append("returnTo", `${returnTo}`); + const res = await fetch(url.href, { + method: "POST", + body: JSON.stringify(values), + headers: { + "Content-Type": "application/json", + }, + }); const json = await res.json(); if (res.ok) {