mirror of
https://github.com/formbricks/formbricks.git
synced 2026-05-07 14:21:52 -05:00
feat: Ability to startAt specific question (#2175)
Co-authored-by: Piyush Gupta <piyushguptaa2z123@gmail.com>
This commit is contained in:
@@ -50,11 +50,28 @@ export default function LinkSurvey({
|
||||
const isPreview = searchParams?.get("preview") === "true";
|
||||
const sourceParam = searchParams?.get("source");
|
||||
const suId = searchParams?.get("suId");
|
||||
const startAt = searchParams?.get("startAt");
|
||||
|
||||
const isStartAtValid = useMemo(() => {
|
||||
if (!startAt) return false;
|
||||
if (survey?.welcomeCard.enabled && startAt === "start") return true;
|
||||
|
||||
const isValid = survey?.questions.some((question) => question.id === startAt);
|
||||
|
||||
// To remove startAt query param from URL if it is not valid:
|
||||
if (!isValid && typeof window !== "undefined") {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete("startAt");
|
||||
window.history.replaceState({}, "", url.toString());
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}, [survey, startAt]);
|
||||
|
||||
// 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));
|
||||
const [activeQuestionId, setActiveQuestionId] = useState<string>(
|
||||
survey.welcomeCard.enabled ? "start" : survey?.questions[0]?.id
|
||||
startAt && isStartAtValid ? startAt : survey.welcomeCard.enabled ? "start" : survey?.questions[0]?.id
|
||||
);
|
||||
|
||||
const prefillResponseData: TResponseData | undefined = prefillAnswer
|
||||
|
||||
Reference in New Issue
Block a user