From 3cceaf5cc776e272d011591bb14e7b854071460e Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Sat, 1 Jul 2023 13:43:46 +0300 Subject: [PATCH] add developer newsletters form --- app/controllers/newsletters_controller.rb | 19 +++++++++++++++++++ app/controllers/setup_controller.rb | 2 +- app/views/newsletters/show.html.erb | 14 ++++++++++++++ config/routes.rb | 1 + lib/docuseal.rb | 1 + 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 app/controllers/newsletters_controller.rb create mode 100644 app/views/newsletters/show.html.erb diff --git a/app/controllers/newsletters_controller.rb b/app/controllers/newsletters_controller.rb new file mode 100644 index 00000000..37cc8645 --- /dev/null +++ b/app/controllers/newsletters_controller.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class NewslettersController < ApplicationController + def show; end + + def update + Faraday.post(Docuseal::NEWSLETTER_URL, newsletter_params.to_json, 'Content-Type' => 'application/json') + rescue StandardError => e + Rails.logger.error(e) + ensure + redirect_to root_path + end + + private + + def newsletter_params + params.require(:user).permit(:email) + end +end diff --git a/app/controllers/setup_controller.rb b/app/controllers/setup_controller.rb index 83bb3788..2b42cc9d 100644 --- a/app/controllers/setup_controller.rb +++ b/app/controllers/setup_controller.rb @@ -30,7 +30,7 @@ class SetupController < ApplicationController sign_in(@user) - redirect_to root_path + redirect_to newsletter_path else render :index, status: :unprocessable_entity end diff --git a/app/views/newsletters/show.html.erb b/app/views/newsletters/show.html.erb new file mode 100644 index 00000000..da3730e5 --- /dev/null +++ b/app/views/newsletters/show.html.erb @@ -0,0 +1,14 @@ +
+

👨‍💻 Developer Newsletters

+ <%= form_for current_user, url: newsletter_path do |f| %> +
+ <%= f.email_field :email, placeholder: 'Email', required: true, class: 'base-input' %> +
+
+ <%= f.button button_title, class: 'base-button' %> +
+
+ Skip +
+ <% end %> +
diff --git a/config/routes.rb b/config/routes.rb index b8ed904f..7a902307 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,6 +28,7 @@ Rails.application.routes.draw do resources :dashboard, only: %i[index] resources :setup, only: %i[index create] + resource :newsletter, only: %i[show update] resources :users, only: %i[new create edit update destroy] resources :submissions, only: %i[show destroy] resources :templates, only: %i[new create edit show destroy] do diff --git a/lib/docuseal.rb b/lib/docuseal.rb index 72c0cee7..3cd5c170 100644 --- a/lib/docuseal.rb +++ b/lib/docuseal.rb @@ -2,6 +2,7 @@ module Docuseal PRODUCT_URL = 'https://www.docuseal.co' + NEWSLETTER_URL = "#{PRODUCT_URL}/newsletters".freeze PRODUCT_NAME = 'DocuSeal' DEFAULT_APP_URL = 'http://localhost:3000'