Skip to content

Commit

Permalink
Controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
kara22 committed Nov 20, 2023
1 parent 6a49a94 commit 8b3fce7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def update_identite
@dossier = dossier
@no_description = true

if @dossier.individual.update(individual_params)
if @dossier.update(dossier_params)
@dossier.update!(autorisation_donnees: true, identity_updated_at: Time.zone.now)
flash.notice = t('.identity_saved')

Expand Down Expand Up @@ -578,8 +578,8 @@ def render_siret_error(error_message)
render :siret
end

def individual_params
params.require(:individual).permit(:gender, :nom, :prenom, :birthdate)
def dossier_params
params.require(:dossier).permit(:for_tiers, :mandataire_first_name, :mandataire_last_name, individual_attributes: [:gender, :nom, :prenom, :birthdate, :email])
end

def siret_params
Expand Down
51 changes: 51 additions & 0 deletions app/javascript/controllers/for_tiers_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApplicationController } from './application_controller';

export class ForTiersController extends ApplicationController {
static values = { procedureid: Number };
static targets = [
'mandataireFirstName',
'mandataireLastName',
'forTiers',
'mandataireBlock',
'beneficiaireNotificationBlock',
'email',
'notificationMethod'
];

declare mandataireFirstNameTarget: HTMLInputElement;
declare mandataireLastNameTarget: HTMLInputElement;
declare forTiersTargets: NodeListOf<HTMLInputElement>;
declare mandataireBlockTarget: HTMLElement;
declare beneficiaireNotificationBlockTarget: HTMLElement;
declare notificationMethodTargets: NodeListOf<HTMLInputElement>;
declare emailTarget: HTMLInputElement;

connect() {
this.toggleFieldRequirements();
this.addEventListeners();
}

addEventListeners() {
this.forTiersTargets.forEach((radio) => {
radio.addEventListener('change', () => this.toggleFieldRequirements());
});
}

toggleFieldRequirements() {
const forTiersSelected = Array.from(this.forTiersTargets).some(
(radio) => radio.checked && radio.value === 'true'
);
this.mandataireBlockTarget.style.display = forTiersSelected
? 'block'
: 'none';
this.beneficiaireNotificationBlockTarget.style.display = forTiersSelected
? 'block'
: 'none';
this.mandataireFirstNameTarget.required = forTiersSelected;
this.mandataireLastNameTarget.required = forTiersSelected;
this.emailTarget.required = forTiersSelected;
this.notificationMethodTargets.forEach(
(radio) => (radio.required = forTiersSelected)
);
}
}

0 comments on commit 8b3fce7

Please sign in to comment.