added the notification email method
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module ApplicationHelper
|
||||
include Pagy::Frontend
|
||||
include Pagy::Frontend
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
56
app/views/forms/notification.html.erb
Normal file
56
app/views/forms/notification.html.erb
Normal 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>
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user