Skip to content

Commit

Permalink
✨ certif: use Pix Toast
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiaPena committed Nov 14, 2024
1 parent 2ef0eed commit 4d37c7c
Show file tree
Hide file tree
Showing 22 changed files with 144 additions and 122 deletions.
6 changes: 3 additions & 3 deletions certif/app/components/add-student-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { tracked } from '@glimmer/tracking';
import some from 'lodash/some';

export default class AddStudentList extends Component {
@service notifications;
@service pixToast;
@service store;
@service router;

Expand Down Expand Up @@ -75,11 +75,11 @@ export default class AddStudentList extends Component {
try {
await this.args.session.save({ adapterOptions: { studentListToAdd, sessionId } });
this.args.returnToSessionCandidates(sessionId);
this.notifications.success('Le(s) candidat(s) ont été inscrit(s) avec succès.');
this.pixToast.sendSuccessNotification({ message: 'Le(s) candidat(s) ont été inscrit(s) avec succès.' });
} catch (error) {
let errorMessage = 'Une erreur est survenue au moment d‘inscrire les candidats...';
if (error.errors?.[0]?.status === '422') errorMessage = error.errors?.[0]?.detail;
this.notifications.error(errorMessage);
this.pixToast.sendErrorNotification({ message: errorMessage });
}
}

Expand Down
9 changes: 5 additions & 4 deletions certif/app/components/import-candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Component from '@glimmer/component';

export default class ImportCandidates extends Component {
@service session;
@service notifications;
@service pixToast;
@service store;
@service intl;

Expand All @@ -15,15 +15,16 @@ export default class ImportCandidates extends Component {
const sessionId = this.args.session.id;

this.isLoading = true;
this.notifications.clearAll();
try {
await adapter.addCertificationCandidatesFromOds(sessionId, files);
this.notifications.success(this.intl.t('pages.sessions.import.candidates-list.import-success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.sessions.import.candidates-list.import-success'),
});
await this.args.reloadCertificationCandidate();
} catch (errorResponse) {
const errorMessage = this._handleErrorMessage(errorResponse);

this.notifications.error(htmlSafe(errorMessage));
this.pixToast.sendErrorNotification({ message: htmlSafe(errorMessage) });
} finally {
this.isLoading = false;
}
Expand Down
10 changes: 7 additions & 3 deletions certif/app/components/members-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ARIA_LABEL_ADMIN_TRANSLATION = 'pages.team.members.actions.select-role.opt

export default class MembersListItem extends Component {
@service currentUser;
@service notifications;
@service pixToast;
@service intl;
@tracked isEditionMode = false;

Expand Down Expand Up @@ -73,10 +73,14 @@ export default class MembersListItem extends Component {
this.isEditionMode = false;
try {
await member.save();
this.notifications.success(this.intl.t('pages.team.members.notifications.change-member-role.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.team.members.notifications.change-member-role.success'),
});
} catch (e) {
member.rollbackAttributes();
this.notifications.error(this.intl.t('pages.team.members.notifications.change-member-role.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.team.members.notifications.change-member-role.error'),
});
}
}

Expand Down
24 changes: 13 additions & 11 deletions certif/app/components/members-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { tracked } from '@glimmer/tracking';
export default class MembersList extends Component {
@service currentUser;
@service intl;
@service notifications;
@service pixToast;
@service session;

@tracked isLeaveCertificationCenterModalOpen = false;
Expand Down Expand Up @@ -52,17 +52,17 @@ export default class MembersList extends Component {
async leaveCertificationCenter() {
try {
await this.args.onLeaveCertificationCenter();
this.notifications.success(
this.intl.t('pages.team.members.notifications.leave-certification-center.success', {
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.team.members.notifications.leave-certification-center.success', {
certificationCenterName: this.currentUser.currentAllowedCertificationCenterAccess.name,
}),
);
});
await this.session.waitBeforeInvalidation(5000);
this.session.invalidate();
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
this.notifications.error(this.intl.t('pages.team.members.notifications.leave-certification-center.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.team.members.notifications.leave-certification-center.error'),
});
} finally {
this.closeLeaveCertificationCenterModal();
}
Expand All @@ -72,14 +72,16 @@ export default class MembersList extends Component {
async removeMember() {
try {
await this.args.onRemoveMember(this.removingMember);
this.notifications.success(
this.intl.t('pages.team.members.notifications.remove-membership.success', {
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.team.members.notifications.remove-membership.success', {
memberFirstName: this.removingMember.firstName,
memberLastName: this.removingMember.lastName,
}),
);
});
} catch (e) {
this.notifications.error(this.intl.t('pages.team.members.notifications.remove-membership.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.team.members.notifications.remove-membership.error'),
});
} finally {
this.closeRemoveMemberModal();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default class UncompletedReportsInformationStep extends Component {
@tracked reportToEdit = null;
@tracked showAddIssueReportModal = false;
@tracked showIssueReportsModal = false;
@service notifications;
@service intl;

get certificationReportsAreNotEmpty() {
Expand Down
50 changes: 27 additions & 23 deletions certif/app/components/session-supervising/candidate-in-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Modals = {
};

export default class CandidateInList extends Component {
@service notifications;
@service pixToast;
@service intl;
@service store;

Expand Down Expand Up @@ -143,9 +143,11 @@ export default class CandidateInList extends Component {
if (this.args.candidate.hasOngoingChallengeLiveAlert) {
this.displayedModal = Modals.HandleLiveAlert;
} else {
this.notifications.error(
this.intl.t('pages.session-supervising.candidate-in-list.handle-live-alert-modal.no-current-live-alert'),
);
this.pixToast.sendErrorNotification({
message: this.intl.t(
'pages.session-supervising.candidate-in-list.handle-live-alert-modal.no-current-live-alert',
),
});
}
}

Expand All @@ -161,11 +163,11 @@ export default class CandidateInList extends Component {
await adapter.dismissLiveAlert(this.args.sessionId, this.args.candidate.userId);
this.isLiveAlertValidated = false;
this.displayedModal = Modals.HandledLiveAlertSuccess;
} catch (err) {
} catch (error) {
const errorMessage = this.intl.t(
'pages.session-supervising.candidate-in-list.handle-live-alert-modal.error-handling-live-alert',
);
this.notifications.error(errorMessage);
this.pixToast.sendErrorNotification({ message: errorMessage });
}
}

Expand All @@ -184,7 +186,7 @@ export default class CandidateInList extends Component {
const errorMessage = this.intl.t(
'pages.session-supervising.candidate-in-list.handle-live-alert-modal.error-handling-live-alert',
);
this.notifications.error(errorMessage);
this.pixToast.sendErrorNotification({ message: errorMessage });
}
}

Expand All @@ -197,15 +199,17 @@ export default class CandidateInList extends Component {
candidateUserId: this.args.candidate.userId,
});

this.notifications.success(
this.intl.t('pages.session-supervising.candidate-in-list.notifications.handling-live-alert.success', {
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.session-supervising.candidate-in-list.notifications.handling-live-alert.success', {
htmlSafe: true,
}),
);
});
} catch (error) {
this.notifications.error(
this.intl.t('pages.session-supervising.candidate-in-list.handle-live-alert-modal.error-handling-live-alert'),
);
this.pixToast.sendErrorNotification({
message: this.intl.t(
'pages.session-supervising.candidate-in-list.handle-live-alert-modal.error-handling-live-alert',
),
});
} finally {
this.displayedModal = null;
}
Expand All @@ -221,12 +225,12 @@ export default class CandidateInList extends Component {
this.closeConfirmationModal();
try {
await this.args.onCandidateTestResumeAuthorization(this.args.candidate);
this.notifications.success(
this.intl.t('pages.session-supervising.candidate-in-list.resume-test-modal.success', {
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.session-supervising.candidate-in-list.resume-test-modal.success', {
firstName: this.args.candidate.firstName,
lastName: this.args.candidate.lastName,
}),
);
});
} catch (responseError) {
const error = responseError?.errors?.[0];
const parameters = {
Expand All @@ -241,7 +245,7 @@ export default class CandidateInList extends Component {
} else {
errorMessage = this.intl.t('common.api-error-messages.authorize-resume-error', parameters);
}
this.notifications.error(errorMessage);
this.pixToast.sendErrorNotification({ message: errorMessage });
}
}

