Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Anna authored and Anna committed Jan 19, 2024
1 parent c0527a4 commit 95c8cc4
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions frontend/public/src/containers/pages/records/LearnerRecordsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,11 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
isRevoking: false,
isEnablingSharing: false
}

getProgramId() {
isProgramRecordShared() {
return this.props.match.params.program.length !== 36
? this.props.match.params.program
: false
}

getOnlyProgramId() {
getProgramId() {
return parseInt(this.props.match.params.program)
}

Expand Down Expand Up @@ -306,18 +303,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 +331,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 +389,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 @@ -588,7 +573,7 @@ export class LearnerRecordsPage extends React.Component<Props, State> {
const { learnerRecord, isLoading } = this.props
const { isRevoking, isEnablingSharing } = this.state

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

return (
Expand Down

0 comments on commit 95c8cc4

Please sign in to comment.