restrict input to just csv file

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-13 14:09:03 +01:00
parent 3b66371bb1
commit 7aa3c930da

View file

@ -90,18 +90,29 @@ export function InputFile({
fundingScheme: string;
goalValue: string;
}) {
function handleOnChange(e: React.ChangeEvent<HTMLInputElement>) {
if (e.target.files) {
// Check if files is not null
const file = e.target.files[0];
if (file.type !== "text/csv") {
// Show an error message
console.error("File is not a CSV");
return;
}
setCsvFile(file); // Assuming you have a state to keep the file
handleButtonDisabled(selectedGoal, fundingScheme, goalValue, file);
}
}
return (
<div className="grid w-full max-w-sm items-center gap-1.5 text-sm font-semibold text-gray-600">
<Label htmlFor="csv-uploader">Upload your csv</Label>
<Input
id="csv-uploader"
type="file"
accept=".csv, text/csv"
className="cursor-pointer"
onChange={(event) => {
const file = event.target.files[0];
setCsvFile(file); // Assuming you have a state to keep the file
handleButtonDisabled(selectedGoal, fundingScheme, goalValue, file);
}}
onChange={handleOnChange}
/>
</div>
);