Skip to content

Commit

Permalink
add first name var
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Sep 2, 2024
1 parent a04c041 commit b16322d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/submitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def friendly_name
end
end

def first_name
name.split(/\s+/, 2).first
end

def last_name
name.split(/\s+/, 2).last
end

def status_event_at
declined_at || completed_at || opened_at || sent_at || created_at
end
Expand Down
4 changes: 4 additions & 0 deletions lib/replace_email_variables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ module ReplaceEmailVariables
SUBMITTER_LINK = /\{+submitter\.link\}+/i
ACCOUNT_NAME = /\{+account\.name\}+/i
SENDER_NAME = /\{+sender\.name\}+/i
SENDER_FIRST_NAME = /\{+sender\.first_name\}+/i
SENDER_EMAIL = /\{+sender\.email\}+/i
SUBMITTER_EMAIL = /\{+submitter\.email\}+/i
SUBMITTER_NAME = /\{+submitter\.name\}+/i
SUBMITTER_FIRST_NAME = /\{+submitter\.first_name\}+/i
SUBMITTER_ID = /\{+submitter\.id\}+/i
SUBMITTER_SLUG = /\{+submitter\.slug\}+/i
SUBMISSION_LINK = /\{+submission\.link\}+/i
Expand All @@ -28,6 +30,7 @@ def call(text, submitter:, tracking_event_type: 'click_email', html_escape: fals
text = replace(text, SUBMISSION_ID, html_escape:) { submitter.submission.id }
text = replace(text, SUBMITTER_EMAIL, html_escape:) { submitter.email }
text = replace(text, SUBMITTER_NAME, html_escape:) { submitter.name || submitter.email || submitter.phone }
text = replace(text, SUBMITTER_FIRST_NAME, html_escape:) { submitter.first_name }
text = replace(text, SUBMITTER_LINK, html_escape:) { build_submitter_link(submitter, tracking_event_type) }
text = replace(text, SUBMISSION_LINK, html_escape:) do
submitter.submission ? build_submission_link(submitter.submission) : ''
Expand All @@ -37,6 +40,7 @@ def call(text, submitter:, tracking_event_type: 'click_email', html_escape: fals
text = replace(text, DOCUMENTS_LINK, html_escape:) { build_documents_links_text(submitter, sig) }
text = replace(text, ACCOUNT_NAME, html_escape:) { submitter.submission.account.name }
text = replace(text, SENDER_NAME, html_escape:) { submitter.submission.created_by_user&.full_name }
text = replace(text, SENDER_FIRST_NAME, html_escape:) { submitter.submission.created_by_user&.first_name }

replace(text, SENDER_EMAIL, html_escape:) { submitter.submission.created_by_user&.email.to_s.sub(/\+\w+@/, '@') }
end
Expand Down

0 comments on commit b16322d

Please sign in to comment.