Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Fix file input clear

Edward Cui81401da8990b
diff --git a/client/src/components/SiteSettings/ImportManager.tsx b/client/src/components/SiteSettings/ImportManager.tsx
index 61c9aa8f5..d519f1963 100644
--- a/client/src/components/SiteSettings/ImportManager.tsx
+++ b/client/src/components/SiteSettings/ImportManager.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useState, useCallback, useMemo } from "react";
+import { useState, useCallback, useMemo, useRef } from "react";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
@@ -59,6 +59,8 @@ export function ImportManager({ siteId, disabled }: ImportManagerProps) {
const [fileError, setFileError] = useState<FileValidationError | null>(null);
const [showConfirmDialog, setShowConfirmDialog] = useState(false);
+ const fileInputRef = useRef<HTMLInputElement>(null);
+
const { data, isLoading, error } = useGetSiteImports(siteId);
const mutation = useImportSiteData(siteId);
@@ -132,9 +134,9 @@ export function ImportManager({ siteId, disabled }: ImportManagerProps) {
});
setFile(null);
setShowConfirmDialog(false);
- // Clear the file input
- const fileInput = document.getElementById("file") as HTMLInputElement;
- if (fileInput) fileInput.value = "";
+ if (fileInputRef.current) {
+ fileInputRef.current.value = "";
+ }
}
}, [file, source, dateRange, mutation]);
@@ -235,6 +237,7 @@ export function ImportManager({ siteId, disabled }: ImportManagerProps) {
CSV File
</Label>
<Input
+ ref={fileInputRef}
id="file"
type="file"
accept=".csv"