Skip to content

Commit a337930

Browse files
authored
fix(regression): disable video uploads on welcome card logo uploader (formbricks#8188)
1 parent 605e5d7 commit a337930

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

apps/web/modules/survey/editor/components/edit-welcome-card.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,14 @@ export const EditWelcomeCard = ({
126126
id="welcome-card-image"
127127
allowedFileExtensions={["png", "jpeg", "jpg", "webp", "heic"]}
128128
workspaceId={workspaceId}
129-
onFileUpload={(url: string[] | undefined, fileType: "image" | "video") => {
129+
onFileUpload={(url: string[] | undefined) => {
130130
if (url?.length && url[0]) {
131-
const update =
132-
fileType === "video"
133-
? { videoUrl: url[0], fileUrl: undefined }
134-
: { fileUrl: url[0], videoUrl: undefined };
135-
updateSurvey(update);
131+
updateSurvey({ fileUrl: url[0], videoUrl: undefined });
136132
} else {
137133
updateSurvey({ fileUrl: undefined, videoUrl: undefined });
138134
}
139135
}}
140136
fileUrl={localSurvey?.welcomeCard?.fileUrl}
141-
videoUrl={localSurvey?.welcomeCard?.videoUrl}
142-
isVideoAllowed={true}
143137
maxSizeInMB={5}
144138
isStorageConfigured={isStorageConfigured}
145139
/>

apps/web/modules/ui/components/file-input/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,14 @@ export const FileInput = ({
6363
];
6464
const [selectedFiles, setSelectedFiles] = useState<SelectedFile[]>([]);
6565
const [uploadedVideoUrl, setUploadedVideoUrl] = useState(videoUrl ?? "");
66-
const [activeTab, setActiveTab] = useState(videoUrl ? "video" : "image");
66+
const [activeTab, setActiveTab] = useState(isVideoAllowed && videoUrl ? "video" : "image");
6767
const [imageUrlTemp, setImageUrlTemp] = useState(fileUrl ?? "");
6868
const [videoUrlTemp, setVideoUrlTemp] = useState(videoUrl ?? "");
69+
const fileType = isVideoAllowed && activeTab === "video" ? "video" : "image";
70+
71+
useEffect(() => {
72+
setActiveTab(isVideoAllowed && videoUrl ? "video" : "image");
73+
}, [isVideoAllowed, videoUrl]);
6974

7075
const handleUpload = async (files: File[]) => {
7176
if (!isStorageConfigured) {
@@ -115,7 +120,7 @@ export const FileInput = ({
115120
return;
116121
}
117122

118-
onFileUpload(uploadedUrls, activeTab === "video" ? "video" : "image");
123+
onFileUpload(uploadedUrls, fileType);
119124
};
120125

121126
const handleDragOver = (e: React.DragEvent<HTMLLabelElement>) => {
@@ -134,7 +139,7 @@ export const FileInput = ({
134139

135140
const handleRemove = async (idx: number) => {
136141
const newFileUrl = selectedFiles.filter((_, i) => i !== idx).map((file) => file.url);
137-
onFileUpload(newFileUrl, activeTab === "video" ? "video" : "image");
142+
onFileUpload(newFileUrl, fileType);
138143
setImageUrlTemp("");
139144
};
140145

@@ -185,7 +190,7 @@ export const FileInput = ({
185190
});
186191

187192
const prevUrls = Array.isArray(fileUrl) ? fileUrl : fileUrl ? [fileUrl] : [];
188-
onFileUpload([...prevUrls, ...uploadedUrls], activeTab === "video" ? "video" : "image");
193+
onFileUpload([...prevUrls, ...uploadedUrls], fileType);
189194
};
190195

191196
useEffect(() => {
@@ -202,23 +207,23 @@ export const FileInput = ({
202207
}, [fileUrl]);
203208

204209
useEffect(() => {
205-
if (activeTab === "image" && typeof imageUrlTemp === "string") {
210+
if (fileType === "image" && typeof imageUrlTemp === "string") {
206211
// Temporarily store the current video URL before switching tabs.
207212
setVideoUrlTemp(videoUrl ?? "");
208213

209214
if (imageUrlTemp) {
210215
onFileUpload([imageUrlTemp], "image");
211216
}
212-
} else if (activeTab === "video") {
217+
} else if (fileType === "video") {
213218
// Temporarily store the current image URL before switching tabs.
214219
setImageUrlTemp(fileUrl ?? "");
215220

216221
if (videoUrlTemp) {
217222
onFileUpload([videoUrlTemp], "video");
218223
}
219224
}
220-
// eslint-disable-next-line react-hooks/exhaustive-deps -- Only run when activeTab changes to avoid infinite loops
221-
}, [activeTab]);
225+
// eslint-disable-next-line react-hooks/exhaustive-deps -- Only run when file type changes to avoid loops
226+
}, [fileType]);
222227

223228
return (
224229
<div className="w-full cursor-default">
@@ -227,7 +232,7 @@ export const FileInput = ({
227232
<OptionsSwitch options={options} currentOption={activeTab} handleOptionChange={setActiveTab} />
228233
)}
229234
<div>
230-
{activeTab === "video" && (
235+
{fileType === "video" && (
231236
<div className={cn(isVideoAllowed && "rounded-b-lg border-x border-b border-slate-200 p-4")}>
232237
<VideoSettings
233238
uploadedVideoUrl={uploadedVideoUrl}
@@ -239,7 +244,7 @@ export const FileInput = ({
239244
</div>
240245
)}
241246

242-
{activeTab === "image" && (
247+
{fileType === "image" && (
243248
<div className={cn(isVideoAllowed && "rounded-b-lg border-x border-b border-slate-200 p-4")}>
244249
{selectedFiles.length > 0 ? (
245250
multiple ? (

0 commit comments

Comments
 (0)