perf(InvitationWithTypoComponent): check email once from controller, forward actuel/suggestion email from ctrl to view
This commit is contained in:
parent
4771c45bce
commit
afa9821edb
3 changed files with 12 additions and 14 deletions
|
@ -9,12 +9,19 @@ module Administrateurs
|
|||
end
|
||||
|
||||
def create
|
||||
email_checker = EmailChecker.new
|
||||
emails = params['emails'].presence || [].to_json
|
||||
@maybe_typo, emails = JSON.parse(emails)
|
||||
.map { EmailSanitizer.sanitize(_1) }
|
||||
.partition { EmailChecker.new.check(email: _1)[:email_suggestions].present? }
|
||||
emails = JSON.parse(emails).map { EmailSanitizer.sanitize(_1) }
|
||||
@maybe_typo, emails = emails.map do |email|
|
||||
result = email_checker.check(email: email)
|
||||
if result[:email_suggestions].present?
|
||||
[email, result[:email_suggestions].first]
|
||||
else
|
||||
[email, nil]
|
||||
end
|
||||
end.partition { _1[1].present? }
|
||||
errors = if !@maybe_typo.empty?
|
||||
["Attention, nous pensons avoir identifié une faute de frappe dans les invitations : #{@maybe_typo.join(', ')}"]
|
||||
["Attention, nous pensons avoir identifié une faute de frappe dans les invitations : #{@maybe_typo.map(&:first).join(', ')}"]
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue