Module: LeadFormHelper

Defined in:
app/helpers/lead_form_helper.rb

Instance Method Summary collapse

Instance Method Details

#compact_lead_form(submit_label: nil, lead_form_defaults: nil, locale: I18n.locale, show_upload: true, business_focused: false, show_header: false, header_title: nil, header_intro: nil) ⇒ Object

Compact lead form with progressive disclosure
Use business_focused: true for trade/business registration forms
Use show_header: true with header_title/header_intro to display a header



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/helpers/lead_form_helper.rb', line 72

def compact_lead_form(submit_label: nil, lead_form_defaults: nil, locale: I18n.locale, show_upload: true, business_focused: false, show_header: false, header_title: nil, header_intro: nil)
  submit_url = cms_link('/contact_es/send') if locale == :es

  I18n.with_locale(locale) do
    render partial: '/www/leads/lead_form_compact', locals: {
                  submit_label: submit_label || 'Send Message',
                  show_upload: show_upload,
                  lead_form_defaults: lead_form_defaults,
                  business_focused: business_focused,
                  submit_url: submit_url,
                  show_header: show_header,
                  header_title: header_title,
                  header_intro: header_intro
                }
  end
end

Inline contact link that opens a modal instead of navigating away.
Use this to replace direct links like link_to 'contact us', cms_link('/contact') with
a modal experience that keeps users on the page.

This is a convenience wrapper around lazy_lead_form_modal with variant: :link

Examples:

Basic usage

Please <%= contact_link 'contact us' %> for more information.

With custom styling

<%= contact_link 'email us', class: 'fw-semibold' %>

With context

<%= contact_link 'get in touch', header_title: 'Questions about Snow Melting?' %>

Parameters:

  • text (String) (defaults to: 'contact us')

    Link text

  • options (Hash) (defaults to: {})

    Options hash

Options Hash (options):

  • :class (String)

    CSS classes for the link

  • :header_title (String)

    Modal header title

  • :header_intro (String)

    Modal header intro text

  • :show_upload (Boolean)

    Show file attachment option (default: true)

  • :application_type (String)

    Pre-select application type



154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/helpers/lead_form_helper.rb', line 154

def contact_link(text = 'contact us', options = {})
  lazy_lead_form_modal(
    variant: :link,
    button_text: text,
    link_class: options[:class],
    header_title: options[:header_title],
    header_intro: options[:header_intro],
    show_upload: options.fetch(:show_upload, true),
    application_type: options[:application_type],
    about_project: options[:about_project]
  )
end

#lazy_lead_form_modal(variant: :card, modal_id: nil, header_title: 'Contact Us', header_intro: "Have a question? We're here to help.", button_text: 'Send Message', button_icon: 'envelope', button_class: 'btn btn-primary btn-lg', link_class: nil, show_upload: true, business_focused: false, submit_label: 'Send Message', application_type: nil, about_project: nil) ⇒ Object

Lazy-loading modal contact form
The form content is loaded via Turbo Frame only when modal opens,
reducing page weight by deferring turnstile and uppy loading.

Examples:

Basic card

<%= lazy_lead_form_modal %>

Custom button

<%= lazy_lead_form_modal(
  variant: :button,
  header_title: 'Request a Quote',
  button_text: 'Get Quote',
  application_type: 'Floor Heating'
) %>

Parameters:

  • variant (:card, :button) (defaults to: :card)

    Display style (:card shows full CTA card, :button shows just trigger)

  • header_title (String) (defaults to: 'Contact Us')

    Modal header title

  • header_intro (String) (defaults to: "Have a question? We're here to help.")

    Subtext below title

  • button_text (String) (defaults to: 'Send Message')

    Button label text

  • button_icon (String) (defaults to: 'envelope')

    Font Awesome icon name

  • show_upload (Boolean) (defaults to: true)

    Show file attachment option in form

  • business_focused (Boolean) (defaults to: false)

    Show company fields expanded/first

  • application_type (String) (defaults to: nil)

    Pre-select application type (e.g., 'Floor Heating')

  • submit_label (String) (defaults to: 'Send Message')

    Form submit button text

  • modal_id (Object, nil) (defaults to: nil)
  • button_class (String) (defaults to: 'btn btn-primary btn-lg')
  • link_class (String, nil) (defaults to: nil)

    CSS classes for link variant

  • about_project (Object, nil) (defaults to: nil)


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'app/helpers/lead_form_helper.rb', line 195

def lazy_lead_form_modal(
  variant: :card,
  modal_id: nil,
  header_title: 'Contact Us',
  header_intro: "Have a question? We're here to help.",
  button_text: 'Send Message',
  button_icon: 'envelope',
  button_class: 'btn btn-primary btn-lg',
  link_class: nil,
  show_upload: true,
  business_focused: false,
  submit_label: 'Send Message',
  application_type: nil,
  about_project: nil
)
  render Www::LeadFormModalComponent.new(
    variant: variant,
    modal_id: modal_id,
    header_title: header_title,
    header_intro: header_intro,
    button_text: button_text,
    button_icon: button_icon,
    button_class: button_class,
    link_class: link_class,
    show_upload: show_upload,
    business_focused: business_focused,
    submit_label: submit_label,
    application_type: application_type,
    about_project: about_project
  )
end

