Merge pull request #48 from bumi/email-notification

Added the notify_email column to the forms table
This commit is contained in:
bumi 2020-07-22 16:30:34 +02:00 committed by GitHub
commit 854dbee7d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 93 additions and 35 deletions

View File

@ -28,11 +28,11 @@ gem 'lockbox'
gem 'airrecord'
gem 'aws-sdk-s3', require: false
gem 'google-api-client'
gem 'pagy'
gem 'rack-cors'
gem 'sentry-raven'
gem 'sequenced'
gem 'sorcery'
gem 'pagy'
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console

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">

View File

@ -1,10 +1,7 @@
# frozen_string_literal: true
if ENV['GOOGLE_DEMO_FORM_ID'].present?
GOOGLE_DEMO_FORM = Form.find_by(id: ENV['GOOGLE_DEMO_FORM_ID'])
end
if ENV['AIRTABLE_DEMO_FORM_ID'].present?
AIRTABLE_DEMO_FORM = Form.find_by(id: ENV['AIRTABLE_DEMO_FORM_ID'])
end
GOOGLE_DEMO_FORM = Form.find_by(id: ENV['GOOGLE_DEMO_FORM_ID']) if ENV['GOOGLE_DEMO_FORM_ID'].present?
AIRTABLE_DEMO_FORM = Form.find_by(id: ENV['AIRTABLE_DEMO_FORM_ID']) if ENV['AIRTABLE_DEMO_FORM_ID'].present?
AIRTABLE_DEMO_EMBED_URL = ENV['AIRTABLE_DEMO_EMBED_URL']

View File

@ -1,15 +1,12 @@
# encoding: utf-8
# frozen_string_literal: true
# Pagy initializer file (3.8.0)
# Customize only what you really need and notice that Pagy works also without any of the following lines.
# Should you just cherry pick part of this file, please maintain the require-order of the extras
# Extras
# See https://ddnexus.github.io/pagy/extras
# Backend Extras
# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
@ -29,7 +26,6 @@
# See https://ddnexus.github.io/pagy/extras/searchkick
# require 'pagy/extras/searchkick'
# Frontend Extras
# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
@ -66,7 +62,6 @@ require 'pagy/extras/bulma'
# See https://ddnexus.github.io/pagy/extras/navs#steps
# Pagy::VARS[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
# Feature Extras
# Headers extra: http response headers (and other helpers) useful for API pagination
@ -101,19 +96,15 @@ require 'pagy/extras/bulma'
# See https://ddnexus.github.io/pagy/extras/trim
# require 'pagy/extras/trim'
# Pagy Variables
# See https://ddnexus.github.io/pagy/api/pagy#variables
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
# per instance by just passing them to Pagy.new or the #pagy controller method
# Instance variables
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
# Pagy::VARS[:items] = 20 # default
# Other Variables
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
# Pagy::VARS[:size] = [1,4,4,1] # default
@ -122,7 +113,6 @@ require 'pagy/extras/bulma'
# Pagy::VARS[:anchor] = '#anchor' # example
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
# Rails
# Rails: extras assets path required by the helpers that use javascript
@ -130,7 +120,6 @@ require 'pagy/extras/bulma'
# See https://ddnexus.github.io/pagy/extras#javascript
# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
# I18n
# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
@ -160,11 +149,10 @@ require 'pagy/extras/bulma'
# filepath: 'path/to/pagy-xyz.yml',
# pluralize: lambda{|count| ... } )
# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
# than the default pagy internal i18n (see above)
# See https://ddnexus.github.io/pagy/extras/i18n
# require 'pagy/extras/i18n'
# Default i18n key
# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default
# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default

View File

@ -7,6 +7,7 @@ Rails.application.routes.draw do
member do
get :form
get :setup
get :notification
end
resources :submissions
end
@ -29,7 +30,7 @@ Rails.application.routes.draw do
get '/auth' => 'sessions#auth', :as => :auth
get '/demo(/:backend)' => 'home#demo', :as => :demo
get '/contact', to: redirect('/#contact-us'), :as => :contact
get '/contact', to: redirect('/#contact-us'), as: :contact
get '/help', to: redirect('https://www.notion.so/Tinyforms-Help-Center-04f13b5908bc46cfb4283079a3cb1149')
get '/privacy', to: redirect('https://www.notion.so/Privacy-Policy-f4bd2d6c8e7742bbb9ca1c952aec0379')
get '/terms', to: redirect('https://www.notion.so/Terms-and-Conditions-d73fd11089164eac91ede8ab4b4da5b3')

View File

@ -0,0 +1,5 @@
class AddNotifyEmailToForms < ActiveRecord::Migration[6.0]
def change
add_column :forms, :notify_email, :string
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_06_10_131725) do
ActiveRecord::Schema.define(version: 2020_07_02_202828) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -62,6 +62,7 @@ ActiveRecord::Schema.define(version: 2020_06_10_131725) do
t.string "airtable_table"
t.string "backend_name"
t.string "google_spreadsheet_sheet"
t.string "notify_email"
end
create_table "submissions", force: :cascade do |t|