Expand All @@ -250,19 +254,19 @@ export default class CandidateInList extends Component {
this.closeConfirmationModal();
try {
await this.args.onSupervisorEndAssessment(this.args.candidate);
this.notifications.success(
this.intl.t('pages.session-supervising.candidate-in-list.test-end-modal.success', {
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.session-supervising.candidate-in-list.test-end-modal.success', {
firstName: this.args.candidate.firstName,
lastName: this.args.candidate.lastName,
}),
);
});
} catch (error) {
this.notifications.error(
this.intl.t('pages.session-supervising.candidate-in-list.test-end-modal.error', {
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.session-supervising.candidate-in-list.test-end-modal.error', {
firstName: this.args.candidate.firstName,
lastName: this.args.candidate.lastName,
}),
);
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class SessionDetailsCleaResultsDownload extends Component {
@service intl;
@service fileSaver;
@service session;
@service notifications;
@service pixToast;

@action
async downloadCleaCertifiedCandidateData() {
Expand All @@ -18,7 +18,7 @@ export default class SessionDetailsCleaResultsDownload extends Component {
try {
await this.fileSaver.save({ url, token });
} catch {
this.notifications.error(this.intl.t('pages.sessions.detail.panel-clea.error-message'));
this.pixToast.sendErrorNotification({ message: this.intl.t('pages.sessions.detail.panel-clea.error-message') });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export default class EnrolledCandidates extends Component {
@service store;
@service intl;
@service currentUser;
@service notifications;
@service featureToggles;
@tracked candidatesInStaging = [];
@tracked newCandidate = {};
Expand All @@ -51,7 +50,6 @@ export default class EnrolledCandidates extends Component {

@action
async deleteCertificationCandidate(certificationCandidate) {
this.notifications.clearAll();
const sessionId = this.args.sessionId;

try {
Expand Down
6 changes: 3 additions & 3 deletions certif/app/components/sessions/session-details/index.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class SessionDetails extends Component {
@service intl;
@service url;
@service session;
@service notifications;
@service pixToast;
@service fileSaver;

@action
Expand All @@ -23,7 +23,7 @@ export default class SessionDetails extends Component {
const token = this.session.data.authenticated.access_token;
await this.fileSaver.save({ url: this.args.model.sessionManagement.urlToDownloadSupervisorKitPdf, token });
} catch (err) {
this.notifications.error(this.intl.t('common.api-error-messages.internal-server-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.api-error-messages.internal-server-error') });
}
}

Expand All @@ -33,7 +33,7 @@ export default class SessionDetails extends Component {
const token = this.session.data.authenticated.access_token;
await this.fileSaver.save({ url: this.args.model.session.urlToDownloadAttendanceSheet, token });
} catch (err) {
this.notifications.error(this.intl.t('common.api-error-messages.internal-server-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.api-error-messages.internal-server-error') });
}
}

Expand Down
29 changes: 16 additions & 13 deletions certif/app/components/sessions/session-list.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class SessionList extends Component {
@tracked currentSessionToBeDeletedId = null;
@tracked currentEnrolledCandidatesCount = null;
@service store;
@service notifications;
@service pixToast;
@service intl;

get currentLocale() {
Expand All @@ -37,15 +37,14 @@ export default class SessionList extends Component {

@action
async deleteSession() {
this.notifications.clearAll();
const sessionSummary = this.store.peekRecord('session-summary', this.currentSessionToBeDeletedId);
try {
await sessionSummary.destroyRecord();
this.notifications.success(this.intl.t('pages.sessions.list.delete-modal.success'));
} catch (err) {
if (this._doesNotExist(err)) {
this.pixToast.sendSuccessNotification({ message: this.intl.t('pages.sessions.list.delete-modal.success') });
} catch (error) {
if (this._doesNotExist(error)) {
this._handleSessionDoesNotExistsError();
} else if (this._sessionHasStarted(err)) {
} else if (this._sessionHasStarted(error)) {
this._handleSessionHasStartedError();
} else {
this._handleUnknownSavingError();
Expand All @@ -54,24 +53,28 @@ export default class SessionList extends Component {
this.closeSessionDeletionConfirmModal();
}

_sessionHasStarted(err) {
return get(err, 'errors[0].status') === '409';
_sessionHasStarted(error) {
return get(error, 'errors[0].status') === '409';
}

_doesNotExist(err) {
return get(err, 'errors[0].status') === '404';
_doesNotExist(error) {
return get(error, 'errors[0].status') === '404';
}

_handleUnknownSavingError() {
this.notifications.error(this.intl.t('pages.sessions.list.delete-modal.errors.unknown'));
this.pixToast.sendErrorNotification({ message: this.intl.t('pages.sessions.list.delete-modal.errors.unknown') });
}

_handleSessionDoesNotExistsError() {
this.notifications.error(this.intl.t('pages.sessions.list.delete-modal.errors.session-does-not-exists'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.sessions.list.delete-modal.errors.session-does-not-exists'),
});
}

_handleSessionHasStartedError() {
this.notifications.error(this.intl.t('pages.sessions.list.delete-modal.errors.session-has-started'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.sessions.list.delete-modal.errors.session-has-started'),
});
}

<template>
Expand Down
Loading

0 comments on commit 4d37c7c

Please sign in to comment.