-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
367 additions
and
2 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
wcc-contentful-app/app/assets/javascripts/wcc/contentful/app/application.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require_tree . |
22 changes: 22 additions & 0 deletions
22
wcc-contentful-app/app/assets/javascripts/wcc/contentful/app/contact-form.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$(window).load(function() { | ||
$('[data-contact-form]').each((_, input) => { | ||
const $form = $(input); | ||
|
||
function handleResponse(status, responseJSON) { | ||
if (responseJSON) { | ||
alert(responseJSON.message); | ||
} else { | ||
alert('Sorry, something went wrong.'); | ||
} | ||
$('input:visible, textarea', $form).val(''); | ||
} | ||
|
||
$form.on('ajax:success', (event, data, status, xhr) => { | ||
handleResponse(status, xhr.responseJSON); | ||
}); | ||
|
||
$form.on('ajax:error', (event, xhr, status) => { | ||
handleResponse(status, xhr.responseJSON); | ||
}); | ||
}); | ||
}) |
21 changes: 21 additions & 0 deletions
21
wcc-contentful-app/app/controllers/wcc/contentful/app/contact_form_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class WCC::Contentful::App::ContactFormController < ApplicationController | ||
def create | ||
form_model.send_email(form_params) | ||
|
||
render json: { type: 'success', message: "Thanks for reaching out. We'll be in touch soon!" } | ||
end | ||
|
||
private | ||
|
||
def form_model | ||
raise ArgumentError, 'missing form ID' unless params[:id] | ||
|
||
@form_model ||= WCC::Contentful::Model::SectionContactForm.find(params[:id]) | ||
end | ||
|
||
def form_params | ||
params.permit(*form_model.fields.map(&:title)) | ||
end | ||
end |
13 changes: 13 additions & 0 deletions
13
wcc-contentful-app/app/mailers/wcc/contentful/app/contact_mailer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module WCC::Contentful::App | ||
if defined?(::ApplicationMailer) | ||
class ContactMailer < ::ApplicationMailer | ||
def contact_form_email(to_email, data) | ||
@form_data = data | ||
|
||
mail(to: to_email, subject: 'Contact Us Form Submission') | ||
end | ||
end | ||
end | ||
end |
8 changes: 8 additions & 0 deletions
8
wcc-contentful-app/app/models/wcc/contentful/app/contact_form_submission.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
module WCC::Contentful::App | ||
if defined?(::ActiveRecord) | ||
class ContactFormSubmission < ::ActiveRecord::Base | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
</head> | ||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= content_for?(:content) ? yield(:content) : yield %> |
35 changes: 35 additions & 0 deletions
35
wcc-contentful-app/app/views/sections/_contact_form.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<div class="row"> | ||
<div class="column"> | ||
<div class="contact-panel -mt5"> | ||
<div class="contact-panel__header"> | ||
<%= markdown(section.text) %> | ||
</div><!--faq-panel__header--> | ||
|
||
<div class="contact-panel__content"> | ||
<%= form_tag contact_form_path, remote: true, data: { contact_form: '' }, method: 'post' do %> | ||
<input type="hidden" name="id" value="<%= section.id %>" /> | ||
<% section.fields&.each do |field| %> | ||
<div class="field"> | ||
<label for="" class="contact-panel__label"><%= field.title %></label> | ||
<%= case field.input_type | ||
when 'email' | ||
content_tag(:input, nil, type: 'email', name: field.title, required: true) | ||
when 'textarea' | ||
content_tag(:textarea, nil, | ||
rows: 8, columnns: 80, name: field.title, minlength: 5, required: true) | ||
else | ||
content_tag(:input, nil, type: 'text', name: field.title) | ||
end %> | ||
|
||
</div> | ||
<% end %> | ||
<%= submit_tag section.submit_button_text || 'Submit', | ||
class: 'button white', data: { disable_with: 'Submitting...' } %> | ||
<% end %> | ||
|
||
</div><!--faq-panel__content--> | ||
|
||
</div><!--faq-panel--> | ||
|
||
</div><!--column--> | ||
</div><!--row--> |
7 changes: 7 additions & 0 deletions
7
wcc-contentful-app/app/views/wcc/contentful/app/user_mailer/contact_form_email.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
<h1>Contact Us Form Submission</h1> | ||
<% @form_data.each do |key, value| %> | ||
<p> | ||
<%= key %> -> <%= value %> | ||
</p> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
...tes/section-contact-form/migrations/create_wcc_contentful_app_contact_form_submissions.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateWCCContentfulAppContactFormSubmissions < ActiveRecord::Migration[5.2] | ||
def change | ||
create_table :wcc_contentful_app_contact_form_submissions do |t| | ||
t.string :form_id | ||
t.json :data, default: {} | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
147 changes: 147 additions & 0 deletions
147
...tors/wcc/templates/section-contact-form/migrations/generated_add_section-contact-forms.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
import Migration, { MigrationFunction } from 'contentful-migration' | ||
|
||
// Generated by contentful-schema-diff | ||
// from contentful-export-4gyidsb2jx1u-rorJeremy-2018-10-18T15-41-43.json | ||
// to 7yx6ovlj39n5/master | ||
export = function (migration: Migration, { makeRequest, spaceId, accessToken }) { | ||
|
||
/************ section-contact-form ******************/ | ||
|
||
var sectionContactForm = migration.createContentType('section-contact-form', { | ||
displayField: 'internalTitle', | ||
name: 'Section: Contact Form', | ||
description: | ||
'A Contact Form section contains a Form with several Form Fields. The responses to the form will be collected and provided to the appropriate administrator.' | ||
}) | ||
|
||
sectionContactForm.createField('internalTitle', { | ||
name: 'Internal Title (Contentful Only)', | ||
type: 'Symbol', | ||
localized: false, | ||
required: true, | ||
validations: [], | ||
disabled: false, | ||
omitted: true | ||
}) | ||
|
||
sectionContactForm.createField('text', { | ||
name: 'Text', | ||
type: 'Text', | ||
localized: false, | ||
required: true, | ||
validations: [], | ||
disabled: false, | ||
omitted: false | ||
}) | ||
|
||
sectionContactForm.createField('fields', { | ||
name: 'Fields', | ||
type: 'Array', | ||
localized: false, | ||
required: true, | ||
validations: [], | ||
disabled: false, | ||
omitted: false, | ||
items: { | ||
type: 'Link', | ||
validations: [ | ||
{ | ||
linkContentType: ['formField'] | ||
} | ||
], | ||
linkType: 'Entry' | ||
} | ||
}) | ||
|
||
sectionContactForm.createField('submitButtonText', { | ||
name: 'Submit Button Text', | ||
type: 'Symbol', | ||
localized: false, | ||
required: false, | ||
validations: [], | ||
disabled: false, | ||
omitted: false | ||
}) | ||
|
||
sectionContactForm.createField('notificationEmail', { | ||
name: 'NotificationEmail', | ||
type: 'Symbol', | ||
localized: false, | ||
required: true, | ||
validations: [ | ||
{ | ||
regexp: { | ||
pattern: | ||
'^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$', | ||
flags: null | ||
}, | ||
message: 'Must be a valid email address.' | ||
} | ||
], | ||
disabled: false, | ||
omitted: false | ||
}) | ||
|
||
sectionContactForm.changeEditorInterface('internalTitle', 'singleLine') | ||
|
||
sectionContactForm.changeEditorInterface('text', 'markdown') | ||
|
||
sectionContactForm.changeEditorInterface('fields', 'entryLinksEditor') | ||
|
||
sectionContactForm.changeEditorInterface('submitButtonText', 'singleLine') | ||
|
||
sectionContactForm.changeEditorInterface('notificationEmail', 'singleLine', { | ||
helpText: | ||
'This is the email address where the form submission notification goes.' | ||
}) | ||
|
||
/************ formField ******************/ | ||
|
||
var formfield = migration.createContentType('formField', { | ||
displayField: 'internalTitle', | ||
name: 'Form Field', | ||
description: 'A Form Field represents a piece of information you want to collect from a user via a Form.' | ||
}) | ||
|
||
formfield.createField('internalTitle', { | ||
name: 'Internal Title (Contentful Only)', | ||
type: 'Symbol', | ||
localized: false, | ||
required: true, | ||
validations: [], | ||
disabled: false, | ||
omitted: true | ||
}) | ||
|
||
formfield.createField('title', { | ||
name: 'Title', | ||
type: 'Symbol', | ||
localized: false, | ||
required: false, | ||
validations: [], | ||
disabled: false, | ||
omitted: false | ||
}) | ||
|
||
formfield.createField('inputType', { | ||
name: 'Input Type', | ||
type: 'Symbol', | ||
localized: false, | ||
required: true, | ||
validations: | ||
[{ | ||
in: | ||
['text', | ||
'email', | ||
'textarea'] | ||
}], | ||
disabled: false, | ||
omitted: false | ||
}) | ||
|
||
formfield.changeEditorInterface('title', 'singleLine') | ||
|
||
formfield.changeEditorInterface('inputType', 'radio') | ||
|
||
formfield.changeEditorInterface('internalTitle', 'singleLine') | ||
} as MigrationFunction |
23 changes: 23 additions & 0 deletions
23
wcc-contentful-app/lib/generators/wcc/templates/section-contact-form/models/form_field.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
# This model represents the 'formField' content type in Contentful. Any linked | ||
# entries of the 'formField' content type will be resolved as instances of this class. | ||
# It exposes #find, #find_by, and #find_all methods to query Contentful. | ||
class FormField < WCC::Contentful::Model::FormField | ||
# Add custom validations to ensure that app-specific properties exist: | ||
# validate_field :foo, :String, :required | ||
# validate_field :bar_links, :Array, link_to: %w[bar baz] | ||
|
||
# Override functionality or add utilities | ||
# | ||
# # Example: override equality | ||
# def ===(other) | ||
# ... | ||
# end | ||
# | ||
# # Example: override "name" attribute to always be camelized. | ||
# # `@name` is populated by the gem in the initializer. | ||
# def name | ||
# @name_camelized ||= @name.camelize(true) | ||
# end | ||
end |
23 changes: 23 additions & 0 deletions
23
...tful-app/lib/generators/wcc/templates/section-contact-form/models/section_contact_form.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
# This model represents the 'section-contact-form' content type in Contentful. Any linked | ||
# entries of the 'section-contact-form' content type will be resolved as instances of this class. | ||
# It exposes .find, .find_by, and .find_all methods to query Contentful. | ||
class SectionContactForm < WCC::Contentful::Model::SectionContactForm | ||
# Add custom validations to ensure that app-specific properties exist: | ||
# validate_field :foo, :String, :required | ||
# validate_field :bar_links, :Array, link_to: %w[bar baz] | ||
|
||
# Override functionality or add utilities | ||
# | ||
# # Example: override equality | ||
# def ===(other) | ||
# ... | ||
# end | ||
# | ||
# # Example: override "title" attribute to always be titlecase. | ||
# # `@title` is populated by the gem in the initializer. | ||
# def title | ||
# @title_titlecased ||= @title.titlecase | ||
# end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class WCC::Contentful::Model::FormField < WCC::Contentful::Model | ||
end |
Oops, something went wrong.