Show unused invitations list
This commit is contained in:
		
							parent
							
								
									f7e48ad3a6
								
							
						
					
					
						commit
						a792d66c90
					
				| @ -6,7 +6,8 @@ class InvitationsController < ApplicationController | ||||
| 
 | ||||
|   # GET /invitations | ||||
|   def index | ||||
|     @invitations = current_user.invitations | ||||
|     @invitations_unused = current_user.invitations.unused | ||||
|     @invitations_used   = current_user.invitations.used | ||||
|   end | ||||
| 
 | ||||
|   # GET /invitations/a-random-invitation-token | ||||
|  | ||||
| @ -2,10 +2,13 @@ class Invitation < ApplicationRecord | ||||
|   # Relations | ||||
|   belongs_to :user | ||||
| 
 | ||||
|   # Validations | ||||
|   validates_presence_of :user | ||||
| 
 | ||||
|   # Hooks | ||||
|   before_create :generate_token | ||||
| 
 | ||||
|   # Scopes | ||||
|   scope :unused, -> { where(used_at: nil) } | ||||
|   scope :used, -> { where.not(used_at: nil) } | ||||
| 
 | ||||
|  | ||||
| @ -1,23 +1,46 @@ | ||||
| <section> | ||||
|   <h2>Invitations</h2> | ||||
| 
 | ||||
|   <% if @invitations_unused.any? %> | ||||
|     <table> | ||||
|       <thead> | ||||
|         <tr> | ||||
|         <th>Token</th> | ||||
|         <th>Created at</th> | ||||
|         <th colspan="3"></th> | ||||
|           <th>URL</th> | ||||
|         </tr> | ||||
|       </thead> | ||||
| 
 | ||||
|       <tbody> | ||||
|       <% @invitations.each do |invitation| %> | ||||
|         <% @invitations_unused.each do |invitation| %> | ||||
|           <tr> | ||||
|           <td><%= invitation.token %></td> | ||||
|           <td><%= invitation.created_at %></td> | ||||
|           <td><%= link_to 'Delete', invitation, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||||
|             <td><%= invitation_url(invitation.token) %></td> | ||||
|           </tr> | ||||
|         <% end %> | ||||
|       </tbody> | ||||
|     </table> | ||||
|   <% else %> | ||||
|     <p> | ||||
|       You do not have any invitations to give away yet. All good | ||||
|       things come in time. | ||||
|     </p> | ||||
|   <% end %> | ||||
| </section> | ||||
| 
 | ||||
| <% if @invitations_used.any? %> | ||||
|   <h3>Accepted Invitations</h3> | ||||
|   <table> | ||||
|     <thead> | ||||
|       <tr> | ||||
|         <th>URL</th> | ||||
|         <th>Used at</th> | ||||
|         <th>Invited user</th> | ||||
|       </tr> | ||||
|     </thead> | ||||
|     <tbody> | ||||
|       <% @invitations_used.each do |invitation| %> | ||||
|         <tr> | ||||
|           <td><%= invitation_url(invitation.token) %></td> | ||||
|           <td><%= invitation.used_at %></td> | ||||
|           <td><%= User.find(invitation.invited_user_id).address %></td> | ||||
|         </tr> | ||||
|       <% end %> | ||||
|     </tbody> | ||||
|   </table> | ||||
| <% end %> | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| FactoryBot.define do | ||||
|   factory :invitation do | ||||
|     id { 1 } | ||||
|     token { "abcdef123456" } | ||||
|     user | ||||
|   end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user