#lead_form(submit_label: nil, lead_form_defaults: nil, show_fields: nil, lead_form_labels: {}, locale: I18n.locale, show_header: true, header_title: 'Contact Us', header_intro: %(Have a question? We're here to help.), layout: :vertical) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/lead_form_helper.rb', line 11

def lead_form(submit_label: nil,
              lead_form_defaults: nil,
              show_fields: nil,
              lead_form_labels: {},
              locale: I18n.locale,
              show_header: true,
              header_title: 'Contact Us',
              header_intro: %(Have a question? We're here to help.),
              layout: :vertical)
  submit_url = cms_link('/contact_es/send') if locale == :es

  I18n.with_locale(locale) do
    render partial: '/www/leads/lead_form', locals: {
                  show_fields:,
                  submit_label:,
                  lead_form_defaults:,
                  lead_form_labels:,
                  submit_url:,
                  show_header:,
                  header_title:,
                  header_intro:,
                  layout:
                }
  end
end

#lead_form_modal(modal_id: 'leadFormModal', button_text: 'Contact Us', button_class: 'btn btn-primary', button_icon: 'envelope', modal_title: nil, modal_intro: nil, show_upload: false, business_focused: false, submit_label: 'Send Message', lead_form_defaults: nil) ⇒ Object

Modal lead form with CTA button trigger
Usage: <%= lead_form_modal(button_text: "Tell us About your Project") %>



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/helpers/lead_form_helper.rb', line 104

def lead_form_modal(modal_id: 'leadFormModal', button_text: 'Contact Us', button_class: 'btn btn-primary', button_icon: 'envelope', modal_title: nil, modal_intro: nil, show_upload: false, business_focused: false, submit_label: 'Send Message',
                    lead_form_defaults: nil)
  render partial: '/www/leads/lead_form_modal', locals: {
    modal_id: modal_id,
    button_text: button_text,
    button_class: button_class,
    button_icon: button_icon,
    modal_title: modal_title || button_text,
    modal_intro: modal_intro,
    show_upload: show_upload,
    business_focused: business_focused,
    submit_label: submit_label,
    lead_form_defaults: lead_form_defaults
  }
end

#pro_lead_form(submit_label: nil, lead_form_defaults: nil, locale: I18n.locale, header_title: nil, header_intro: nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/helpers/lead_form_helper.rb', line 51

def pro_lead_form(submit_label: nil, lead_form_defaults: nil, locale: I18n.locale, header_title: nil, header_intro: nil)
  submit_url = cms_link('/contact_es/send') if locale == :es
  lead_form_defaults ||= {}
  lead_form_defaults[:activity_type_task_type] = 'LEAD_TP'

  I18n.with_locale(locale) do
    render partial: '/www/leads/lead_form_compact', locals: {
                  submit_label: submit_label || 'Register as a Pro',
                  show_upload: true,
                  lead_form_defaults: lead_form_defaults,
                  business_focused: true,
                  header_title: header_title,
                  header_intro: header_intro,
                  submit_url: submit_url
                }
  end
end

#product_question_lead_form(presenter) ⇒ Object



120
121
122
123
124
125
126
127
128
129
# File 'app/helpers/lead_form_helper.rb', line 120

def product_question_lead_form(presenter)
  if presenter.is_a?(Www::ProductLinePresenter)
    product = nil
    product_line = presenter.slug_ltree.to_s
  elsif presenter.is_a?(Www::ProductCatalogPresenter)
    product = presenter.item.id
    product_line = nil
  end
  render partial: '/www/leads/product_question_lead_form', locals: { product_id: product, product_line: product_line }
end

#referral_program_lead_form(submit_label: nil, lead_form_defaults: nil, show_fields: nil, locale: I18n.locale) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
# File 'app/helpers/lead_form_helper.rb', line 89

def referral_program_lead_form(submit_label: nil, lead_form_defaults: nil, show_fields: nil, locale: I18n.locale)
  submit_url = cms_link('/contact_es/send') if locale == :es

  I18n.with_locale(locale) do
    render partial: '/www/leads/referral_program_lead_form', locals: {
                  show_fields: show_fields,
                  submit_label: submit_label,
                  lead_form_defaults: lead_form_defaults,
                  submit_url: submit_url
                }
  end
end

#setup_lead_form(lead_form_defaults = {}) ⇒ Object



2
3
4
5
6
7
8
9
# File 'app/helpers/lead_form_helper.rb', line 2

def setup_lead_form(lead_form_defaults = {})
  lead_form_defaults ||= {}
  lead_form_defaults[:preferred_locale] = I18n.locale.to_s
  task_type = lead_form_defaults.delete(:activity_type_task_type)
  lead_form_defaults[:activity_type_id] ||= ActivityType.find_by(task_type: task_type)&.id if task_type
  lead_form_defaults[:skip_activity] ||= false
  Lead.new(lead_form_defaults).from_party(@context_user)
end

#support_request_form(locale: I18n.locale, referred_sku: nil, referred_product_line: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/helpers/lead_form_helper.rb', line 37

def support_request_form(locale: I18n.locale, referred_sku: nil, referred_product_line: nil)
  # if locale == :es
  #   submit_url = cms_link('/contact_es/send')
  # end
  I18n.with_locale(locale) do
    render partial: '/www/leads/support_request_form', locals: {
                  support_case_note: 'Incoming Support Request from Support page',
                  referred_sku: referred_sku,
                  referred_product_line: referred_product_line,
                  submit_url: cms_link('/contact/send')
                }
  end
end