Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes#54 Fixes#33 build the root pages & Logout #56

Merged
merged 24 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Application Configurations
APP_BASE_URL="miru.saeloun.com"
APP_BASE_URL="<Replace with app url>"

# Postgres Database config variables
DATABASE_URL="postgres://root:password@localhost/miru_web?encoding=utf8&pool=5&timeout=5000"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ GEM
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
parallel (1.21.0)
parser (3.0.3.2)
Expand Down
Binary file added app/assets/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/assets/images/miru-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@

class ApplicationController < ActionController::Base
before_action :authenticate_user!

def redirect_path
path = case current_user.role
when "owner" || "admin"
dashboard_index_path
else
time_trackings_path
end
redirect_to path
end
end
7 changes: 0 additions & 7 deletions app/controllers/home_controller.rb

This file was deleted.

6 changes: 6 additions & 0 deletions app/controllers/time_trackings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class TimeTrackingsController < ApplicationController
def index
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

module HomeHelper
module TimeTrackingsHelper
end
5 changes: 5 additions & 0 deletions app/javascript/images/miru-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import * as ActiveStorage from "@rails/activestorage";
import Rails from "@rails/ujs";
import * as ReactRailsUJS from "react_ujs";

import "alpine-turbo-drive-adapter";
require("alpinejs");

import "@fontsource/plus-jakarta-sans";

global.toastr = require("toastr");
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#

class User < ApplicationRecord
enum role: { admin: 0, employee: 1 }, _default: "employee"
enum role: { owner: 0, admin: 1, employee: 2 }, _default: "employee"

validates :first_name, :last_name, :email, :encrypted_password, presence: true
validates :first_name, :last_name, length: { maximum: 50 }
Expand Down
5 changes: 3 additions & 2 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<h1>Dashboard#index</h1>
<p>Find me in app/views/dashboard/index.html.erb</p>
<div class="" id="root-page">
<%= render "partial/navbar" %>
</div>
14 changes: 6 additions & 8 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
<%= f.password_field :password, autocomplete: "current-password", class: "p-2 w-full bg-miru-grey-200 text-sm" %>
</div>
<% if devise_mapping.rememberable? %>
<%
=begin%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<%
=end%>
<% begin %>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end %>
<% end %>
<div class="actions mt-3">
<%= f.submit "SIGN IN", class: "p-2 w-full bg-miru-grey-400 font-bold text-white text-base hover:bg-miru-black-1000 cursor-pointer" %>
Expand Down
1 change: 0 additions & 1 deletion app/views/home/index.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<%= csp_meta_tag %>
<%#= stylesheet_link_tag "inter-font", "data-turbo-track": "reload" %>
<%= stylesheet_pack_tag "application" %>
<%= javascript_pack_tag 'application' %>
<%= javascript_pack_tag "application"%>
</head>
<body>
<main class="min-h-screen bg-miru-white-400">
Expand Down
134 changes: 134 additions & 0 deletions app/views/partial/_navbar.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<nav class="bg-white shadow" x-data="{ isOpen: false}">
<div class="max-w-8xl mx-auto px-2 md:px-11">
<div class="relative flex justify-between h-16">
<div class="absolute inset-y-0 left-0 flex items-center md:hidden">
<!-- Mobile menu button -->
<button type="button" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500" aria-controls="mobile-menu" aria-expanded="false" @click="isOpen = !isOpen" @keydown.escape="isOpen = false">
<span class="sr-only">Open main menu</span>
<!--
Icon when menu is closed.

Heroicon name: outline/menu

Menu open: "hidden", Menu closed: "block"
-->
<div>
<svg class="block h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
</svg>
<!--
Icon when menu is open.

Heroicon name: outline/x

Menu open: "block", Menu closed: "hidden"
-->
<svg class="hidden h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</div>
</button>
</div>
<div class="flex-1 flex items-center justify-center md:items-stretch md:justify-start">
<!-- Logo -->
<div class="flex-shrink-0 flex items-center">
<a href="/" class="font-semibold text-xl tracking-tight">
<img class="block lg:hidden h-8 w-auto md:mr-12" src="/miru-logo.svg" alt="miru web">
<img class="hidden lg:block h-8 w-auto lg:mr-32" src="/miru-logo.svg" alt="miru web">
</a>
</div>
<div class="hidden md:mx-3 md:flex md:space-x-2 lg:space-x-8">
<!-- Current: "border-indigo-500 text-gray-900", Default: "border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700" -->
<% if (current_user.admin? || current_user.owner?) %>
<a href="/dashboard" class="<%= request.path == "/dashboard" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Dashboard
</a>
<% end %>
<a href="/time-tracking" class="<%= request.path == "/time-tracking" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Time Tracking
</a>
<% if (current_user.admin? || current_user.owner?) %>
<a href="/team" class="<%= request.path == "/team" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Team
</a>
<% end %>
<a href="/clients" class="<%= request.path == "/clients" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Clients
</a>
<a href="/projects" class="<%= request.path == "/project" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Projects
</a>
<% if (current_user.admin? || current_user.owner?) %>
<a href="/invoice" class="<%= request.path == "/invoice" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Invoice
</a>
<% end %>
<% if (current_user.admin? || current_user.owner?) %>
<a href="/report" class="<%= request.path == "/report" ? "text-miru-han-purple-1000" : "border-transparent text-gray-500 hover:text-gray-700" %> inline-flex items-center px-1 pt-1 text-sm font-medium">
Report
</a>
<% end %>
</div>
</div>
<div class="absolute inset-y-0 right-0 flex items-center pr-2 md:static md:inset-auto md:ml-6 md:pr-0">
<button type="button" class="bg-white p-1 rounded-full text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
<span class="sr-only">View notifications</span>
<!-- Heroicon name: outline/bell -->
<svg class="h-6 w-6" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" aria-hidden="true">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9" />
</svg>
</button>
<!-- Profile dropdown -->
<div class="ml-3 relative" x-data="{ isOpen: false}">
<div class="hover:border-miru-han-purple-1000 border-2 rounded-full border-miru-white-1000">
<button type="button" class="bg-white rounded-full flex text-sm focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-miru-han-purple-1000" id="user-menu-button" aria-expanded="false" aria-haspopup="true" @click="isOpen = !isOpen" @keydown.escape="isOpen = false">
<span class="sr-only">Open user menu</span>
<img class="h-8 w-8 rounded-full" src="/avtar.svg" alt="profile">
</button>
</div>
<!--
Dropdown menu, show/hide based on menu state.

