Scheduling infrastructure for absolutely everyone.
Fix duplicate query param missing issue (#9328)
Hariom Balhara785a08ba2ca5
diff --git a/apps/web/lib/hooks/useRouterQuery.ts b/apps/web/lib/hooks/useRouterQuery.tsindex 155d991cd03..72d1072fcc9 100644--- a/apps/web/lib/hooks/useRouterQuery.ts+++ b/apps/web/lib/hooks/useRouterQuery.ts@@ -5,7 +5,25 @@ export default function useRouterQuery<T extends string>(name: T) {const existingQueryParams = router.asPath.split("?")[1];const urlParams = new URLSearchParams(existingQueryParams);- const query = Object.fromEntries(urlParams);+ const query: Record<string, string | string[]> = {};+ // Following error is thrown by Typescript:+ // 'Type 'URLSearchParams' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher'+ // We should change the target to higher ES2019 atleast maybe+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-expect-error+ for (const [key, value] of urlParams) {+ if (!query[key]) {+ query[key] = value;+ } else {+ let queryValue = query[key];+ if (queryValue instanceof Array) {+ queryValue.push(value);+ } else {+ queryValue = query[key] = [queryValue];+ queryValue.push(value);+ }+ }+ }const setQuery = (newValue: string | number | null | undefined) => {router.replace({ query: { ...router.query, [name]: newValue } }, undefined, { shallow: true });diff --git a/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx b/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsxindex c63a6f61b4a..ab0191e4aa9 100644--- a/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx+++ b/packages/app-store/routing-forms/pages/routing-link/[...appPages].tsx@@ -82,7 +82,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {}, [customPageMessage]);const responseMutation = trpc.viewer.appRoutingForms.public.response.useMutation({- onSuccess: () => {+ onSuccess: async () => {const decidedActionWithFormResponse = decidedActionWithFormResponseRef.current;if (!decidedActionWithFormResponse) {return;@@ -98,7 +98,7 @@ function RoutingForm({ form, profile, ...restProps }: Props) {if (decidedAction.type === "customPageMessage") {setCustomPageMessage(decidedAction.value);} else if (decidedAction.type === "eventTypeRedirectUrl") {- router.push(`/${decidedAction.value}?${allURLSearchParams}`);+ await router.push(`/${decidedAction.value}?${allURLSearchParams}`);} else if (decidedAction.type === "externalRedirectUrl") {window.parent.location.href = `${decidedAction.value}?${allURLSearchParams}`;}