Skip to content

Commit

Permalink
[FEATURE] Utiliser PixToast dans Pix Admin (PIX-15328).
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Nov 21, 2024
2 parents 7956c7c + f094db8 commit 8f8d1bd
Show file tree
Hide file tree
Showing 135 changed files with 13,280 additions and 16,433 deletions.
12 changes: 7 additions & 5 deletions admin/app/components/actions-on-users-role-in-organization.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';

export default class ActionsOnUsersRoleInOrganization extends Component {
@service notifications;
@service pixToast;
@service accessControl;
@service intl;

Expand Down Expand Up @@ -37,9 +37,11 @@ export default class ActionsOnUsersRoleInOrganization extends Component {
try {
this.args.organizationMembership.organizationRole = this.selectedNewRole;
await this.args.organizationMembership.save();
this.notifications.success('Le rôle du membre a été mis à jour avec succès.');
this.pixToast.sendSuccessNotification({ message: 'Le rôle du membre a été mis à jour avec succès.' });
} catch (e) {
this.notifications.error('Une erreur est survenue lors de la mise à jour du rôle du membre.');
this.pixToast.sendErrorNotification({
message: 'Une erreur est survenue lors de la mise à jour du rôle du membre.',
});
} finally {
this.isEditionMode = false;
}
Expand All @@ -66,9 +68,9 @@ export default class ActionsOnUsersRoleInOrganization extends Component {
async disableOrganizationMembership() {
try {
await this.args.organizationMembership.destroyRecord({ adapterOptions: { disable: true } });
this.notifications.success('Le membre a été désactivé avec succès.');
this.pixToast.sendSuccessNotification({ message: 'Le membre a été désactivé avec succès.' });
} catch (e) {
this.notifications.error('Une erreur est survenue lors de la désactivation du membre.');
this.pixToast.sendErrorNotification({ message: 'Une erreur est survenue lors de la désactivation du membre.' });
} finally {
this.displayConfirm = false;
}
Expand Down
25 changes: 13 additions & 12 deletions admin/app/components/administration/access/anonymize-gar-import.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import AdministrationBlockLayout from '../block-layout';

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

@tracked isLoading = false;

@action
async anonymizeGar(files) {
this.isLoading = true;
this.notifications.clearAll();

try {
const token = this.session.data.authenticated.access_token;
Expand All @@ -39,31 +38,33 @@ export default class AnonymizeGarImport extends Component {
const { 'gar-anonymized-user-count': garAnonymizedUserCount, total } = json.data.attributes;

if (garAnonymizedUserCount === total) {
return this.notifications.success(
this.intl.t('components.administration.anonymize-gar-import.notifications.success.full', { total }),
);
return this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.anonymize-gar-import.notifications.success.full', {
total,
}),
});
}

return this.notifications.warning(
this.intl.t('components.administration.anonymize-gar-import.notifications.success.partial', {
return this.pixToast.sendWarningNotification({
message: this.intl.t('components.administration.anonymize-gar-import.notifications.success.partial', {
garAnonymizedUserCount,
total,
}),
);
});
}

const error = json.errors[0];
if (error.code === 'PAYLOAD_TOO_LARGE') {
return this.notifications.error(
this.intl.t('components.administration.anonymize-gar-import.notifications.error.payload-too-large', {
return this.pixToast.sendErrorNotification({
message: this.intl.t('components.administration.anonymize-gar-import.notifications.error.payload-too-large', {
maxSize: error.meta.maxSize,
}),
);
});
}

this.errorResponseHandler.notify(await response.json());
} catch (error) {
this.notifications.error(this.intl.t('common.notifications.generic-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
} finally {
this.isLoading = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import AdministrationBlockLayout from '../block-layout';

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

@action
async importOidcProviders(files) {
this.notifications.clearAll();

let response;
try {
const fileContent = files[0];
Expand All @@ -32,9 +30,9 @@ export default class OidcProvidersImport extends Component {
body: fileContent,
});
if (response.ok) {
this.notifications.success(
this.intl.t('components.administration.oidc-providers-import.notifications.success'),
);
this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.oidc-providers-import.notifications.success'),
});
return;
}

Expand All @@ -44,10 +42,10 @@ export default class OidcProvidersImport extends Component {
}

jsonResponse.errors.forEach((error) => {
this.notifications.error(error.detail, { autoClear: false });
this.pixToast.sendErrorNotification({ message: error.detail });
});
} catch (error) {
this.notifications.error(this.intl.t('common.notifications.generic-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
} finally {
this.isLoading = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ import AdministrationBlockLayout from '../block-layout';

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

@action
async importCampaigns(files) {
this.notifications.clearAll();

const adapter = this.store.adapterFor('import-files');
try {
await adapter.addCampaignsCsv(files);
this.notifications.success(this.intl.t('components.administration.campaigns-import.notifications.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.campaigns-import.notifications.success'),
});
} catch (errorResponse) {
const errors = errorResponse.errors;

if (!errors) {
return this.notifications.error(this.intl.t('common.notifications.generic-error'));
return this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
}
errors.forEach((error) => {
switch (error.code) {
case 'MISSING_REQUIRED_FIELD_NAMES':
this.notifications.error(`${error.meta}`, { autoClear: false });
this.pixToast.sendErrorNotification({ message: `${error.meta}` });
break;
default:
this.notifications.error(error.detail, { autoClear: false });
this.pixToast.sendErrorNotification({ message: error.detail });
}
});
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AdministrationBlockLayout from '../block-layout';

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

@tracked isLoading;
Expand All @@ -21,30 +21,33 @@ export default class SwapCampaignCodes extends Component {
async swapCodes(event) {
event.preventDefault();
this.isLoading = true;
this.notifications.clearAll();

const adapter = this.store.adapterFor('swap-campaign-code');
try {
await adapter.swap({ firstCampaignId: this.firstCampaignId, secondCampaignId: this.secondCampaignId });
this.notifications.success(this.intl.t('components.administration.swap-campaign-codes.notifications.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.swap-campaign-codes.notifications.success'),
});
} catch (errorResponse) {
const errors = errorResponse.errors;

if (!errors) {
return this.notifications.error(this.intl.t('common.notifications.generic-error'));
return this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
} else {
const error = errors[0];

if (error.code === 'ORGANIZATION_MISMATCH') {
return this.notifications.error(
this.intl.t('components.administration.swap-campaign-codes.notifications.error.mismatch-organization'),
);
return this.pixToast.sendErrorNotification({
message: this.intl.t(
'components.administration.swap-campaign-codes.notifications.error.mismatch-organization',
),
});
} else if (error.code === 'UNKNOWN_CAMPAIGN_ID') {
this.notifications.error(
this.intl.t('components.administration.swap-campaign-codes.notifications.error.swap-code-error'),
);
this.pixToast.sendErrorNotification({
message: this.intl.t('components.administration.swap-campaign-codes.notifications.error.swap-code-error'),
});
} else {
this.notifications.error(this.intl.t('common.notifications.generic-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import AdministrationBlockLayout from '../block-layout';

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

@tracked isLoading;
Expand All @@ -20,34 +20,41 @@ export default class UpdateCampaignCode extends Component {
async updateCode(event) {
event.preventDefault();
this.isLoading = true;
this.notifications.clearAll();

const adapter = this.store.adapterFor('update-campaign-code');
try {
await adapter.updateCampaignCode({ campaignId: this.campaignId, campaignCode: this.campaignCode });
this.notifications.success(this.intl.t('components.administration.update-campaign-code.notifications.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.update-campaign-code.notifications.success'),
});
} catch (errorResponse) {
const errors = errorResponse.errors;

if (!errors) {
return this.notifications.error(this.intl.t('common.notifications.generic-error'));
return this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
} else {
const error = errors[0];

if (error.code === 'CAMPAIGN_CODE_BAD_FORMAT') {
return this.notifications.error(
this.intl.t('components.administration.update-campaign-code.notifications.error.campaign-code-format'),
);
return this.pixToast.sendErrorNotification({
message: this.intl.t(
'components.administration.update-campaign-code.notifications.error.campaign-code-format',
),
});
} else if (error.code === 'CAMPAIGN_CODE_NOT_UNIQUE') {
return this.notifications.error(
this.intl.t('components.administration.update-campaign-code.notifications.error.unique-code-error'),
);
return this.pixToast.sendErrorNotification({
message: this.intl.t(
'components.administration.update-campaign-code.notifications.error.unique-code-error',
),
});
} else if (error.code === 'UNKNOWN_CAMPAIGN_ID') {
this.notifications.error(
this.intl.t('components.administration.update-campaign-code.notifications.error.campaign-id-error'),
);
this.pixToast.sendErrorNotification({
message: this.intl.t(
'components.administration.update-campaign-code.notifications.error.campaign-id-error',
),
});
} else {
this.notifications.error(this.intl.t('common.notifications.generic-error'));
this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AdministrationBlockLayout from '../block-layout';

export default class CertificationScoringConfiguration extends Component {
@service store;
@service notifications;
@service pixToast;
certificationScoringConfiguration = '';

@action
Expand All @@ -24,9 +24,9 @@ export default class CertificationScoringConfiguration extends Component {
const adapter = this.store.adapterFor('scoring-configuration');
try {
await adapter.updateCertificationScoringConfiguration(this.certificationScoringConfiguration);
this.notifications.success('Configuration enregistrée');
} catch (e) {
this.notifications.error("La config n'a pas pu être ajoutée");
this.pixToast.sendSuccessNotification({ message: 'Configuration enregistrée' });
} catch (_) {
this.pixToast.sendErrorNotification({ message: "La config n'a pas pu être ajoutée" });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AdministrationBlockLayout from '../block-layout';

export default class CompetenceScoringConfiguration extends Component {
@service store;
@service notifications;
@service pixToast;
competenceScoringConfiguration = '';

@action
Expand All @@ -24,9 +24,9 @@ export default class CompetenceScoringConfiguration extends Component {
const adapter = this.store.adapterFor('scoring-configuration');
try {
await adapter.updateCompetenceScoringConfiguration(this.competenceScoringConfiguration);
this.notifications.success('Configuration enregistrée');
} catch (e) {
this.notifications.error("La config n'a pas pu être ajoutée");
this.pixToast.sendSuccessNotification({ message: 'Configuration enregistrée' });
} catch (_) {
this.pixToast.sendErrorNotification({ message: "La config n'a pas pu être ajoutée" });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Form from './form';

export default class FlashAlgorithmConfiguration extends Component {
@service store;
@service notifications;
@service pixToast;
@tracked form = {
maximumAssessmentLength: this.args.model.maximumAssessmentLength,
warmUpLength: this.args.model.warmUpLength,
Expand All @@ -27,9 +27,9 @@ export default class FlashAlgorithmConfiguration extends Component {
const adapter = this.store.adapterFor('flash-algorithm-configuration');
try {
await adapter.createRecord(this.form);
this.notifications.success('La configuration a été créée');
this.pixToast.sendSuccessNotification({ message: 'La configuration a été créée' });
} catch (errorResponse) {
this.notifications.error("La configuration n'a pu être créée");
this.pixToast.sendErrorNotification({ message: "La configuration n'a pu être créée" });
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import AdministrationBlockLayout from '../block-layout';
export default class ScoWhitelistConfiguration extends Component {
@service intl;
@service session;
@service notifications;
@service pixToast;

@action
async importScoWhitelist(files) {
this.notifications.clearAll();
try {
const fileContent = files[0];

Expand All @@ -30,12 +29,18 @@ export default class ScoWhitelistConfiguration extends Component {
body: fileContent,
});
if (response.ok) {
this.notifications.success(this.intl.t('pages.administration.certification.sco-whitelist.import.success'));
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.administration.certification.sco-whitelist.import.success'),
});
} else {
this.notifications.error(this.intl.t('pages.administration.certification.sco-whitelist.import.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.administration.certification.sco-whitelist.import.error'),
});
}
} catch (error) {
this.notifications.error(this.intl.t('pages.administration.certification.sco-whitelist.import.error'));
this.pixToast.sendErrorNotification({
message: this.intl.t('pages.administration.certification.sco-whitelist.import.error'),
});
} finally {
this.isLoading = false;
}
Expand Down
Loading

0 comments on commit 8f8d1bd

Please sign in to comment.