Skip to content

Commit

Permalink
User initation mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
benreyn committed Oct 23, 2019
1 parent 9eb41bd commit ef8eea6
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 5 deletions.
23 changes: 23 additions & 0 deletions app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Users::InvitationsController < Devise::InvitationsController
layout "application"

def create
user = User.invite!(
email: user_params[:email],
name: user_params[:name],
partner: current_partner,
)
flash[:success] = "You have invited #{user.name} to join your organization!"
redirect_to users_path
end

def new
@user = current_partner.users.new
end

private

def user_params
params.require(:user).permit(:name, :email)
end
end
5 changes: 5 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class UsersController < ApplicationController
def index
@users = current_partner.users
end
end
16 changes: 13 additions & 3 deletions app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
<header class="app-header"><a class="app-header__logo" href="#">Partnerbase</a>
<ul class="app-nav">
<li class="dropdown">
<a class="app-nav__item" href="#" data-toggle="dropdown" aria-label="Open Profile Menu"><i class="fa fa-user fa-lg"></i></a>
<a class="app-nav__item" href="#" data-toggle="dropdown" aria-label="Open Profile Menu">
<i class="fa fa-user fa-lg"></i>
<%= current_user.name%>
</a>
<ul class="dropdown-menu settings-menu dropdown-menu-right">
<li><%= link_to edit_partner_path(current_partner), class: "dropdown-item" do %>
<li>
<%= link_to edit_partner_path(current_partner), class: "dropdown-item" do %>
<i class="fa fa-cog fa-lg"></i> Edit Partner
<% end %>
</li>
<li><%= link_to destroy_user_session_path, method: :delete, class: "dropdown-item" do %>
<li>
<%= link_to users_path, class: "dropdown-item" do %>
<i class="fa fa-users fa-lg"></i> My CoWorkers
<% end %>
</li>
<li>
<%= link_to destroy_user_session_path, method: :delete, class: "dropdown-item" do %>
<i class="fa fa-sign-out fa-lg"></i> Logout
<% end %>
</li>
Expand Down
3 changes: 3 additions & 0 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<main class="app-content">
<%= render partial: "layouts/navbar" %>
<%= render partial: "layouts/sidebar" %>
<div id="flash-message-container">
<%= render partial: "shared/flash" %>
</div>
<%= yield %>
<%= render partial: "layouts/footer" %>
</main>
Expand Down
6 changes: 6 additions & 0 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<% flash.each do |key, message| %>
<div class="alert #{key} alert-#{key} alert-dismissible" role="alert">
<a href="#" class="close" data-dismiss="alert" aria-label="close" style="text-decoration: none;"><%= fa_icon('times') %></a>
<%== message %>
</div>
<% end %>
41 changes: 41 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<%= form_with(model: user, local: true) do |form| %>
<div class="row">
<div class="col-md-12">
<% if user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="tile">
<h3 class="tile-title">Invite a New User to <%= current_partner.name %></h3>
<div class="tile-body">

<div class="form-horizontal">
<div class="form-group row">
<%= form.label :name, class: "control-label col-md-3"%>
<%= form.text_field :name, class: "col-md-8 form-control" %>
</div>
</div>

<div class="form-horizontal">
<div class="form-group row">
<%= form.label :email, class: "control-label col-md-3"%>
<%= form.text_field :email, class: "col-md-8 form-control" %>
</div>
</div>

<div class="actions">
<%= form.submit(class: 'btn btn-primary') %>
</div>
</div>
</div>
</div>
</div>
<% end %>
36 changes: 36 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<div class="app-title">
<div>
<h1><i class="fa fa-users"></i>Users</h1>
</div>
<ul class="app-breadcrumb breadcrumb">
<li class="breadcrumb-item"><i class="fa fa-users"></i></li>
<li class="breadcrumb-item"><a href="#">Users</a></li>
</ul>
</div>

<div class="row">
<div class="col-md-12">
<div class="tile">
<h3><%= current_partner.name %> Users </h3>
<%= link_to "Invite new user", new_user_invitation_path, class: "btn btn-sam btn-primary pull-right" %>

<table class="table table-striped">
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.name %></td>
<td><%= user.email %></td>
</tr>
<% end %>
</tbody>
</table>
<hr>
</div>
</div>
</div>
54 changes: 54 additions & 0 deletions app/views/users/invitations/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<div class="app-title">
<div>
<h1><i class="fa fa-new"></i>New User</h1>
</div>
<ul class="app-breadcrumb breadcrumb">
<li class="breadcrumb-item"><i class="fa fa-users"></i></li>
<li class="breadcrumb-item"><a href="#">New User</a></li>
</ul>
</div>

<%= form_for resource, :as => resource_name, :url => invitation_path(resource_name), :html => {:method => :post} do |form| %>
<div class="row">
<div class="col-md-12">
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="tile">
<h3 class="tile-title">Invite a New User to <%= current_partner.name %></h3>
<div class="tile-body">

<div class="form-horizontal">
<div class="form-group row">
<%= form.label :name, class: "control-label col-md-3"%>
<%= form.text_field :name, class: "col-md-8 form-control" %>
</div>
</div>

<div class="form-horizontal">
<div class="form-group row">
<%= form.label :email, class: "control-label col-md-3"%>
<%= form.text_field :email, class: "col-md-8 form-control" %>
</div>
</div>

<div class="actions">
<%= form.submit(class: 'btn btn-primary') %>
</div>
</div>
</div>
</div>
</div>
<% end %>
<%= link_to 'Back', users_path %>
6 changes: 5 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
end
end
mount flipper_app, at: "/flipper"
devise_for :users, controllers: { sessions: "users/sessions" }
devise_for :users, controllers: {
sessions: "users/sessions",
invitations: "users/invitations"
}
# TODO: remove these two
resources :children do
post :active
Expand All @@ -31,6 +34,7 @@
get :approve
end

resources :users, only: [:index]
resources :partner_requests, only: [:new, :create, :show, :index]
resources :family_requests, only: [:new, :create] do
resource :pickup_sheets, only: :show
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20191022214135_add_name_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :name, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_10_21_182550) do
ActiveRecord::Schema.define(version: 2019_10_22_214135) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -266,6 +266,7 @@
t.bigint "invited_by_id"
t.integer "invitations_count", default: 0
t.bigint "partner_id"
t.string "name"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["invitations_count"], name: "index_users_on_invitations_count"
Expand Down
4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
partner_status: "verified"
)
User.create(
name: Faker::Name.name,
password: "password",
password_confirmation: "password",
email: "[email protected]",
Expand Down Expand Up @@ -84,6 +85,7 @@
executive_director_email: "[email protected]"
)
User.create(
name: Faker::Name.name,
password: "password",
password_confirmation: "password",
email: "[email protected]",
Expand Down Expand Up @@ -132,6 +134,7 @@
executive_director_email: "[email protected]"
)
User.create(
name: Faker::Name.name,
password: "password",
password_confirmation: "password",
email: "[email protected]",
Expand All @@ -157,6 +160,7 @@
executive_director_email: "[email protected]"
)
User.create(
name: Faker::Name.name,
password: "password",
password_confirmation: "password",
email: "[email protected]",
Expand Down

0 comments on commit ef8eea6

Please sign in to comment.