diff --git a/Gemfile b/Gemfile index 7f793ee..97ede64 100644 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/app/controllers/forms_controller.rb b/app/controllers/forms_controller.rb index d941881..5fd4648 100644 --- a/app/controllers/forms_controller.rb +++ b/app/controllers/forms_controller.rb @@ -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 @@ -33,6 +31,12 @@ class FormsController < ApplicationController def edit @form = current_user.forms.find_by!(token: params[:id]) + puts "===========#{@form.notify_email}=======================" + end + + def notification + puts '' + @form = current_user.forms.find_by!(token: params[:id]) end def update @@ -55,6 +59,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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c2ebd8c..0e0edb4 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ApplicationHelper - include Pagy::Frontend + include Pagy::Frontend end diff --git a/app/models/authentication.rb b/app/models/authentication.rb index e74ac3f..6491af9 100644 --- a/app/models/authentication.rb +++ b/app/models/authentication.rb @@ -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 diff --git a/app/models/form.rb b/app/models/form.rb index b01fdab..12d3a77 100644 --- a/app/models/form.rb +++ b/app/models/form.rb @@ -18,7 +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, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :update } # TODO: use counter_cache option on association def submissions_count @submissions_count ||= submissions.count @@ -41,7 +41,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) diff --git a/app/views/forms/edit.html.erb b/app/views/forms/edit.html.erb index 54d75e5..e7be0d5 100644 --- a/app/views/forms/edit.html.erb +++ b/app/views/forms/edit.html.erb @@ -28,7 +28,7 @@ diff --git a/app/views/forms/notification.html.erb b/app/views/forms/notification.html.erb new file mode 100644 index 0000000..7b75909 --- /dev/null +++ b/app/views/forms/notification.html.erb @@ -0,0 +1,56 @@ +
+
+ <%= link_to image_tag("#{@form.backend_name}-icon.svg", alt: @form.backend_name.humanize), @form.spreadsheet_url %> +
+ +

+ <%= @form.title %> +

+ + +
+
+ + + +
+
+ + <%= form_for @form, local: true do |f| %> + +
+ +
+ <%= f.email_field :notify_email, class: 'input', placeholder: '', required: true, autocomplete: 'off' %> +
+

On which Email would you like to be notified when a form is submitted?

+
+ +
+ <%= f.submit 'Save', class: 'button is-primary' %> +
+ <% end %> + +
+
+ +
diff --git a/app/views/forms/setup.html.erb b/app/views/forms/setup.html.erb index cbdd1b0..0dc9397 100644 --- a/app/views/forms/setup.html.erb +++ b/app/views/forms/setup.html.erb @@ -28,7 +28,7 @@ diff --git a/config/initializers/demo.rb b/config/initializers/demo.rb index 857dc99..ab5b956 100644 --- a/config/initializers/demo.rb +++ b/config/initializers/demo.rb @@ -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'] diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb index 3b416b3..9712381 100644 --- a/config/initializers/pagy.rb +++ b/config/initializers/pagy.rb @@ -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 \ No newline at end of file +# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default diff --git a/config/routes.rb b/config/routes.rb index 13f84c7..46627d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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') diff --git a/db/migrate/20200702202828_add_notify_email_to_forms.rb b/db/migrate/20200702202828_add_notify_email_to_forms.rb new file mode 100644 index 0000000..0f770e9 --- /dev/null +++ b/db/migrate/20200702202828_add_notify_email_to_forms.rb @@ -0,0 +1,5 @@ +class AddNotifyEmailToForms < ActiveRecord::Migration[6.0] + def change + add_column :forms, :notify_email, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index cfb8137..3e1e9ee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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|