Skip to content

Commit

Permalink
Fixed an issue that caused the user to be prompted to view their prac…
Browse files Browse the repository at this point in the history
…tice challenge certificate upon completion of a practice session even if a certificate has not been created in Admin.
  • Loading branch information
sei-bstein committed Oct 30, 2023
1 parent a73ff04 commit 0cc8158
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ <h2>Congratulations!</h2>
<div class="modal-body container">
<p>
You've successfully solved the challenge <strong>{{ context.challenge.spec.name }}!</strong>
Congratulations! Click
<a [href]="certificateUrl! | relativeToAbsoluteHref" target="_blank">here</a> to view a printable
certificate commemorating your achievement.
Congratulations!
<span *ngIf="isCertificateConfigured">
Click <a [href]="certificateUrl! | relativeToAbsoluteHref" target="_blank">here</a> to view a printable
certificate commemorating your achievement.
</span>
</p>

<p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { LocalActiveChallenge } from '@/api/challenges.models';
import { PlayerMode } from '@/api/player-models';
import { PracticeService } from '@/services/practice.service';
import { RouterService } from '@/services/router.service';
import { Component, OnInit } from '@angular/core';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { firstValueFrom } from 'rxjs';

export interface PracticeChallengeSolvedModalContext {
challenge: LocalActiveChallenge;
Expand All @@ -16,16 +18,20 @@ export interface PracticeChallengeSolvedModalContext {
export class PracticeChallengeSolvedModalComponent implements OnInit {
protected context?: PracticeChallengeSolvedModalContext;
protected certificateUrl?: string;
protected isCertificateConfigured = false;

constructor(
private practiceService: PracticeService,
private routerService: RouterService,
private modalRef: BsModalRef) { }

ngOnInit(): void {
async ngOnInit(): Promise<void> {
if (!this.context) {
throw new Error("Can't resolve the context for the PracticeChallengeSolvedModalComponent.");
}

const practiceSettings = await firstValueFrom(this.practiceService.getSettings());
this.isCertificateConfigured = !!practiceSettings.certificateHtmlTemplate;
this.certificateUrl = this.routerService.getCertificatePrintableUrl(PlayerMode.practice, this.context.challenge.spec.id);
}

Expand Down

0 comments on commit 0cc8158

Please sign in to comment.