From 35e3c6a608918d459efe70aa6e3d81d808add0af Mon Sep 17 00:00:00 2001 From: Robert Prehn Date: Fri, 28 Aug 2020 16:49:56 -0500 Subject: [PATCH] feat: Add new tailwind styles --- .../templates/pow/registration/new.html.eex | 41 ++++--------- .../templates/pow/session/new.html.eex | 55 +++++++----------- .../reset_password/new.html.eex | 33 ++++------- .../controllers/posts_controller.ex | 2 +- apps/core/lib/core_web/views/helpers.ex | 58 ++++++++++++++++--- 5 files changed, 95 insertions(+), 94 deletions(-) diff --git a/apps/auth_web/lib/auth_web/templates/pow/registration/new.html.eex b/apps/auth_web/lib/auth_web/templates/pow/registration/new.html.eex index 17b975c9..92663a2c 100644 --- a/apps/auth_web/lib/auth_web/templates/pow/registration/new.html.eex +++ b/apps/auth_web/lib/auth_web/templates/pow/registration/new.html.eex @@ -1,37 +1,18 @@ -
-
-

-
- Create My Account -
-

- <%= flash_block(@conn) %> - <%= changeset_error_block(@changeset) %> +<%= floating_page_wrapper do %> + <%= floating_form "Sign Up", @changeset do %> <%= form_for @changeset, @action, [as: :user, class: "ui large form"], fn f -> %>
-
- <%= label f, Pow.Ecto.Schema.user_id_field(@changeset) %> -
- - <%= text_input f, Pow.Ecto.Schema.user_id_field(@changeset), placeholder: "E-mail address" %> -
- <%= error_tag f, Pow.Ecto.Schema.user_id_field(@changeset), class: "ui pointing red basic label" %> -
-
- <%= label f, :password %> -
- - <%= password_input f, :password, placeholder: "Password" %> -
-
- <%= error_tag f, :password, class: "ui pointing red basic label" %> -
- <%= submit "Create My Account", class: "ui fluid large teal submit button" %> + <%= styled_input f, Pow.Ecto.Schema.user_id_field(@changeset), placeholder: "E-mail address" %> + <%= styled_input f, :password, placeholder: "Password" %> + + <%= styled_button "Create My Account" %>
<% end %> + <% end %> -
- Already have an account? <%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %> +
+
+ Already have an account? <%= link "Sign in", to: Routes.pow_session_path(@conn, :new), class: "text-blue-100" %>
-
+<% end %> diff --git a/apps/auth_web/lib/auth_web/templates/pow/session/new.html.eex b/apps/auth_web/lib/auth_web/templates/pow/session/new.html.eex index 5031634f..fd5e5a7e 100644 --- a/apps/auth_web/lib/auth_web/templates/pow/session/new.html.eex +++ b/apps/auth_web/lib/auth_web/templates/pow/session/new.html.eex @@ -1,38 +1,23 @@ -
-
-
-
-
-

Log In

- <%= changeset_error_block(@changeset) %> -
-
- <%= form_for @changeset, @action, [as: :user, class: "ui large form"], fn f -> %> - <%= styled_input f, Pow.Ecto.Schema.user_id_field(@changeset), icon: "user", placeholder: "joe@example.org" %> - <%= styled_input f, :password, icon: "lock", type: "password" %> - <%= hidden_input f, :persistent_session, value: "true" %> -
- <%= submit "Sign In", class: "bg-gray-900 text-white active:bg-gray-700 text-sm font-bold uppercase px-6 py-3 rounded shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 w-full" %> -
- <% end %> -
-
-
-
- New to us? <%= link "Register", to: Routes.pow_registration_path(@conn, :new) %> -
- - <%= if pow_extension_enabled?(PowResetPassword) do %> -
- Forgot your password? <%= link("Reset password", to: Routes.pow_reset_password_reset_password_path(@conn, :new)) %> -
- <% end %> -
+<%= floating_page_wrapper do %> + <%= floating_form "Log In", @changeset do %> + <%= form_for @changeset, @action, [as: :user, class: "ui large form"], fn f -> %> + <%= styled_input f, Pow.Ecto.Schema.user_id_field(@changeset), icon: "user", placeholder: "joe@example.org" %> + <%= styled_input f, :password, icon: "lock", type: "password" %> + <%= hidden_input f, :persistent_session, value: "true" %> +
+ <%= styled_button "Sign In" %>
+ <% end %> + <% end %> +
+
+ New to us? <%= link "Register", to: Routes.pow_registration_path(@conn, :new), class: "text-blue-100" %>
+ + <%= if pow_extension_enabled?(PowResetPassword) do %> +
+ Forgot your password? <%= link("Reset password", to: Routes.pow_reset_password_reset_password_path(@conn, :new), class: "text-blue-100") %> +
+ <% end %>
-
+<% end %> diff --git a/apps/auth_web/lib/auth_web/templates/pow_reset_password/reset_password/new.html.eex b/apps/auth_web/lib/auth_web/templates/pow_reset_password/reset_password/new.html.eex index dcad0866..76ff242a 100644 --- a/apps/auth_web/lib/auth_web/templates/pow_reset_password/reset_password/new.html.eex +++ b/apps/auth_web/lib/auth_web/templates/pow_reset_password/reset_password/new.html.eex @@ -1,25 +1,16 @@ -
-
-

