Skip to content

Commit

Permalink
Fix program id retrieval when sharing (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav authored Jan 23, 2024
1 parent 9c84bf8 commit 11a33c3
Showing 1 changed file with 15 additions and 31 deletions.
46 changes: 15 additions & 31 deletions frontend/public/src/containers/pages/records/LearnerRecordsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
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.
Expand Down Expand Up @@ -306,18 +304,12 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
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 })

Expand All @@ -340,16 +332,13 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
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
)

Expand Down Expand Up @@ -401,15 +390,12 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
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 })

Expand Down Expand Up @@ -587,16 +573,14 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
render() {
const { learnerRecord, isLoading } = this.props
const { isRevoking, isEnablingSharing } = this.state

const isSharedRecord = this.getProgramId() ? true : false
const hasSharingEnabled = this.hasSharingEnabled(learnerRecord)

return (
<DocumentTitle title={`${SETTINGS.site_name} | ${RECORDS_PAGE_TITLE}`}>
<Loader isLoading={isLoading}>
<div className="std-page-body container">
<div className="d-flex flex-row-reverse mb-4">
{isSharedRecord ? (
{!this.isSharedRecordView() ? (
<div className="d-flex learner-record-sharing-controls mb-2">
{!hasSharingEnabled ? (
<button
Expand Down

0 comments on commit 11a33c3

Please sign in to comment.