Skip to content

Commit

Permalink
Introduce flash for matchmatching groups
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxagon committed Jan 31, 2024
1 parent 720bdf2 commit fff378c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
18 changes: 16 additions & 2 deletions app/controllers/matchmaking_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ def new
end

def create
MatchmakingGroup.create(group_params.merge(slack_user_id: @current_user.slack_user_id))
if MatchmakingGroup.exists?(name: group_params[:name])
flash[:error] = "Group already exists"
else
MatchmakingGroup.create(group_params.merge(slack_user_id: @current_user.slack_user_id))
flash[:notice] = "Group created"
end

redirect_to matchmaking_groups_path
end

Expand All @@ -21,7 +27,15 @@ def edit

def update
@group = MatchmakingGroup.find_by(id: params[:id])
@group.update(group_params)

if @group.name != group_params[:name] && MatchmakingGroup.exists?(name: group_params[:name])
flash[:error] = "Other group already exists with that name"
else
@group = MatchmakingGroup.find_by(id: params[:id])
@group.update(group_params)

flash[:notice] = "Group updated"
end
redirect_to matchmaking_groups_path
end

Expand Down
8 changes: 6 additions & 2 deletions app/views/matchmaking_groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="w-full">
<% if notice.present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium inline-block" id="notice"><%= notice %></p>
<% if flash[:notice].present? %>
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium inline-block" id="notice"><%= flash[:notice] %></p>
<% end %>
<% if flash[:error].present? %>
<p class="py-2 px-3 bg-red-50 mb-5 text-red-500 font-medium inline-block" id="error"><%= flash[:error] %></p>
<% end %>

<div class="flex justify-between items-center">
Expand Down

0 comments on commit fff378c

Please sign in to comment.