mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-04 10:30:00 -06:00
fix: setting duplicate question Ids now does not set random ID when click saved, the user has to update it
This commit is contained in:
@@ -45,8 +45,8 @@ export default function SurveyMenuBar({
|
||||
const { product } = useProduct(environmentId);
|
||||
let faultyQuestions: String[] = [];
|
||||
const existingLogicConditions = new Set();
|
||||
const existingQuestionIds = new Set();
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (audiencePrompt && activeId === "settings") {
|
||||
setAudiencePrompt(false);
|
||||
@@ -118,6 +118,11 @@ export default function SurveyMenuBar({
|
||||
}
|
||||
|
||||
for (const question of survey.questions) {
|
||||
if (existingQuestionIds.has(question.id)) {
|
||||
toast.error("You cannot have 2 same question IDs, please change one!");
|
||||
return false;
|
||||
}
|
||||
existingQuestionIds.add(question.id);
|
||||
for (const logic of question.logic || []) {
|
||||
if (question.required && logic.condition === "skipped") {
|
||||
toast.error("User cannot skip a required question, please change the logic jump!");
|
||||
|
||||
@@ -7,6 +7,9 @@ import toast from "react-hot-toast";
|
||||
export default function UpdateQuestionId({ localSurvey, question, questionIdx, updateQuestion }) {
|
||||
const [currentValue, setCurrentValue] = useState(question.id);
|
||||
const [prevValue, setPrevValue] = useState(question.id);
|
||||
const [isInputInvalid, setIsInputInvalid] = useState(
|
||||
currentValue.trim() === "" || currentValue.includes(" ")
|
||||
);
|
||||
|
||||
const saveAction = () => {
|
||||
// return early if the input value was not changed
|
||||
@@ -14,28 +17,22 @@ export default function UpdateQuestionId({ localSurvey, question, questionIdx, u
|
||||
return;
|
||||
}
|
||||
|
||||
// check if id is unique
|
||||
const questionIds = localSurvey.questions.map((q) => q.id);
|
||||
if (questionIds.includes(currentValue)) {
|
||||
setIsInputInvalid(true);
|
||||
toast.error("IDs have to be unique per survey.");
|
||||
setCurrentValue(question.id);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if id contains any spaces
|
||||
if (currentValue.trim() === "" || currentValue.includes(" ")) {
|
||||
} else if (currentValue.trim() === "" || currentValue.includes(" ")) {
|
||||
setIsInputInvalid(true);
|
||||
toast.error("ID should not contain space.");
|
||||
setCurrentValue(question.id);
|
||||
return;
|
||||
} else {
|
||||
setIsInputInvalid(false);
|
||||
toast.success("Question ID updated.");
|
||||
}
|
||||
|
||||
updateQuestion(questionIdx, { id: currentValue });
|
||||
toast.success("Question ID updated.");
|
||||
setPrevValue(currentValue); // after successful update, set current value as previous value
|
||||
};
|
||||
|
||||
const isInputInvalid = currentValue.trim() === "" || currentValue.includes(" ");
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Label htmlFor="questionId">Question ID</Label>
|
||||
|
||||
Reference in New Issue
Block a user