fix: calHost UX and validation in cal question (#2944)

This commit is contained in:
Dhruwang Jariwala
2024-08-01 19:57:14 +05:30
committed by GitHub
parent c1492e3429
commit 864d4b3cb7
3 changed files with 15 additions and 1 deletions

View File

@@ -37,6 +37,8 @@ export const CalQuestionForm = ({
useEffect(() => {
if (!isCalHostEnabled) {
updateQuestion(questionIdx, { calHost: undefined });
} else {
updateQuestion(questionIdx, { calHost: question.calHost ?? "cal.com" });
}
// eslint-disable-next-line react-hooks/exhaustive-deps

View File

@@ -185,7 +185,6 @@ export const questionTypes: TQuestion[] = [
preset: {
headline: { default: "Schedule a call with me" },
calUserName: "rick/get-rick-rolled",
calHost: "cal.com",
} as Partial<TSurveyCalQuestion>,
},
{

View File

@@ -854,6 +854,19 @@ export const ZSurvey = z
}
}
if (question.type === TSurveyQuestionTypeEnum.Cal) {
if (question.calHost !== undefined) {
const hostnameRegex = /^[a-zA-Z0-9]+(?<domain>\.[a-zA-Z0-9]+)+$/;
if (!hostnameRegex.test(question.calHost)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: `Question ${String(questionIndex + 1)} must have a valid host name`,
path: ["questions", questionIndex, "calHost"],
});
}
}
}
if (question.logic) {
question.logic.forEach((logic, logicIndex) => {
const logicConditions = ["condition", "value", "destination"] as const;