Skip to content

Commit

Permalink
fix: single use survey not working with email verification (#1935)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
  • Loading branch information
Dhruwang and mattinannt committed Jan 26, 2024
1 parent 1fb165e commit 6dcd065
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": ["dbaeumer.vscode-eslint"],
},
"extensions": ["dbaeumer.vscode-eslint"]
}
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand All @@ -25,5 +25,5 @@
"postAttachCommand": "pnpm dev --filter=web... --filter=demo...",

// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"remoteUser": "node"
}
3 changes: 2 additions & 1 deletion apps/formbricks-com/pages/api/oss-friends/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default async function handle(req: NextApiRequest, res: NextApiResponse)
},
{
name: "Aptabase",
description: "Analytics for Apps, open source, simple and privacy-friendly. SDKs for Swift, React Native, Electron, Flutter and many others.",
description:
"Analytics for Apps, open source, simple and privacy-friendly. SDKs for Swift, React Native, Electron, Flutter and many others.",
href: "https://aptabase.com",
},
{
Expand Down
3 changes: 2 additions & 1 deletion apps/web/app/s/[surveyId]/components/LinkSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function LinkSurvey({
const searchParams = useSearchParams();
const isPreview = searchParams?.get("preview") === "true";
const sourceParam = searchParams?.get("source");
const suId = searchParams?.get("suId");

// pass in the responseId if the survey is a single use survey, ensures survey state is updated with the responseId
const [surveyState, setSurveyState] = useState(new SurveyState(survey.id, singleUseId, responseId, userId));
Expand Down Expand Up @@ -129,7 +130,7 @@ export default function LinkSurvey({
return <VerifyEmail survey={survey} isErrorComponent={true} />;
}
//emailVerificationStatus === "not-verified"
return <VerifyEmail survey={survey} />;
return <VerifyEmail singleUseId={suId ?? ""} survey={survey} />;
}

return (
Expand Down
3 changes: 3 additions & 0 deletions apps/web/app/s/[surveyId]/components/VerifyEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ const StackedCardsContainer = ({ children }) => (
export default function VerifyEmail({
survey,
isErrorComponent,
singleUseId,
}: {
survey: TSurvey;
isErrorComponent?: boolean;
singleUseId?: string;
}) {
const [showPreviewQuestions, setShowPreviewQuestions] = useState(false);
const [email, setEmail] = useState<string | null>(null);
Expand All @@ -44,6 +46,7 @@ export default function VerifyEmail({
surveyId: survey.id,
email: email,
surveyData: survey.verifyEmail,
suId: singleUseId ?? "",
};
try {
await sendLinkSurveyEmailAction(data);
Expand Down
11 changes: 9 additions & 2 deletions packages/lib/emails/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ interface TEmailUserWithName extends TEmailUser {
export interface LinkSurveyEmailData {
surveyId: string;
email: string;
suId: string;
surveyData?: {
name?: string;
subheading?: string;
Expand Down Expand Up @@ -249,16 +250,22 @@ export const sendLinkSurveyToVerifiedEmail = async (data: LinkSurveyEmailData) =
const surveyId = data.surveyId;
const email = data.email;
const surveyData = data.surveyData;
const singleUseId = data.suId ?? null;
const token = createTokenForLinkSurvey(surveyId, email);
const surveyLink = `${WEBAPP_URL}/s/${surveyId}?verify=${encodeURIComponent(token)}`;
const getSurveyLink = () => {
if (singleUseId) {
return `${WEBAPP_URL}/s/${surveyId}?verify=${encodeURIComponent(token)}&suId=${singleUseId}`;
}
return `${WEBAPP_URL}/s/${surveyId}?verify=${encodeURIComponent(token)}`;
};
await sendEmail({
to: data.email,
subject: "Your Formbricks Survey",
html: withEmailTemplate(`<h1>Hey 👋</h1>
Thanks for validating your email. Here is your Survey.<br/><br/>
<strong>${surveyData?.name}</strong>
<p>${surveyData?.subheading}</p>
<a class="button" href="${surveyLink}">Take survey</a><br/>
<a class="button" href="${getSurveyLink()}">Take survey</a><br/>
<br/>
All the best,<br/>
Your Formbricks Team 🤍`),
Expand Down
1 change: 1 addition & 0 deletions packages/lib/response/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export const createResponse = async (responseInput: TResponseInput): Promise<TRe
id: response.id,
personId: response.person?.id,
surveyId: response.surveyId,
singleUseId: singleUseId ? singleUseId : undefined,
});

responseNoteCache.revalidate({
Expand Down
4 changes: 2 additions & 2 deletions packages/lib/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"include": ["."],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"downlevelIteration": true,
},
"downlevelIteration": true
}
}
4 changes: 2 additions & 2 deletions packages/ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"include": ["."],
"exclude": ["build", "node_modules"],
"compilerOptions": {
"lib": ["ES2021.String"],
},
"lib": ["ES2021.String"]
}
}

2 comments on commit 6dcd065

@vercel
Copy link

@vercel vercel bot commented on 6dcd065 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

formbricks-com – ./apps/formbricks-com

formbricks-com.vercel.app
formbricks-com-formbricks.vercel.app
formbricks.com
formbricks-com-git-main-formbricks.vercel.app
www.formbricks.com

@vercel
Copy link

@vercel vercel bot commented on 6dcd065 Jan 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.