Skip to content

Commit

Permalink
adds general settings, implements updating the company name
Browse files Browse the repository at this point in the history
  • Loading branch information
fermion committed Jan 14, 2024
1 parent 01271c8 commit 610c4aa
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ def require_user!
save_passwordless_redirect_location!(User)
redirect_to auth_sign_in_url, flash: { notice: 'Please sign in.' }
end

def require_company_owner_or_admin!
return if current_user.owner? || current_user.admin?
redirect_to root_url, flash: { error: 'You are not authorized to access this page.' }
end
end
17 changes: 17 additions & 0 deletions app/controllers/settings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
class SettingsController < ApplicationController

before_action :require_company_owner_or_admin!
def show
end

def update
if current_company.update(update_params)
flash[:success] = "Company updated successfully"
redirect_to settings_path
else
render :show
end
end

private

def update_params
params.require(:company).permit(:name)
end
end
10 changes: 10 additions & 0 deletions app/javascript/controllers/flash_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Controller } from "@hotwired/stimulus"

// Connects to data-controller="settings-tabs"
export default class extends Controller {

close() {
this.element.remove()
}
}

4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ class User < ApplicationRecord
def owner?
memberships.find_by(company: current_company).role == Membership::OWNER
end

def admin?
memberships.find_by(company: current_company).role == Membership::ADMIN
end
end
27 changes: 26 additions & 1 deletion app/views/settings/show.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
<%= render(Settings::TabsComponent.new) %>
<%= render(Settings::TabsComponent.new) %>

<div class="bg-white p-4 mt-4">
<%= form_for current_company, url: settings_path do |f| %>
<div class="space-y-12">
<div class="border-b border-gray-900/10 pb-12">
<h2 class="text-base font-semibold leading-7 text-gray-900">General settings</h2>
<p class="mt-1 text-sm leading-6 text-gray-600">This is an area that might make sense for a company's default settings (projects bill monthly, etc.)</p>

<div class="mt-10 grid grid-cols-1 gap-x-6 gap-y-8 sm:grid-cols-6">
<div class="sm:col-span-4">
<%= f.label :name, "Company Name", class: "block text-sm font-medium leading-6 text-gray-900" %>

<div class="mt-2">
<%= f.text_field :name, class: "block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" %>
</div>
</div>
</div>
</div>
</div>

<div class="mt-6 flex items-center justify-end gap-x-6">
<%= f.submit "Save", class: "rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %>
</div>
<% end %>
</div>
4 changes: 2 additions & 2 deletions app/views/shared/_flash.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<% end %>
<% if flash[:success].present? %>
<div class="rounded-md bg-green-50 p-4">
<div class="rounded-md bg-green-50 p-4" data-controller="flash">
<div class="flex">
<div class="flex-shrink-0">
<svg class="h-5 w-5 text-green-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
Expand All @@ -47,7 +47,7 @@
</div>
<div class="ml-auto pl-3">
<div class="-mx-1.5 -my-1.5">
<button type="button" class="inline-flex rounded-md bg-green-50 p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2 focus:ring-offset-green-50">
<button data-action="click->flash#close" type="button" class="inline-flex rounded-md bg-green-50 p-1.5 text-green-500 hover:bg-green-100 focus:outline-none focus:ring-2 focus:ring-green-600 focus:ring-offset-2 focus:ring-offset-green-50">
<span class="sr-only">Dismiss</span>
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
<path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

resource :dashboard, only: [:show], controller: "dashboard"

resource :settings, only: [:show], controller: "settings" do
resource :settings, only: [:show, :update], controller: "settings" do
resource :billing_information, only: [:show, :edit, :update], controller: "settings/billing_information"
end

Expand Down

0 comments on commit 610c4aa

Please sign in to comment.