diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/actions.ts b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/actions.ts new file mode 100644 index 0000000000..994ea7cca2 --- /dev/null +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/actions.ts @@ -0,0 +1,21 @@ +"use server"; + +import { getServerSession } from "next-auth"; +import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions"; +import { sendEmbedSurveyPreviewEmail } from "@formbricks/lib/emails/emails"; +import { AuthenticationError } from "@formbricks/types/v1/errors"; + +type TSendEmailActionArgs = { + to: string; + subject: string; + html: string; +}; + +export const sendEmailAction = async ({ html, subject, to }: TSendEmailActionArgs) => { + const session = await getServerSession(authOptions); + + if (!session) { + throw new AuthenticationError("Not authenticated"); + } + return await sendEmbedSurveyPreviewEmail(to, subject, html); +}; diff --git a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx index c45e991e09..3846898e27 100644 --- a/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx +++ b/apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/summary/components/ShareEmbedSurvey.tsx @@ -63,7 +63,9 @@ export default function ShareEmbedSurvey({