mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-18 19:41:17 -05:00
Ensure Type Safety for inputType
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import React, { useState } from "react";
|
||||
import { TSurveyOpenTextQuestion, TSurveyWithAnalytics } from "@formbricks/types/v1/surveys";
|
||||
import {
|
||||
TSurveyOpenTextQuestion,
|
||||
TSurveyOpenTextQuestionInputType,
|
||||
TSurveyWithAnalytics,
|
||||
} from "@formbricks/types/v1/surveys";
|
||||
import { Button, Input, Label, QuestionTypeSelector } from "@formbricks/ui";
|
||||
import { TrashIcon, PlusIcon } from "@heroicons/react/24/solid";
|
||||
|
||||
@@ -29,7 +33,7 @@ export default function OpenQuestionForm({
|
||||
const [showSubheader, setShowSubheader] = useState(!!question.subheader);
|
||||
const defaultPlaceholder = getPlaceholderByInputType(question.inputType ?? "text");
|
||||
|
||||
const handleInputChange = (inputType: string) => {
|
||||
const handleInputChange = (inputType: TSurveyOpenTextQuestionInputType) => {
|
||||
const updatedAttributes = {
|
||||
inputType: inputType,
|
||||
placeholder: getPlaceholderByInputType(inputType),
|
||||
@@ -110,7 +114,7 @@ export default function OpenQuestionForm({
|
||||
);
|
||||
}
|
||||
|
||||
function getPlaceholderByInputType(inputType: string) {
|
||||
function getPlaceholderByInputType(inputType: TSurveyOpenTextQuestionInputType) {
|
||||
switch (inputType) {
|
||||
case "email":
|
||||
return "example@email.com";
|
||||
|
||||
@@ -162,12 +162,15 @@ const ZSurveyQuestionBase = z.object({
|
||||
isDraft: z.boolean().optional(),
|
||||
});
|
||||
|
||||
export const ZSurveyOpenTextQuestionInputType = z.enum(["text", "email", "url", "number", "phone"]);
|
||||
export type TSurveyOpenTextQuestionInputType = z.infer<typeof ZSurveyOpenTextQuestionInputType>;
|
||||
|
||||
export const ZSurveyOpenTextQuestion = ZSurveyQuestionBase.extend({
|
||||
type: z.literal(QuestionType.OpenText),
|
||||
placeholder: z.string().optional(),
|
||||
longAnswer: z.boolean().optional(),
|
||||
logic: z.array(ZSurveyOpenTextLogic).optional(),
|
||||
inputType: z.enum(["text", "email", "url", "number", "phone"]).optional().default("text"),
|
||||
inputType: ZSurveyOpenTextQuestionInputType.optional().default("text"),
|
||||
});
|
||||
|
||||
export type TSurveyOpenTextQuestion = z.infer<typeof ZSurveyOpenTextQuestion>;
|
||||
|
||||
Reference in New Issue
Block a user