mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-25 15:18:32 -06:00
validation on changing assignment name
This commit is contained in:
@@ -40,20 +40,25 @@ export function UpdateAssignmentName({
|
||||
if (name === assignmentName) closeModal();
|
||||
|
||||
setIsLoading(true); // page refresh resets flag
|
||||
await updateAssignment.mutateAsync({
|
||||
assignment: assignment,
|
||||
moduleName,
|
||||
assignmentName: name,
|
||||
previousModuleName: moduleName,
|
||||
previousAssignmentName: assignmentName,
|
||||
courseName,
|
||||
});
|
||||
try{
|
||||
|
||||
// update url (will trigger reload...)
|
||||
router.replace(
|
||||
getModuleItemUrl(courseName, moduleName, "assignment", name),
|
||||
{}
|
||||
);
|
||||
await updateAssignment.mutateAsync({
|
||||
assignment: assignment,
|
||||
moduleName,
|
||||
assignmentName: name,
|
||||
previousModuleName: moduleName,
|
||||
previousAssignmentName: assignmentName,
|
||||
courseName,
|
||||
});
|
||||
|
||||
// update url (will trigger reload...)
|
||||
router.replace(
|
||||
getModuleItemUrl(courseName, moduleName, "assignment", name),
|
||||
{}
|
||||
);
|
||||
}finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<TextInput
|
||||
|
||||
@@ -133,6 +133,18 @@ export async function updateOrCreateAssignmentFile({
|
||||
assignmentName: string;
|
||||
assignment: LocalAssignment;
|
||||
}) {
|
||||
const illegalCharacters = ["<", ">", ":", '"', "/", "\\", "|", "?", "*"];
|
||||
const foundIllegalCharacters = illegalCharacters.filter((char) =>
|
||||
assignmentName.includes(char)
|
||||
);
|
||||
if (foundIllegalCharacters.length > 0) {
|
||||
throw new Error(
|
||||
`"${assignmentName}" cannot contain the following characters: ${foundIllegalCharacters.join(
|
||||
" "
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
const courseDirectory = await getCoursePathByName(courseName);
|
||||
const folder = path.join(courseDirectory, moduleName, "assignments");
|
||||
await fs.mkdir(folder, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user