Skip to content

Commit bd3c95a

Browse files
committed
💄 Make the warning on negative balance more annoying (closes #149)
1 parent 2cb8a2a commit bd3c95a

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

app/controllers/users_controller.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,7 @@ def buy_barcode
116116
def payment
117117
@user = User.find(params[:id])
118118
@user.payment(BigDecimal(params[:amount]))
119-
flash[:success] = "You just bought a drink and your new balance is #{show_amount(@user.balance)}. Thank you."
120-
if (@user.balance < 0) then
121-
flash[:warning] = "Your balance is below zero. Remember to compensate as soon as possible."
122-
end
119+
print_balance
123120
warn_user_if_audit
124121
no_resp_redir @user
125122
end
@@ -135,10 +132,7 @@ def stats
135132

136133
def buy_drink
137134
@user.buy(@drink)
138-
flash[:success] = "You just bought a drink and your new balance is #{show_amount(@user.balance)}. Thank you."
139-
if (@user.balance < 0) then
140-
flash[:warning] = "Your balance is below zero. Remember to compensate as soon as possible."
141-
end
135+
print_balance
142136
warn_user_if_audit
143137
no_resp_redir @user.redirect ? redirect_path(@user) : @user
144138
end
@@ -152,4 +146,13 @@ def warn_user_if_audit
152146
flash[:info] = "This transaction has been logged, because you set up your account that way. #{view_context.link_to 'Change?', edit_user_url(@user)}".html_safe
153147
end
154148
end
149+
150+
def print_balance
151+
flash[:success] = "You just bought a drink and your new balance is #{show_amount(@user.balance)}. Thank you."
152+
if (@user.balance < -50) then
153+
flash[:danger] = "Your balance is way below zero. Remember to compensate as soon as possible."
154+
elsif (@user.balance < 0) then
155+
flash[:warning] = "Your balance is below zero. Please remember to compensate."
156+
end
157+
end
155158
end

app/views/users/show.html.haml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
%dt
2828
= model_class.human_attribute_name(:balance)
2929
%dd
30-
= show_amount @user.balance
30+
- if @user.balance < -50
31+
.text-danger
32+
= show_amount @user.balance
33+
- elsif @user.balance < 0
34+
.text-warning
35+
= show_amount @user.balance
36+
- else
37+
.text-success
38+
= show_amount @user.balance
3139

3240
- if @wrapped
3341
.mt-3.alert.alert-info

0 commit comments

Comments
 (0)