Merge pull request #48 from bumi/email-notification

Added the notify_email column to the forms table
This commit is contained in:
2020-07-22 16:30:34 +02:00
committed by GitHub
14 changed files with 93 additions and 35 deletions

View File

@@ -17,9 +17,7 @@ class FormsController < ApplicationController
def index
@forms = current_user.forms
if @forms.empty?
redirect_to new_form_url
end
redirect_to new_form_url if @forms.empty?
end
def create
@@ -35,12 +33,20 @@ class FormsController < ApplicationController
@form = current_user.forms.find_by!(token: params[:id])
end
def notification
@form = current_user.forms.find_by!(token: params[:id])
end
def update
@form = current_user.forms.find_by!(token: params[:id])
if @form.update(form_params)
redirect_to form_url(@form)
else
render :edit
if form_params[:notify_email]
render :notification
else
render :edit
end
end
end
@@ -55,6 +61,6 @@ class FormsController < ApplicationController
private
def form_params
params.require(:form).permit(:title, :thank_you_url, :backend_name, :google_spreadsheet_sheet, :airtable_table, :airtable_api_key, :airtable_app_key)
params.require(:form).permit(:title, :thank_you_url, :backend_name, :google_spreadsheet_sheet, :airtable_table, :airtable_api_key, :airtable_app_key, :notify_email)
end
end

View File

@@ -1,5 +1,5 @@
# frozen_string_literal: true
module ApplicationHelper
include Pagy::Frontend
include Pagy::Frontend
end

View File

@@ -27,9 +27,7 @@ class Authentication < ApplicationRecord
c.access_token = access_token
c.refresh_token = refresh_token
c.expires_at = expires_at
if expires_at < 1.minute.from_now
refresh_from(c)
end
refresh_from(c) if expires_at < 1.minute.from_now
end
end
end

View File

@@ -18,6 +18,7 @@ class Form < ApplicationRecord
validates :airtable_api_key, presence: { if: :airtable? }
validates :airtable_app_key, presence: { if: :airtable? }
validates :airtable_table, presence: { if: :airtable? }
validates :notify_email, presence: true, on: :update, allow_blank: true
# TODO: use counter_cache option on association
def submissions_count
@@ -41,7 +42,11 @@ class Form < ApplicationRecord
def google?
backend_name == 'google_sheets'
end
def google; google?; end # TODO: remove this alias
# TODO: remove this alias
def google
google?
end
def backend
@backend ||= SpreadsheetBackends.const_get(backend_name.camelize).new(self)

View File

@@ -28,7 +28,7 @@
<ul class="menu-list">
<li><%= link_to "Form Settings", edit_form_url(@form), class: "is-active" %></li>
<li><%= link_to "Setup", setup_form_url(@form) %></li>
<li><a>Email notifications</a></li>
<li><%= link_to 'Email notifications', notification_form_url(@form) %></li>
</ul>
</aside>

View File

@@ -0,0 +1,56 @@
<div class="container">
<div class="is-pulled-right">
<%= link_to image_tag("#{@form.backend_name}-icon.svg", alt: @form.backend_name.humanize), @form.spreadsheet_url %>
</div>
<nav class="breadcrumb is-small has-bullet-separator" aria-label="breadcrumbs">
<ul>
<li>
<%= link_to forms_url do %>
<span class="icon is-small"><i class="fas fa-home" aria-hidden="true"></i></span>
Forms
<% end %>
</li>
<li><%= link_to @form.title, form_url(@form) %></li>
</ul>
</nav>
<h1 class="title">
<%= @form.title %>
</h1>
<div class="columns">
<div class="column is-one-quarter">
<aside class="menu">
<p class="menu-label">
General
</p>
<ul class="menu-list">
<li><%= link_to "Form Settings", edit_form_url(@form) %></li>
<li><%= link_to "Setup", setup_form_url(@form) %></li>
<li><%= link_to 'Email notifications', notification_form_url(@form), class: "is-active" %></li>
</ul>
</aside>
</div>
<div class="column">
<%= form_for @form, local: true do |f| %>
<div class="field">
<label class="label">Notification Email</label>
<div class="control">
<%= f.email_field :notify_email, class: 'input', placeholder: '', required: true, autocomplete: 'off' %>
</div>
<p class="help">On which Email would you like to be notified when a form is submitted?</p>
</div>
<div>
<%= f.submit 'Save', class: 'button is-primary' %>
</div>
<% end %>
</div>
</div>
</div>

View File

@@ -28,7 +28,7 @@
<ul class="menu-list">
<li><%= link_to "Form Settings", edit_form_url(@form) %></li>
<li><%= link_to "Setup", setup_form_url(@form), class: 'is-active' %></li>
<li><a>Email notifications</a></li>
<li><%= link_to 'Email notifications', notification_form_url(@form) %></li>
</ul>
</aside>

View File

@@ -26,8 +26,9 @@
<div class="column is-two-thirds">
<h3 class="title">One more step:</h3>
<p>Your document has been successfuly configured. \o/</p>
<p>
Set the <code>action</code> of your online form to <code><%= submission_url(@form) %></code> and make sure your fields have proper <code>name</code> attributes.
Now set the <code>action</code> of your HTML online form to <code><%= submission_url(@form) %></code> and make sure your fields have proper <code>name</code> attributes.
</p>
<h4 class="subtitle" style="margin-top:1em">Example:</h4>
<pre><code class="language-html">