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();
|
if (name === assignmentName) closeModal();
|
||||||
|
|
||||||
setIsLoading(true); // page refresh resets flag
|
setIsLoading(true); // page refresh resets flag
|
||||||
await updateAssignment.mutateAsync({
|
try{
|
||||||
assignment: assignment,
|
|
||||||
moduleName,
|
|
||||||
assignmentName: name,
|
|
||||||
previousModuleName: moduleName,
|
|
||||||
previousAssignmentName: assignmentName,
|
|
||||||
courseName,
|
|
||||||
});
|
|
||||||
|
|
||||||
// update url (will trigger reload...)
|
await updateAssignment.mutateAsync({
|
||||||
router.replace(
|
assignment: assignment,
|
||||||
getModuleItemUrl(courseName, moduleName, "assignment", name),
|
moduleName,
|
||||||
{}
|
assignmentName: name,
|
||||||
);
|
previousModuleName: moduleName,
|
||||||
|
previousAssignmentName: assignmentName,
|
||||||
|
courseName,
|
||||||
|
});
|
||||||
|
|
||||||
|
// update url (will trigger reload...)
|
||||||
|
router.replace(
|
||||||
|
getModuleItemUrl(courseName, moduleName, "assignment", name),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
}finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TextInput
|
<TextInput
|
||||||
|
|||||||
@@ -133,6 +133,18 @@ export async function updateOrCreateAssignmentFile({
|
|||||||
assignmentName: string;
|
assignmentName: string;
|
||||||
assignment: LocalAssignment;
|
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 courseDirectory = await getCoursePathByName(courseName);
|
||||||
const folder = path.join(courseDirectory, moduleName, "assignments");
|
const folder = path.join(courseDirectory, moduleName, "assignments");
|
||||||
await fs.mkdir(folder, { recursive: true });
|
await fs.mkdir(folder, { recursive: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user