From 11a33c3c887b29d0e866ce03ebf565eaac4b93dc Mon Sep 17 00:00:00 2001 From: Anna Gavrilman Date: Tue, 23 Jan 2024 11:34:35 -0500 Subject: [PATCH] Fix program id retrieval when sharing (#2061) --- .../pages/records/LearnerRecordsPage.js | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/frontend/public/src/containers/pages/records/LearnerRecordsPage.js b/frontend/public/src/containers/pages/records/LearnerRecordsPage.js index 3de4c1125e..6deb4d7365 100644 --- a/frontend/public/src/containers/pages/records/LearnerRecordsPage.js +++ b/frontend/public/src/containers/pages/records/LearnerRecordsPage.js @@ -70,15 +70,13 @@ export class LearnerRecordsPage extends React.Component { isRevoking: false, isEnablingSharing: false } - - getProgramId() { - return this.props.match.params.program.length !== 36 - ? this.props.match.params.program - : false + //when the record is in the shared view the program parameter is a 36 char UUID + isSharedRecordView() { + return this.props.match.params.program.length === 36 } - getOnlyProgramId() { - return parseInt(this.props.match.params.program.length) + getProgramId() { + return parseInt(this.props.match.params.program) } // Renders program's courses table. @@ -306,18 +304,12 @@ export class LearnerRecordsPage extends React.Component { async onEnableRecordSharing() { const { enableRecordSharing, addUserNotification } = this.props - this.setState({ isEnablingSharing: true }) - - const programId = this.getProgramId() - - if (programId === null) { + if (this.props.match.params.program === null) { return } + this.setState({ isEnablingSharing: true }) - const sharingResponse = await enableRecordSharing( - this.getOnlyProgramId(), - null - ) + const sharingResponse = await enableRecordSharing(this.getProgramId(), null) this.setState({ isEnablingSharing: false }) @@ -340,16 +332,13 @@ export class LearnerRecordsPage extends React.Component { async onSubmitPartnerSchoolShare(values: any) { const { enableRecordSharing, addUserNotification } = this.props - this.setState({ isEnablingSharing: true }) - - const programId = this.getProgramId() - - if (programId === null) { + if (this.props.match.params.program === null) { return } + this.setState({ isEnablingSharing: true }) const sharingResponse = await enableRecordSharing( - this.getOnlyProgramId(), + this.getProgramId(), values.partnerSchool ) @@ -401,15 +390,12 @@ export class LearnerRecordsPage extends React.Component { async onRevokeSharing() { const { revokeRecordSharing, addUserNotification } = this.props - this.setState({ isRevoking: true }) - - const programId = this.getProgramId() - - if (programId === null) { + if (this.props.match.params.program === null) { return } + this.setState({ isRevoking: true }) - const sharingResponse = await revokeRecordSharing(this.getOnlyProgramId()) + const sharingResponse = await revokeRecordSharing(this.getProgramId()) this.setState({ isRevoking: false }) @@ -587,8 +573,6 @@ export class LearnerRecordsPage extends React.Component { render() { const { learnerRecord, isLoading } = this.props const { isRevoking, isEnablingSharing } = this.state - - const isSharedRecord = this.getProgramId() ? true : false const hasSharingEnabled = this.hasSharingEnabled(learnerRecord) return ( @@ -596,7 +580,7 @@ export class LearnerRecordsPage extends React.Component {
- {isSharedRecord ? ( + {!this.isSharedRecordView() ? (
{!hasSharingEnabled ? (