Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Effacer le message d'erreur de saisie de l'externalId lors de la modification du précedent en erreur (PIX-15158) #10811

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion api/db/seeds/data/common/tooling/campaign-tooling.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export { createAssessmentCampaign, createProfilesCollectionCampaign };
* @param {string} code
* @param {string} title
* @param {string} idPixLabel
* @param {string} idPixLabelType
* @param {string} externalIdHelpImageUrl
* @param {string} alternativeTextToExternalIdHelpImage
* @param {string} customLandingPageText
Expand Down Expand Up @@ -62,6 +63,7 @@ async function createAssessmentCampaign({
code,
title,
idPixLabel,
idPixLabelType,
externalIdHelpImageUrl,
alternativeTextToExternalIdHelpImage,
customLandingPageText,
Expand All @@ -87,6 +89,7 @@ async function createAssessmentCampaign({
code,
title,
idPixLabel,
idPixLabelType,
externalIdHelpImageUrl,
alternativeTextToExternalIdHelpImage,
customLandingPageText,
Expand Down Expand Up @@ -443,6 +446,7 @@ function _buildCampaign({
code,
title,
idPixLabel,
idPixLabelType,
externalIdHelpImageUrl,
alternativeTextToExternalIdHelpImage,
customLandingPageText,
Expand Down Expand Up @@ -490,10 +494,13 @@ function _buildCampaign({
assessmentMethod,
});
if (idPixLabel) {
const type = Object.values(CampaignExternalIdTypes).includes(idPixLabelType)
? idPixLabelType
: CampaignExternalIdTypes.STRING;
databaseBuilder.factory.buildCampaignFeature({
campaignId: realCampaignId,
featureId: FEATURE_CAMPAIGN_EXTERNAL_ID,
params: { type: CampaignExternalIdTypes.STRING, label: idPixLabel },
params: { type, label: idPixLabel },
});
}
return { realCampaignId, realOrganizationId, realCreatedAt };
Expand Down
6 changes: 4 additions & 2 deletions api/db/seeds/data/team-prescription/build-campaigns.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dayjs from 'dayjs';

import { CampaignExternalIdTypes } from '../../../../src/prescription/shared/domain/constants.js';
import {
PRO_MANAGING_ORGANIZATION_ID,
PRO_ORGANIZATION_ID,
Expand Down Expand Up @@ -184,9 +185,10 @@ async function _createProCampaigns(databaseBuilder) {
targetProfileId: TARGET_PROFILE_NO_BADGES_NO_STAGES_ID,
organizationId: PRO_ORGANIZATION_ID,
ownerId: USER_ID_ADMIN_ORGANIZATION,
name: "Campagne d'évaluation PRO envoi multiple",
name: "Campagne d'évaluation PRO envoi multiple - ExternalId EMAIL",
code: 'PROASSMUL',
idPixLabel: 'IdPixLabel',
idPixLabel: 'gimme gimme gimme your email buddy',
idPixLabelType: CampaignExternalIdTypes.EMAIL,
multipleSendings: true,
createdAt: dayjs().subtract(30, 'days').toDate(),
configCampaign: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import PixBackgroundHeader from '@1024pix/pix-ui/components/pix-background-header';
import PixBlock from '@1024pix/pix-ui/components/pix-block';
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixInput from '@1024pix/pix-ui/components/pix-input';
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { t } from 'ember-intl';

const ERROR_MESSAGE = {
INVALID_EMAIL: 'pages.fill-in-participant-external-id.errors.invalid-external-id-email',
INVALID_EXTERNAL_ID: 'pages.fill-in-participant-external-id.errors.invalid-external-id',
MISSING_EXTERNAL_ID: 'pages.fill-in-participant-external-id.errors.missing-external-id',
};
export default class FillInParticipantExternalId extends Component {
@service intl;
@service campaignStorage;

@tracked participantExternalId = this.previousParticipantExternalId || null;
@tracked isLoading = false;
@tracked errorMessage = ERROR_MESSAGE[this.previousError] ? this.intl.t(ERROR_MESSAGE[this.previousError]) : null;

get previousError() {
return this.campaignStorage.get(this.args.campaign.code, 'error');
}
get previousParticipantExternalId() {
return this.campaignStorage.get(this.args.campaign.code, 'previousParticipantExternalId');
}

@action
submit(event) {
event.preventDefault();

if (!this.participantExternalId.trim()) {
this.errorMessage = this.intl.t('pages.fill-in-participant-external-id.errors.missing-external-id', {
idPixLabel: this.args.campaign.idPixLabel,
});
return;
}

if (this.participantExternalId.length > 255) {
this.errorMessage = this.intl.t('pages.fill-in-participant-external-id.errors.max-length-external-id', {
idPixLabel: this.args.campaign.idPixLabel,
});
return;
}

this.errorMessage = null;
return this.args.onSubmit(this.participantExternalId);
}

@action
updateParticipantExternalId(event) {
this.participantExternalId = event.target.value;
}

@action
resetErrorMessage() {
if (!this.errorMessage) return;

this.errorMessage = null;
}

@action
cancel() {
this.errorMessage = null;
return this.args.onCancel();
}

get idPixInputType() {
if (this.args.campaign.idPixType === 'EMAIL') {
return 'email';
} else if (this.args.campaign.idPixType === 'STRING') {
return 'text';
}
return null;
}

get idPixInputSubLabel() {
if (this.args.campaign.idPixType === 'EMAIL') {
return this.intl.t('pages.sign-up.fields.email.help');
} else if (this.args.campaign.idPixInputType === 'STRING') {
return '';
}
return null;
}

<template>
{{! template-lint-disable no-action require-input-label no-unknown-arguments-for-builtin-components }}
<main role="main">
<PixBackgroundHeader>
<PixBlock class="fill-in-participant-external-id">
<h1 class="fill-in-participant-external-id__title">{{t "pages.fill-in-participant-external-id.first-title"}}
</h1>
<p class="fill-in-participant-external-id__announcement">
{{t "pages.fill-in-participant-external-id.announcement"}}
</p>

<form {{on "submit" this.submit}} class="fill-in-participant-external-id__form">
<PixInput
@id="external-id"
@value={{this.participantExternalId}}
@errorMessage={{this.errorMessage}}
@validationStatus={{if this.errorMessage "error"}}
@requiredLabel={{true}}
{{on "input" this.resetErrorMessage}}
{{on "change" this.updateParticipantExternalId}}
@subLabel={{this.idPixInputSubLabel}}
type={{this.idPixInputType}}
aria-autocomplete="none"
>
<:label>{{@campaign.idPixLabel}}</:label>
</PixInput>

{{#if @campaign.externalIdHelpImageUrl}}
<img
class="fill-in-participant-external-id__help"
src={{@campaign.externalIdHelpImageUrl}}
alt={{@campaign.alternativeTextToExternalIdHelpImage}}
/>
{{/if}}

<div class="fill-in-participant-external-id__buttonbar">
<PixButton @variant="secondary" @triggerAction={{this.cancel}}>
{{t "pages.fill-in-participant-external-id.buttons.cancel"}}
</PixButton>

<PixButton @type="submit">
{{t "pages.fill-in-participant-external-id.buttons.continue"}}
</PixButton>
</div>
</form>
</PixBlock>
</PixBackgroundHeader>
</main>
</template>
}

This file was deleted.

This file was deleted.

Loading
Loading