Fix staff candidate pages pendingField null access#101
Open
sentry[bot] wants to merge 1 commit into
Open
Conversation
✅ Deploy Preview for studenthub-staff ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Comment on lines
647
to
651
| if (this.candidate && this.candidate.pendingField && this.candidate.pendingField.length > 0) { | ||
| this.candidate.pendingField = this.candidate?.pendingField?.filter(v => v != "experience") | ||
| this.candidate.pendingField = (this.candidate?.pendingField || []).filter(v => v != "experience"); | ||
| this.candidate.isProfileCompleted = this.candidate.pendingField.length == 0; | ||
|
|
||
| this.pendingData = 'Total ' + this.candidate.pendingField.length + ' pending fields\n ' + this.candidate.pendingField.join(','); |
Author
There was a problem hiding this comment.
Bug: The check for pendingField does not handle the null case from the API, which can cause a runtime error in the template's *ngFor when iterating over the null value.
Severity: HIGH
Suggested Fix
Update the conditional check to if (this.candidate) to ensure the block always executes. This will correctly initialize this.candidate.pendingField to an empty array [] when it is null, preventing the template from receiving a null value and avoiding the runtime error.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
src/app/pages/logged-in/candidate/candidate-view/candidate-view.page.ts#L647-L651
Potential issue: The `if` condition at line 647 checks `this.candidate.pendingField &&
this.candidate.pendingField.length > 0`. When the API returns `null` for `pendingField`
(indicating a completed profile), this condition is false. The block is skipped, leaving
`this.candidate.pendingField` as `null`. When a user with a completed profile triggers
the 'pending-fields' popover, the template's `*ngFor` attempts to iterate over `null`,
causing a `TypeError` and a runtime crash. This also leads to incorrect UI states, such
as showing an 'Incomplete profile' badge for a completed profile.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a
TypeError: Cannot read properties of null (reading 'filter')that occurred whenthis.model.pendingField(orthis.candidate.pendingField) wasnullin the API response. This happens when a candidate's profile is fully completed, and the backend'sgetPendingField()method returnsnullinstead of an empty array.The fix involves adding a fallback to an empty array (
|| []) before calling.filter()onpendingFieldin the following files:src/app/pages/logged-in/candidate/candidate-warning-list/candidate-warning-list.page.tssrc/app/pages/logged-in/candidate/candidate-salary-list/candidate-salary-list.page.tssrc/app/pages/logged-in/candidate/candidate-invitations/candidate-invitations.page.tssrc/app/pages/logged-in/candidate/candidate-notes/candidate-notes.page.tssrc/app/pages/logged-in/candidate/candidate-suggestions/candidate-suggestions.page.tssrc/app/pages/logged-in/candidate/candidate-view/candidate-view.page.tsNote:
src/app/pages/logged-in/candidate/candidate-form/candidate-form.page.tsalready had a similar fix implemented in a previous commit.Fixes SH-STAFF-APP-9
Fixes TECH-2033