Compare commits

...

5 Commits

Author SHA1 Message Date
pandeymangg
4327319d75 fix: placeholder 2024-07-03 12:33:05 +05:30
pandeymangg
dc4f146983 fixed the cal.com host not configured 2024-07-03 12:18:24 +05:30
pandeymangg
0ed6401df7 Merge remote-tracking branch 'origin/main' into aschaber-cal 2024-07-03 11:11:19 +05:30
Matti Nannt
e856006e04 Merge branch 'main' into feature/custom-calcom-host 2024-06-25 15:34:10 +02:00
Alexander Schaber
01210dba3f feat(calcom): add custom cal.com field
Closes: #2654
2024-06-23 16:50:14 +02:00
6 changed files with 56 additions and 11 deletions

View File

@@ -1,8 +1,10 @@
import { PlusIcon } from "lucide-react";
import { useEffect, useState } from "react";
import { createI18nString, extractLanguageCodes } from "@formbricks/lib/i18n/utils";
import { TAttributeClass } from "@formbricks/types/attributeClasses";
import { TSurvey, TSurveyCalQuestion } from "@formbricks/types/surveys";
import { Button } from "@formbricks/ui/Button";
import { Checkbox } from "@formbricks/ui/Checkbox";
import { Input } from "@formbricks/ui/Input";
import { Label } from "@formbricks/ui/Label";
import { QuestionFormInput } from "@formbricks/ui/QuestionFormInput";
@@ -30,6 +32,15 @@ export const CalQuestionForm = ({
attributeClasses,
}: CalQuestionFormProps): JSX.Element => {
const surveyLanguageCodes = extractLanguageCodes(localSurvey.languages);
const [isCalHostEnabled, setIsCalHostEnabled] = useState(!!question.calHost);
useEffect(() => {
if (!isCalHostEnabled) {
updateQuestion(questionIdx, { calHost: undefined });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isCalHostEnabled]);
return (
<form>
@@ -80,15 +91,41 @@ export const CalQuestionForm = ({
Add Description
</Button>
)}
<div className="mt-3">
<Label htmlFor="calUserName">Add your Cal.com username or username/event</Label>
<div className="mt-2">
<Input
id="calUserName"
name="calUserName"
value={question.calUserName}
onChange={(e) => updateQuestion(questionIdx, { calUserName: e.target.value })}
/>
<div className="mt-3 flex flex-col gap-4">
<div className="flex flex-col gap-3">
<Label htmlFor="calUserName">Add your Cal.com username or username/event</Label>
<div>
<Input
id="calUserName"
name="calUserName"
value={question.calUserName}
onChange={(e) => updateQuestion(questionIdx, { calUserName: e.target.value })}
/>
</div>
</div>
<div className="flex flex-col gap-4">
<div className="flex items-center gap-2">
<Checkbox
id="calHost"
checked={isCalHostEnabled}
onCheckedChange={(checked: boolean) => setIsCalHostEnabled(checked)}
/>
<Label htmlFor="calHost">Do you have a self-hosted Cal.com instance?</Label>
</div>
{isCalHostEnabled && (
<div className="flex flex-col gap-2">
<Label htmlFor="calHost">Enter the hostname of your self-hosted Cal.com instance</Label>
<Input
id="calHost"
name="calHost"
placeholder="cal.com"
value={question.calHost}
onChange={(e) => updateQuestion(questionIdx, { calHost: e.target.value })}
/>
</div>
)}
</div>
</div>
</div>

View File

@@ -185,6 +185,7 @@ 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

@@ -228,6 +228,7 @@ export const mockCalQuestion: TSurveyCalQuestion = {
default: "Skip",
},
calUserName: "rick/get-rick-rolled",
calHost: "cal.com",
id: "o3bnux6p42u9ew9d02l14r26",
type: TSurveyQuestionTypeEnum.Cal,
isDraft: true,

View File

@@ -44,8 +44,12 @@ export const CalEmbed = ({ question, onSuccessfulBooking }: CalEmbedProps) => {
useEffect(() => {
// remove any existing cal-inline elements
document.querySelectorAll("cal-inline").forEach((el) => el.remove());
cal("inline", { elementOrSelector: "#fb-cal-embed", calLink: question.calUserName });
}, [cal, question.calUserName]);
cal("init", { calOrigin: question.calHost ? `https://${question.calHost}` : "https://cal.com" });
cal("inline", {
elementOrSelector: "#fb-cal-embed",
calLink: question.calUserName,
});
}, [cal, question.calHost, question.calUserName]);
return (
<div className="fb-relative fb-mt-4 fb-overflow-auto">

View File

@@ -136,6 +136,7 @@ export type TLegacySurveyFileUploadQuestion = z.infer<typeof ZLegacySurveyFileUp
export const ZLegacySurveyCalQuestion = ZLegacySurveyQuestionBase.extend({
type: z.literal(TSurveyQuestionTypeEnum.Cal),
calUserName: z.string(),
calHost: z.string().optional(),
logic: z.array(ZSurveyCalLogic).optional(),
});

View File

@@ -385,6 +385,7 @@ export type TSurveyFileUploadQuestion = z.infer<typeof ZSurveyFileUploadQuestion
export const ZSurveyCalQuestion = ZSurveyQuestionBase.extend({
type: z.literal(TSurveyQuestionTypeEnum.Cal),
calUserName: z.string(),
calHost: z.string().optional(),
logic: z.array(ZSurveyCalLogic).optional(),
});