Add initial user show page

This commit is contained in:
Trevor Vallender 2024-05-29 17:17:06 +01:00
parent df0854ac39
commit 3e7909c02b
8 changed files with 33 additions and 3 deletions

View File

@ -5,7 +5,7 @@ class TableInvitesController < ApplicationController
before_action :set_table_invite, only: [ :edit, :update ] before_action :set_table_invite, only: [ :edit, :update ]
def index def index
@table_invites = TableInvite.where(email: Current.user.email) @table_invites = TableInvite.where(email: Current.user.email).not_responded
end end
def new def new

View File

@ -2,6 +2,7 @@
class UsersController < ApplicationController class UsersController < ApplicationController
skip_before_action :authenticate, only: [ :new, :create ] skip_before_action :authenticate, only: [ :new, :create ]
before_action :set_user, only: [ :show ]
def new def new
@user = User.new @user = User.new
@ -20,6 +21,12 @@ class UsersController < ApplicationController
end end
end end
def show
if @user == Current.user
@table_invites = TableInvite.where(email: @user.email).not_responded
end
end
private private
def user_params def user_params
@ -32,4 +39,8 @@ class UsersController < ApplicationController
:last_name, :last_name,
) )
end end
def set_user
@user = User.find_by(username: params[:id])
end
end end

View File

@ -37,6 +37,10 @@ class User < ApplicationRecord
scope :verified, -> { where(verified: true) } scope :verified, -> { where(verified: true) }
scope :unverified, -> { where(verified: false) } scope :unverified, -> { where(verified: false) }
def to_param
username
end
def full_name def full_name
return first_name if last_name.blank? return first_name if last_name.blank?

View File

@ -4,7 +4,7 @@
<% if @table_invites.any? %> <% if @table_invites.any? %>
<% @table_invites.each do |table_invite| %> <% @table_invites.each do |table_invite| %>
<%= link_to table_invite.table, edit_table_invite_path(table_invite) %> <%= link_to table_invite.table.name, edit_table_invite_path(table_invite) %>
<% end %> <% end %>
<% else %> <% else %>
<p><%= t(".no_table_invites") %></p> <p><%= t(".no_table_invites") %></p>

View File

@ -0,0 +1,7 @@
<%= content_for :title, @user.username %>
<h2><%= @user.username %></h2>
<% if @user == Current.user && @table_invites.any? %>
<%= link_to t(".your_invites"), table_invites_path %>
<% end %>

View File

@ -122,6 +122,8 @@ en:
create: create:
error: "Could not create account: %{error}" error: "Could not create account: %{error}"
success: "Thanks for joining Tabletop Companion, %{name}! Please check your email to verify your address." success: "Thanks for joining Tabletop Companion, %{name}! Please check your email to verify your address."
show:
your_invites: Your invites
user_mailer: user_mailer:
email_verified: email_verified:
content: |- content: |-

View File

@ -8,7 +8,7 @@ Rails.application.routes.draw do
get "login" => "sessions#new", as: :login get "login" => "sessions#new", as: :login
delete "logout" => "sessions#destroy", as: :logout delete "logout" => "sessions#destroy", as: :logout
resources :users, only: [ :new, :create ] resources :users, only: [ :new, :create, :show ]
resources :account_verifications, only: [ :show ] resources :account_verifications, only: [ :show ]
resources :sessions, only: [ :new, :create, :destroy ] resources :sessions, only: [ :new, :create, :destroy ]

View File

@ -8,6 +8,12 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
assert_response :success assert_response :success
end end
test "should get show" do
sign_in users(:trevor)
get user_url(users(:trevor))
assert_response :success
end
test "should create user" do test "should create user" do
assert_changes("User.count", +1) do assert_changes("User.count", +1) do
post(users_url, params: { user: user_params }) post(users_url, params: { user: user_params })