Fix Link Survey not pulling the right product (#726)

This commit is contained in:
Matti Nannt
2023-08-22 17:07:05 +02:00
committed by GitHub
parent 6538f8abdc
commit 4562d85974
2 changed files with 9 additions and 7 deletions

View File

@@ -8,18 +8,17 @@ import { getProductByEnvironmentId } from "@formbricks/lib/services/product";
import SurveyInactive from "@/app/s/[surveyId]/SurveyInactive";
export default async function LinkSurveyPage({ params }) {
const [survey, product] = await Promise.all([
getSurvey(params.surveyId),
getProductByEnvironmentId(params.environmentId),
]);
const survey = await getSurvey(params.surveyId);
if (!survey) {
return <SurveyInactive status="not found" />;
}
if (survey && survey.status !== "inProgress") {
return <SurveyInactive status={survey.status} surveyClosedMessage={survey.surveyClosedMessage} />;
}
if (survey === null) {
return <SurveyInactive status="not found" />;
}
const product = await getProductByEnvironmentId(survey.environmentId);
return (
<>

View File

@@ -23,6 +23,9 @@ const selectProduct = {
};
export const getProductByEnvironmentId = cache(async (environmentId: string): Promise<TProduct> => {
if (!environmentId) {
throw new ValidationError("EnvironmentId is required");
}
let productPrisma;
try {
productPrisma = await prisma.product.findFirst({