Skip to content

Commit

Permalink
[FEATURE] Utiliser le composant Pix Toast dans Pix Certif (PIX-15280).
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Nov 18, 2024
2 parents e4246a1 + f9cbaf3 commit 776e6d0
Show file tree
Hide file tree
Showing 45 changed files with 284 additions and 301 deletions.
8 changes: 4 additions & 4 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...';
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,7 @@ export default class EnrolledCandidates extends Component {
@service store;
@service intl;
@service currentUser;
@service notifications;
@service pixToast;
@service featureToggles;
@tracked candidatesInStaging = [];
@tracked newCandidate = {};
Expand All @@ -51,18 +51,19 @@ export default class EnrolledCandidates extends Component {

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

try {
await certificationCandidate.destroyRecord({ adapterOptions: { sessionId } });
this.notifications.success(this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.success-remove`));
this.pixToast.sendSuccessNotification({
message: this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.success-remove`),
});
} catch (error) {
let errorText = this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.error-remove-unknown`);
if (get(error, 'errors[0].code') === 403) {
errorText = this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.error-remove-already-in`);
}
this.notifications.error(errorText);
this.pixToast.sendErrorNotification({ message: errorText });
}
}

Expand Down Expand Up @@ -133,10 +134,14 @@ export default class EnrolledCandidates extends Component {
try {
const adapter = this.store.adapterFor('certification-candidate');
await adapter.updateRecord({ candidate: this.certificationCandidateInEditModal, sessionId: this.args.sessionId });
this.notifications.success(this.intl.t('pages.sessions.detail.candidates.edit-modal.notifications.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.sessions.detail.candidates.edit-modal.notifications.success'),
});
this.closeEditCandidateModal();
} catch (e) {
this.notifications.error(this.intl.t('pages.sessions.detail.candidates.edit-modal.notifications.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.sessions.detail.candidates.edit-modal.notifications.error'),
});
} finally {
this.args.reloadCertificationCandidate();
}
Expand All @@ -149,7 +154,6 @@ export default class EnrolledCandidates extends Component {

@action
async saveCertificationCandidate(certificationCandidateData) {
this.notifications.clearAll();
const { certificationCandidate, subscriptions } =
this._createCertificationCandidateRecord(certificationCandidateData);

Expand All @@ -163,7 +167,9 @@ export default class EnrolledCandidates extends Component {
adapterOptions: { registerToSession: true, sessionId: this.args.sessionId, subscriptions },
});
this.args.reloadCertificationCandidate();
this.notifications.success(this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.success-add`));
this.pixToast.sendSuccessNotification({
message: this.intl.t(`${TRANSLATE_PREFIX}.add-modal.notifications.success-add`),
});
return true;
} catch (errorResponse) {
const status = get(errorResponse, 'errors[0].status');
Expand Down Expand Up @@ -268,7 +274,7 @@ export default class EnrolledCandidates extends Component {

_handleSavingError({ errorText, certificationCandidate }) {
const error = errorText ?? this.intl.t(`common.api-error-messages.internal-server-error`);
this.notifications.error(error);
this.pixToast.sendErrorNotification({ message: error });
certificationCandidate.deleteRecord();
}

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
Loading

0 comments on commit 776e6d0

Please sign in to comment.