Clean up forms

This commit is contained in:
Ryan Pandya 2022-10-30 00:25:34 -07:00
parent 90007d40e7
commit 0c2f304b2f
3 changed files with 90 additions and 67 deletions

View File

@ -1,14 +1,8 @@
<ul class="p-2 shadow menu menu-compact dropdown-content bg-base-100 text-neutral rounded-box w-52 flex flex-col gap-4">
<%= if @current_user do %> <%= if @current_user do %>
<label tabindex="0" class="btn btn-ghost btn-circle avatar"> <li class="p-2 pb-4 border-b-2"><%= @current_user.email %></li>
<div class="w-10 rounded-full">
<img src="https://placeimg.com/80/80/people" />
</div>
</label>
<ul class="mt-3 p-2 shadow menu menu-compact dropdown-content bg-base-100 text-neutral rounded-box w-52">
<li><%= @current_user.email %></li>
<li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li> <li><%= link "Settings", to: Routes.user_settings_path(@conn, :edit) %></li>
<li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li> <li><%= link "Log out", to: Routes.user_session_path(@conn, :delete), method: :delete %></li>
</ul>
<% else %> <% else %>
<%= link "Log in", to: Routes.user_session_path(@conn, :new), class: "btn" %> <%= link "Log in", to: Routes.user_session_path(@conn, :new), class: "btn" %>
<%= link "Register", to: Routes.user_registration_path(@conn, :new), class: "btn btn-primary" %> <%= link "Register", to: Routes.user_registration_path(@conn, :new), class: "btn btn-primary" %>

View File

@ -6,19 +6,23 @@
<p><%= @error_message %></p> <p><%= @error_message %></p>
</div> </div>
<% end %> <% end %>
<ul class="w-1/2 pl-0 flex flex-col gap-6">
<%= label f, :email %> <li class="flex flex-row gap-4">
<%= label f, :email, class: "w-1/3" %>
<%= email_input f, :email, required: true %> <%= email_input f, :email, required: true %>
</li>
<%= label f, :password %> <li class="flex flex-row gap-4">
<%= label f, :password, class: "w-1/3" %>
<%= password_input f, :password, required: true %> <%= password_input f, :password, required: true %>
</li>
<%= label f, :remember_me, "Keep me logged in for 60 days" %> <li class="flex flex-row gap-4">
<%= label f, :remember_me, "Keep me logged in for 60 days", class: "w-fit" %>
<%= checkbox f, :remember_me %> <%= checkbox f, :remember_me %>
</li>
<div> <li class="flex">
<%= submit "Log in" %> <%= submit "Log in", class: "btn btn-primary" %>
</div> </li>
</ul>
</.form> </.form>
<p> <p>

View File

@ -1,8 +1,13 @@
<h1>Settings</h1> <h1>Settings</h1>
<h3>Change email</h3> <div class="flex gap-16 flex-col md:flex-row justify-evenly">
<.form
<.form let={f} for={@email_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_email"> let={f}
for={@email_changeset}
action={Routes.user_settings_path(@conn, :update)}
id="update_email"
class="w-max"
>
<%= if @email_changeset.action do %> <%= if @email_changeset.action do %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p> <p>Oops, something went wrong! Please check the errors below.</p>
@ -11,22 +16,37 @@
<%= hidden_input f, :action, name: "action", value: "update_email" %> <%= hidden_input f, :action, name: "action", value: "update_email" %>
<%= label f, :email %>
<h3>Change email</h3>
<ul class="w-full pl-0 flex flex-col gap-6">
<li class="flex flex-row gap-4">
<%= label f, :email, class: "w-1/3" %>
<%= email_input f, :email, required: true %> <%= email_input f, :email, required: true %>
<%= error_tag f, :email %> <%= error_tag f, :email %>
</li>
<%= label f, :current_password, for: "current_password_for_email" %> <li class="flex flex-row gap-4">
<%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_email" %> <%= label f, :current_password, for: "current_password_for_email", class: "w-1/3" %>
<%= password_input f, :password, required: true %>
<%= error_tag f, :current_password %> <%= error_tag f, :current_password %>
</li>
<div> <li class="flex place-self-stretch">
<%= submit "Change email" %> <%= submit "Change email", class: "btn btn-primary" %>
</div> </li>
</ul>
</.form> </.form>
<.form
let={f}
for={@password_changeset}
action={Routes.user_settings_path(@conn, :update)}
id="update_password"
class="w-max"
>
<h3>Change password</h3> <h3>Change password</h3>
<.form let={f} for={@password_changeset} action={Routes.user_settings_path(@conn, :update)} id="update_password"> <ul class="w-full pl-0 flex flex-col gap-6 md:h-full">
<%= if @password_changeset.action do %> <%= if @password_changeset.action do %>
<div class="alert alert-danger"> <div class="alert alert-danger">
<p>Oops, something went wrong! Please check the errors below.</p> <p>Oops, something went wrong! Please check the errors below.</p>
@ -35,19 +55,24 @@
<%= hidden_input f, :action, name: "action", value: "update_password" %> <%= hidden_input f, :action, name: "action", value: "update_password" %>
<%= label f, :password, "New password" %> <li class="flex flex-row gap-4">
<%= password_input f, :password, required: true %> <%= label f, :current_password, for: "current_password_for_password", class: "w-1/3" %>
<%= error_tag f, :password %>
<%= label f, :password_confirmation, "Confirm new password" %>
<%= password_input f, :password_confirmation, required: true %>
<%= error_tag f, :password_confirmation %>
<%= label f, :current_password, for: "current_password_for_password" %>
<%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password" %> <%= password_input f, :current_password, required: true, name: "current_password", id: "current_password_for_password" %>
<%= error_tag f, :current_password %> <%= error_tag f, :current_password %>
</li>
<div> <li class="flex flex-row gap-4">
<%= submit "Change password" %> <%= label f, :password, "New password", class: "w-1/3" %>
</div> <%= password_input f, :password, required: true, class: "shrink-0" %>
<%= error_tag f, :password %>
</li>
<li class="flex flex-row gap-4">
<%= label f, :password_confirmation, "Confirm new password", class: "w-1/3" %>
<%= password_input f, :password_confirmation, required: true %>
<%= error_tag f, :password_confirmation %>
</li>
<li class="flex">
<%= submit "Change password", class: "btn btn-primary" %>
</li>
</ul>
</.form> </.form>
</div>