-
Notifications
You must be signed in to change notification settings - Fork 16
fix: Add Subjects to School button is missing for OPS user in Teacher mode #4734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,13 @@ interface CurriculumWithCourses { | |
| courses: TableTypes<'course'>[]; | ||
| } | ||
|
|
||
| const SUBJECT_MODIFICATION_ROLES = [ | ||
| RoleType.SUPER_ADMIN, | ||
| RoleType.OPERATIONAL_DIRECTOR, | ||
| RoleType.PROGRAM_MANAGER, | ||
| RoleType.FIELD_COORDINATOR, | ||
| ]; | ||
|
|
||
| const SubjectSelection: React.FC = () => { | ||
| const [curriculumsWithCourses, setCurriculumsWithCourses] = useState< | ||
| CurriculumWithCourses[] | ||
|
|
@@ -118,8 +125,14 @@ const SubjectSelection: React.FC = () => { | |
| !currentSchool?.id || | ||
| !selectedSchoolId || | ||
| currentSchool.id === selectedSchoolId; | ||
| setCanModify(schoolMatches && normalizedRole === RoleType.PRINCIPAL); | ||
| }, [currentSchool?.id, paramSchoolId, roleMap]); | ||
| const hasSubjectModificationRole = SUBJECT_MODIFICATION_ROLES.some((role) => | ||
| roles.includes(role), | ||
| ); | ||
| setCanModify( | ||
| schoolMatches && | ||
| (normalizedRole === RoleType.PRINCIPAL || hasSubjectModificationRole), | ||
|
Comment on lines
+131
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When an ops user opens a school's subjects from the school list, Useful? React with 👍 / 👎. |
||
| ); | ||
| }, [currentSchool?.id, paramSchoolId, roleMap, roles]); | ||
|
|
||
| const fetchCurriculumsAndCourses = async ( | ||
| context: 'school' | 'class', | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
roles.includes(role)directly can throw aTypeErrorifrolesis undefined or null. Sincerolesis retrieved from the Redux store and might not be immediately available (as indicated by the defensive checkconst userRoles = roles || []on line 99), we should use optional chainingroles?.includes(role)to prevent potential runtime crashes.