Fix duplicate query param missing issue (#9328)
parent
6aa83102e4
commit
785a08ba2c
|
@ -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 });
|
||||
|
|
|
@ -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}`;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue