From 95c8cc44b939967f073f91ea09d95b209b5dd788 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 19 Jan 2024 16:20:03 -0500 Subject: [PATCH] refactoring --- .../pages/records/LearnerRecordsPage.js | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/frontend/public/src/containers/pages/records/LearnerRecordsPage.js b/frontend/public/src/containers/pages/records/LearnerRecordsPage.js index fadfe71aca..3772d28c36 100644 --- a/frontend/public/src/containers/pages/records/LearnerRecordsPage.js +++ b/frontend/public/src/containers/pages/records/LearnerRecordsPage.js @@ -70,14 +70,11 @@ export class LearnerRecordsPage extends React.Component { 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) } @@ -306,18 +303,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 +331,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 +389,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 }) @@ -588,7 +573,7 @@ export class LearnerRecordsPage extends React.Component { 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 (