mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-30 10:19:51 -06:00
fix: simplify redirect of URL in Environment Notice Component (#1598)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
This commit is contained in:
committed by
GitHub
parent
b28f6f4bb2
commit
45fbdd58af
@@ -34,7 +34,7 @@ export default async function ProfileSettingsPage({ params }) {
|
||||
return !isViewer ? (
|
||||
<div>
|
||||
<SettingsTitle title="API Keys" />
|
||||
<EnvironmentNotice environmentId={environment.id} />
|
||||
<EnvironmentNotice environmentId={environment.id} subPageUrl="/settings/api-keys" />
|
||||
{environment.type === "development" ? (
|
||||
<SettingsCard
|
||||
title="Development Env Keys"
|
||||
|
||||
@@ -10,7 +10,7 @@ export default async function ProfileSettingsPage({ params }) {
|
||||
<>
|
||||
<div className="space-y-4">
|
||||
<SettingsTitle title="Setup Checklist" />
|
||||
<EnvironmentNotice environmentId={params.environmentId} />
|
||||
<EnvironmentNotice environmentId={params.environmentId} subPageUrl="/settings/setup" />
|
||||
<SettingsCard
|
||||
title="Widget Status"
|
||||
description="Check if the Formbricks widget is alive and kicking.">
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
import { WEBAPP_URL } from "@formbricks/lib/constants";
|
||||
import { getEnvironment, getEnvironments } from "@formbricks/lib/environment/service";
|
||||
import { LightBulbIcon } from "@heroicons/react/24/outline";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
interface EnvironmentNoticeProps {
|
||||
environmentId: string;
|
||||
subPageUrl: string;
|
||||
}
|
||||
|
||||
export default async function EnvironmentNotice({ environmentId }: EnvironmentNoticeProps) {
|
||||
const headersList = headers();
|
||||
const currentUrl = headersList.get("referer") || headersList.get("x-invoke-path") || "";
|
||||
export default async function EnvironmentNotice({ environmentId, subPageUrl }: EnvironmentNoticeProps) {
|
||||
const environment = await getEnvironment(environmentId);
|
||||
if (!environment) {
|
||||
throw new Error("Environment not found");
|
||||
}
|
||||
|
||||
const environments = await getEnvironments(environment.productId);
|
||||
const otherEnvironmentId = environments.find((e) => e.id !== environment.id)?.id || "";
|
||||
|
||||
const replaceEnvironmentId = (url: string, newId: string): string => {
|
||||
const regex = /environments\/([a-zA-Z0-9]+)/;
|
||||
if (regex.test(url)) {
|
||||
return url.replace(regex, `environments/${newId}`);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
const otherEnvironmentId = environments.filter((e) => e.id !== environment.id)[0].id;
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -32,7 +23,7 @@ export default async function EnvironmentNotice({ environmentId }: EnvironmentNo
|
||||
<p>
|
||||
{`You're currently in the ${environment.type} environment.`}
|
||||
<a
|
||||
href={replaceEnvironmentId(currentUrl, otherEnvironmentId)}
|
||||
href={`${WEBAPP_URL}/environments/${otherEnvironmentId}${subPageUrl}`}
|
||||
className="ml-1 cursor-pointer text-sm underline">
|
||||
Switch to {environment.type === "production" ? "Development" : "Production"} now.
|
||||
</a>
|
||||
|
||||
Reference in New Issue
Block a user