feat: Add Installation onboarding flow (#1640)
Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class AccountBuilder
|
||||
include CustomExceptions::Account
|
||||
pattr_initialize [:account_name!, :email!, :confirmed!, :user, :user_full_name]
|
||||
pattr_initialize [:account_name!, :email!, :confirmed!, :user, :user_full_name, :user_password]
|
||||
|
||||
def perform
|
||||
if @user.nil?
|
||||
@@ -26,7 +26,7 @@ class AccountBuilder
|
||||
if address.valid? # && !address.disposable?
|
||||
true
|
||||
else
|
||||
raise InvalidEmail.new(valid: address.valid?) # , disposable: address.disposable?})
|
||||
raise InvalidEmail.new(valid: address.valid?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@ class AccountBuilder
|
||||
end
|
||||
|
||||
def create_user
|
||||
password = SecureRandom.alphanumeric(12)
|
||||
password = user_password || SecureRandom.alphanumeric(12)
|
||||
|
||||
@user = User.new(email: @email,
|
||||
password: password,
|
||||
|
||||
@@ -3,6 +3,7 @@ class DashboardController < ActionController::Base
|
||||
|
||||
before_action :set_global_config
|
||||
around_action :switch_locale
|
||||
before_action :ensure_installation_onboarding, only: [:index]
|
||||
|
||||
layout 'vueapp'
|
||||
|
||||
@@ -24,4 +25,8 @@ class DashboardController < ActionController::Base
|
||||
APP_VERSION: Chatwoot.config[:version]
|
||||
)
|
||||
end
|
||||
|
||||
def ensure_installation_onboarding
|
||||
redirect_to '/installation/onboarding' if ::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
end
|
||||
end
|
||||
|
||||
36
app/controllers/installation/onboarding_controller.rb
Normal file
36
app/controllers/installation/onboarding_controller.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
class Installation::OnboardingController < ApplicationController
|
||||
before_action :ensure_installation_onboarding
|
||||
|
||||
def index; end
|
||||
|
||||
def create
|
||||
begin
|
||||
AccountBuilder.new(
|
||||
account_name: onboarding_params.dig(:user, :company),
|
||||
user_full_name: onboarding_params.dig(:user, :name),
|
||||
email: onboarding_params.dig(:user, :email),
|
||||
user_password: params.dig(:user, :password),
|
||||
confirmed: true
|
||||
).perform
|
||||
rescue StandardError => e
|
||||
redirect_to '/', flash: { error: e.message } and return
|
||||
end
|
||||
finish_onboarding
|
||||
redirect_to '/'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def onboarding_params
|
||||
params.permit(:subscribe_to_updates, user: [:name, :company, :email])
|
||||
end
|
||||
|
||||
def finish_onboarding
|
||||
::Redis::Alfred.delete(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
ChatwootHub.register_instance(onboarding_params) if onboarding_params[:subscribe_to_updates]
|
||||
end
|
||||
|
||||
def ensure_installation_onboarding
|
||||
redirect_to '/' unless ::Redis::Alfred.get(::Redis::Alfred::CHATWOOT_INSTALLATION_ONBOARDING)
|
||||
end
|
||||
end
|
||||
@@ -1,15 +1,36 @@
|
||||
@import '../variables';
|
||||
|
||||
.superadmin-body {
|
||||
background: $color-background;
|
||||
background: var(--color-background);
|
||||
|
||||
.hero--title {
|
||||
font-size: var(--font-size-mega);
|
||||
font-weight: var(--font-weight-light);
|
||||
margin-top: var(--space-large);
|
||||
}
|
||||
}
|
||||
|
||||
.alert-box {
|
||||
background-color: $alert-color;
|
||||
background-color: var(--r-500);
|
||||
border-radius: 5px;
|
||||
color: $color-white;
|
||||
color: var(--color-white);
|
||||
font-size: 14px;
|
||||
margin-bottom: 14px;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.update-subscription--checkbox {
|
||||
display: flex;
|
||||
|
||||
input {
|
||||
line-height: 1.5;
|
||||
margin-right: var(--space-one);
|
||||
}
|
||||
|
||||
div {
|
||||
font-size: var(--font-size-small);
|
||||
line-height: 1.5;
|
||||
margin-bottom: var(--space-normal);
|
||||
}
|
||||
}
|
||||
|
||||
59
app/views/installation/onboarding/index.html.erb
Normal file
59
app/views/installation/onboarding/index.html.erb
Normal file
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SuperAdmin | Chatwoot</title>
|
||||
<%= javascript_pack_tag 'superadmin' %>
|
||||
<%= stylesheet_pack_tag 'superadmin' %>
|
||||
</head>
|
||||
<body data-gr-c-s-loaded="true">
|
||||
<div id="app" class="superadmin-body app-wrapper app-root">
|
||||
<div class="medium column login">
|
||||
<div class="text-center medium-12 login__hero align-self-top">
|
||||
<img
|
||||
src="/brand-assets/logo.svg"
|
||||
alt="Chatwoot logo"
|
||||
class="hero__logo"
|
||||
/>
|
||||
<h2 class="hero--title">
|
||||
Howdy, Welcome to Chatwoot 👋
|
||||
</h2>
|
||||
</div>
|
||||
<div class="row align-center">
|
||||
<div class="small-12 medium-4 column">
|
||||
<%= form_tag('/installation/onboarding', class: 'login-box column align-self-top') do %>
|
||||
<div class="column log-in-form">
|
||||
<% if flash[:error].present? %>
|
||||
<div data-alert class="alert-box warning"><%= flash[:error] %></div>
|
||||
<% end %>
|
||||
<label>
|
||||
<span>Name</span>
|
||||
<%= text_field :user, :name, placeholder: "Enter your full name. eg: Bruce Wayne", required: true %>
|
||||
</label>
|
||||
<label>
|
||||
<span>Company Name</span>
|
||||
<%= text_field :user, :company, placeholder: "Enter an account name. eg: Wayne Enterprises", required: true %>
|
||||
</label>
|
||||
<label>
|
||||
<span>Work Email</span>
|
||||
<%= email_field :user, :email, placeholder: "Enter your work email address. eg: bruce@wayne.enterprises", required: true %>
|
||||
</label>
|
||||
<label>
|
||||
<span>Password</span>
|
||||
<%= password_field :user, :password, placeholder: "Enter a password with 6 characters or more.", required: true %>
|
||||
</label>
|
||||
<div class="update-subscription--checkbox">
|
||||
<%= check_box_tag "subscribe_to_updates", 'true', true %>
|
||||
<div for="subscribe_to_updates">
|
||||
Subscribe to release notes, newsletters & product feedback surveys.
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" class="button nice large expanded">
|
||||
Finish Setup
|
||||
</button>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user