adding file name validation

This commit is contained in:
2026-01-05 10:30:26 -07:00
parent 8c01cb2422
commit 767528560c
5 changed files with 63 additions and 48 deletions

View File

@@ -17,6 +17,7 @@ import {
getDateFromStringOrThrow,
} from "@/features/local/utils/timeUtils";
import { useCreateAssignmentMutation } from "@/features/local/assignments/assignmentHooks";
import { validateFileName } from "@/services/fileNameValidation";
export default function NewItemForm({
moduleName: defaultModuleName,
@@ -41,20 +42,6 @@ export default function NewItemForm({
const [name, setName] = useState("");
const [nameError, setNameError] = useState("");
const validateFileName = (fileName: string): string => {
// Check for invalid file system characters
const invalidChars = [":", "/", "\\", "*", '"', "<", ">", "|"];
for (const char of fileName) {
if (invalidChars.includes(char)) {
return `Name contains invalid character: "${char}". Please avoid: ${invalidChars.join(
" "
)}`;
}
}
return "";
};
const handleNameChange = (newName: string) => {
setName(newName);
const error = validateFileName(newName);