diff --git a/app/helpers/auth_messages_helper.rb b/app/helpers/auth_messages_helper.rb new file mode 100644 index 00000000..116ea654 --- /dev/null +++ b/app/helpers/auth_messages_helper.rb @@ -0,0 +1,6 @@ +module AuthMessagesHelper + def auth_messages(form = nil) + render "shared/auth_messages", flash: flash, + errors: form&.object&.errors&.full_messages || [] + end +end diff --git a/app/views/layouts/auth.html.erb b/app/views/layouts/auth.html.erb index e6720d52..fdd46e00 100644 --- a/app/views/layouts/auth.html.erb +++ b/app/views/layouts/auth.html.erb @@ -18,12 +18,6 @@ - <% flash.each do |type, msg| %> -
- <%= msg %> -
- <% end %> -
diff --git a/app/views/password_resets/edit.html.erb b/app/views/password_resets/edit.html.erb index d72bab32..4130b0d6 100644 --- a/app/views/password_resets/edit.html.erb +++ b/app/views/password_resets/edit.html.erb @@ -3,6 +3,7 @@ %> <%= form_with url: password_reset_path(token: params[:token]), html: {class: 'space-y-6'} do |form| %> + <%= auth_messages form %>
<%= form.label :password, class: 'block text-sm font-medium text-gray-700' %> @@ -17,4 +18,4 @@
<%= form.submit "Reset Password", class: 'flex justify-center w-full px-4 py-3 text-sm font-medium text-white bg-black rounded-xl hover:bg-black focus:outline-none focus:ring-2 focus:ring-gray-200 shadow' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/password_resets/new.html.erb b/app/views/password_resets/new.html.erb index 63065e94..c89894b1 100644 --- a/app/views/password_resets/new.html.erb +++ b/app/views/password_resets/new.html.erb @@ -3,6 +3,8 @@ %> <%= form_with url: password_reset_path, html: {class: 'space-y-6'} do |form| %> + <%= auth_messages form %> +
<%= form.label :email, class: 'block text-sm font-medium text-gray-700' %> <%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: 'you@example.com', class: 'p-0 mt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> @@ -11,4 +13,4 @@
<%= form.submit "Reset password", class: 'flex justify-center w-full px-4 py-3 text-sm font-medium text-white bg-black rounded-xl hover:bg-black focus:outline-none focus:ring-2 focus:ring-gray-200 shadow' %>
-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/passwords/edit.html.erb b/app/views/passwords/edit.html.erb index 36691bbc..a40731fd 100644 --- a/app/views/passwords/edit.html.erb +++ b/app/views/passwords/edit.html.erb @@ -1,11 +1,7 @@

Update Password

<%= form_with model: current_user, url: password_path do |form| %> - <% if form.object.errors.any? %> - <% form.object.errors.full_messages.each do |message| %> -
<%= message %>
- <% end %> - <% end %> + <%= auth_messages form %>
<%= form.label :password_challenge, "Current Password" %> diff --git a/app/views/registrations/new.html.erb b/app/views/registrations/new.html.erb index d762f0e0..10bb40b2 100644 --- a/app/views/registrations/new.html.erb +++ b/app/views/registrations/new.html.erb @@ -3,11 +3,7 @@ %> <%= form_with model: @user, url: registration_path, html: {class: 'space-y-6'} do |form| %> - <% if form.object.errors.any? %> - <% form.object.errors.full_messages.each do |message| %> -
<%= message %>
- <% end %> - <% end %> + <%= auth_messages form %>
<%= form.label :email, class: 'block text-sm font-medium text-gray-700' %> diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index c7fbf2bc..904fba78 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -8,6 +8,8 @@ <%= form_with url: session_path, html: {class: 'space-y-6'} do |form| %> + <%= auth_messages form %> +
<%= form.label :email, "Email address", class: 'block text-sm font-medium text-gray-700' %> <%= form.email_field :email, autofocus: false, autocomplete: "email", required: 'required', placeholder: 'you@example.com', class: 'p-0 mt-1 bg-transparent border-none opacity-50 focus:outline-none focus:ring-0 focus-within:opacity-100 w-full' %> @@ -25,4 +27,4 @@

Forgot your password? <%= link_to "Reset it", new_password_reset_path, class: 'font-medium text-candlelight-600 hover:text-candlelight-500' %>

-
\ No newline at end of file +
diff --git a/app/views/shared/_auth_messages.html.erb b/app/views/shared/_auth_messages.html.erb new file mode 100644 index 00000000..62883dca --- /dev/null +++ b/app/views/shared/_auth_messages.html.erb @@ -0,0 +1,7 @@ +<% flash.each do |type, msg| %> +
<%= msg %>
+<% end %> + +<% errors.each do |message| %> +
<%= message %>
+<% end %>