-
- Reset Password -
-

- <%= flash_block(@conn) %> - <%= changeset_error_block(@changeset) %> +<%= floating_page_wrapper do %> + <%= floating_form "Reset Password", @changeset do %> <%= form_for @changeset, @action, [as: :user, class: "ui large form"], fn f -> %> -
- <%= styled_input f, :email, [placeholder: "joe@example.org", icon: "user"] %> -
- <%= submit "Reset My Password", class: "ui fluid large teal submit button" %> + <%= styled_input f, :email, [placeholder: "joe@example.org", icon: "user"] %> + <%= styled_button "Reset My Password" %> <% end %> + <% end %> -
- Remembered your password? <%= link "Sign in", to: Routes.pow_session_path(@conn, :new) %> -
- -
- New to us? <%= link "Register", to: Routes.pow_registration_path(@conn, :new) %> -
+
+ Remembered your password? <%= link "Sign in", to: Routes.pow_session_path(@conn, :new), class: "text-blue-100" %>
-
+ +
+ New to us? <%= link "Register", to: Routes.pow_registration_path(@conn, :new), class: "text-blue-100" %> +
+<% end %> diff --git a/apps/content/lib/content_web/controllers/posts_controller.ex b/apps/content/lib/content_web/controllers/posts_controller.ex index 4b2c6f82..4a439759 100644 --- a/apps/content/lib/content_web/controllers/posts_controller.ex +++ b/apps/content/lib/content_web/controllers/posts_controller.ex @@ -72,7 +72,7 @@ defmodule Content.PostsController do defp try_static_post(conn, id) do path = "static_pages/#{id}.html" try do - render(conn |> put_flash(:error, "Tits!"), path) + render(conn, path) rescue e in Phoenix.Template.UndefinedError -> case e do diff --git a/apps/core/lib/core_web/views/helpers.ex b/apps/core/lib/core_web/views/helpers.ex index 5da6825a..a3ac959b 100644 --- a/apps/core/lib/core_web/views/helpers.ex +++ b/apps/core/lib/core_web/views/helpers.ex @@ -16,7 +16,7 @@ defmodule CoreWeb.Helpers do def changeset_error_block(changeset) do ~E""" <%= if changeset.action do %> -
+

Oops, something went wrong! Please check the errors below.

<% end %> @@ -25,10 +25,10 @@ defmodule CoreWeb.Helpers do def flash_block(conn) do ~E""" -
- <%= [info: "grey", error: "red"] |> Enum.map(fn {level, color} -> %> +
+ <%= [info: "green", error: "red"] |> Enum.map(fn {level, color} -> %> <%= if get_flash(conn, level) do %> -
+
@@ -57,6 +57,14 @@ defmodule CoreWeb.Helpers do {classes, rest_opts} = Keyword.pop(rest_opts, :class, "px-3 py-3 placeholder-gray-400 text-gray-700 bg-white rounded text-sm shadow focus:outline-none focus:shadow-outline w-full") {label_text, rest_opts} = Keyword.pop(rest_opts, :label) {input_helper, rest_opts} = Keyword.pop(rest_opts, :input_helper, :text_input) + + error_classes = + if Keyword.get_values(f.errors, field) |> Enum.any?() do + " border border-red-500" + else + "" + end + ~E"""
<%= if label_text do %> @@ -67,17 +75,53 @@ defmodule CoreWeb.Helpers do <%= if options == nil do %> - <%= apply(Phoenix.HTML.Form, input_helper, [f, field, rest_opts ++ [class: classes]]) %> + <%= apply(Phoenix.HTML.Form, input_helper, [f, field, rest_opts ++ [class: Enum.join([classes, error_classes], " ")]]) %> <% else %> - <%= apply(Phoenix.HTML.Form, input_helper, [f, field, options, rest_opts ++ [class: classes]]) %> + <%= apply(Phoenix.HTML.Form, input_helper, [f, field, options, rest_opts ++ [class: Enum.join([classes, error_classes], " ")]]) %> <% end %> <%= content %> - <%= error_tag f, field, class: "ui pointing red basic label" %> + <%= error_tag f, field, class: "text-red-500 italic" %>
""" end + def styled_button(text) do + ~E""" + <%= submit text, class: "bg-gray-900 text-white active:bg-gray-700 text-sm font-bold uppercase px-6 py-3 rounded shadow hover:shadow-lg outline-none focus:outline-none mr-1 mb-1 w-full" %> + """ + end + + def floating_form(title, changeset, do: content) do + ~E""" +

<%= title %>

+
+ <%= changeset_error_block(changeset) %> +
+ <%= content %> +
+
+ """ + + end + + def floating_page_wrapper(do: content) do + ~E""" +
+
+
+
+
+ <%= content %> +
+
+
+
+ """ + end + def pow_extension_enabled?(extension) do {extensions, _rest} = Application.get_env(:auth_web, :pow) |> Keyword.pop(:extensions, [])