Entering: "transition ease-out duration-200"
From: "transform opacity-0 scale-95"
To: "transform opacity-100 scale-100"
Leaving: "transition ease-in duration-75"
From: "transform opacity-100 scale-100"
To: "transform opacity-0 scale-95"
-->
<div x-show="isOpen" @click.away="isOpen = false">
<div class="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg py-1 bg-white ring-1 ring-black ring-opacity-5 focus:outline-none" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1">
<!-- Active: "bg-gray-100", Not Active: "" -->
<a href="/profile" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem" tabindex="-1" id="user-menu-item-0">Your Profile</a>
<a href="/settings" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100" role="menuitem" tabindex="-1" id="user-menu-item-1">Settings</a>
<div class= "block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<%= button_to "logout", destroy_user_session_path, method: :delete, role: "menuitem", tabindex: "-1", id: "user-menu-item-2"%>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Mobile menu, show/hide based on menu state. -->
<div class="flex">
<div class="md:hidden">
<div class="pt-2 pb-4 space-y-1" x-show="isOpen" @click.away="isOpen = false">
<!-- Current: "bg-indigo-50 border-indigo-500 text-indigo-700", Default: "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" -->
<% if (current_user.admin? || current_user.owner?) %>
<a href="/dashboard" class="<%= request.path == "/dashboard" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Dashboard</a>
<% end %>
<a href="/time-tracking" class="<%= request.path == "/time-tracking" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Time Tracking</a>
<% if (current_user.admin? || current_user.owner?) %>
<a href="/team" class="<%= request.path == "/team" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Team</a>
<% end %>
<a href="/clients" class="<%= request.path == "/clients" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Clients</a>
<a href="/projects" class="<%= request.path == "/projects" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Projects</a>
<% if (current_user.admin? || current_user.owner?) %>
<a href="/invoice" class="<%= request.path == "/invoice" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Invoice</a>
<a href="/report" class="<%= request.path == "/report" ? "bg-indigo-50 border-indigo-500 text-indigo-700" : "border-transparent text-gray-500 hover:bg-gray-50 hover:border-gray-300 hover:text-gray-700" %> block pl-3 pr-4 py-2 border-l-4 text-base font-medium">Report</a>
<% end %>
</div>
</div>
</div>
</nav>
3 changes: 3 additions & 0 deletions app/views/time_trackings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="" id="root-page">
<%= render "partial/navbar" %>
</div>
6 changes: 3 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Rails.application.routes.draw do
devise_for :users, controllers: { registrations: "users/registrations" }
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

root "dashboard#index"
root to: "application#redirect_path"
resources :dashboard, only: [:index]

get "*path", to: "home#index", via: :all
resources :time_trackings, only: [:index], path: "time-tracking"
end
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"@types/react-dom": "^17.0.11",
"@typescript-eslint/eslint-plugin": "^5.7.0",
"@typescript-eslint/parser": "^5.7.0",
"alpine-turbo-drive-adapter": "^2.0.0",
"alpinejs": "^2.2.5",
"autoprefixer": "~9",
"axios": "^0.24.0",
"babel-plugin-js-logger": "^1.0.17",
Expand Down
4 changes: 4 additions & 0 deletions public/avtar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/favicon.ico
Binary file not shown.
5 changes: 5 additions & 0 deletions public/miru-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
9 changes: 7 additions & 2 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
expect(user).to be_valid
end

it "checks if it is an admin" do
it "checks if it is an owner" do
user.role = 0
expect(user).to be_owner
end

it "checks if it is an admin" do
user.role = 1
expect(user).to be_admin
end

it "checks if it is an employee" do
user.role = 1
user.role = 2
expect(user).to be_employee
end

Expand Down
Empty file.
Loading