FOR-201 fix hqUrl in feedback and pmf widget to work with trailing slash

This commit is contained in:
Matthias Nannt
2023-01-30 13:42:59 +01:00
parent b8fd9ee624
commit 067022e69c
3 changed files with 41 additions and 20 deletions

View File

@@ -226,6 +226,10 @@ function changeType(e: Event) {
}
}
const stripLastBackslash = (url: string) => {
return url.endsWith("/") ? url.slice(0, -1) : url;
};
function submit(e: Event) {
e.preventDefault();
const target = e.target as HTMLFormElement;
@@ -253,11 +257,16 @@ function submit(e: Event) {
finished: true,
};
fetch(`${config.hqUrl || "https://xm.formbricks.com"}/api/capture/forms/${config.formId}/submissions`, {
method: "POST",
headers,
body: JSON.stringify(body),
})
fetch(
`${stripLastBackslash(config.hqUrl || "https://xm.formbricks.com")}/api/capture/forms/${
config.formId
}/submissions`,
{
method: "POST",
headers,
body: JSON.stringify(body),
}
)
.then(() => {
containerElement.setAttribute("data-success", "");
const feedbackType = containerElement.getAttribute("data-feedback-type");

View File

@@ -161,20 +161,27 @@ async function submitElement(name?: string, value?: string) {
}
}
const stripLastBackslash = (url: string) => {
return url.endsWith("/") ? url.slice(0, -1) : url;
};
async function createSubmission(submission: any) {
if (!config.formId) {
throw new Error("Missing formId");
}
const response = await fetch(`${config.formbricksUrl}/api/capture/forms/${config.formId}/submissions`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
customer: config.customer,
data: submission,
}),
});
const response = await fetch(
`${stripLastBackslash(config.formbricksUrl)}/api/capture/forms/${config.formId}/submissions`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
customer: config.customer,
data: submission,
}),
}
);
return response.json();
}
@@ -189,7 +196,9 @@ async function updateSubmission(submissionId: string, submission: any, finished:
body["finished"] = true;
}
const response = await fetch(
`${config.formbricksUrl}/api/capture/forms/${config.formId}/submissions/${submissionId}`,
`${stripLastBackslash(config.formbricksUrl)}/api/capture/forms/${
config.formId
}/submissions/${submissionId}`,
{
method: "PUT",
headers: {
@@ -205,9 +214,12 @@ async function sendWarmupRequest() {
if (!config.formId) {
throw new Error("Missing formId");
}
const response = await fetch(`${config.formbricksUrl}/api/capture/forms/${config.formId}/submissions`, {
method: "OPTIONS",
});
const response = await fetch(
`${stripLastBackslash(config.formbricksUrl)}/api/capture/forms/${config.formId}/submissions`,
{
method: "OPTIONS",
}
);
return;
}

View File

@@ -45,7 +45,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonPr
const isLink = typeof props.href !== "undefined";
const elementType = isLink ? "span" : "button";
const element = React.createElement(
const element: any = React.createElement(
elementType,
{
...passThroughProps,