diff --git a/lib/foedus_web/components/layouts.ex b/lib/foedus_web/components/layouts.ex index 249a6bf..7013178 100644 --- a/lib/foedus_web/components/layouts.ex +++ b/lib/foedus_web/components/layouts.ex @@ -201,12 +201,6 @@ defmodule FoedusWeb.Layouts do > Entrar - <.link - href={~p"/users/register"} - class="bg-indigo-600 text-white px-4 py-2 rounded-md text-sm font-medium hover:bg-indigo-700 transition-colors" - > - Cadastrar - """ end diff --git a/lib/foedus_web/components/ui/addresses_list.ex b/lib/foedus_web/components/ui/addresses_list.ex index b8d1d2c..2b8fe49 100644 --- a/lib/foedus_web/components/ui/addresses_list.ex +++ b/lib/foedus_web/components/ui/addresses_list.ex @@ -5,7 +5,7 @@ defmodule FoedusWeb.Components.UI.AddressesList do attr :addresses, :list, required: true attr :title, :string, default: "Addresses" - attr :class, :string, default: "" + attr :class, :any, default: "" def addresses_list(assigns) do ~H""" diff --git a/lib/foedus_web/components/ui/button.ex b/lib/foedus_web/components/ui/button.ex index 851b624..4d8a8ec 100644 --- a/lib/foedus_web/components/ui/button.ex +++ b/lib/foedus_web/components/ui/button.ex @@ -1,8 +1,6 @@ defmodule FoedusWeb.Components.UI.Button do use Phoenix.Component - alias FoedusWeb.Components.UI.Icon - @base_class "inline-flex items-center justify-center gap-2 border font-medium rounded-lg transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" @variants %{ diff --git a/lib/foedus_web/components/ui/card.ex b/lib/foedus_web/components/ui/card.ex index ab41e4f..9786a45 100644 --- a/lib/foedus_web/components/ui/card.ex +++ b/lib/foedus_web/components/ui/card.ex @@ -3,7 +3,7 @@ defmodule FoedusWeb.Components.UI.Card do import FoedusWeb.Components.UI.Icon - attr :class, :string, default: "" + attr :class, :any, default: "" attr :title, :string, default: nil attr :icon, :string, default: nil attr :icon_color, :string, default: "gray" @@ -82,12 +82,4 @@ defmodule FoedusWeb.Components.UI.Card do defp icon_text_class("yellow"), do: "text-yellow-600" defp icon_text_class("indigo"), do: "text-indigo-600" defp icon_text_class(_), do: "text-gray-600" - - defp stat_bg_class("blue"), do: "bg-blue-500" - defp stat_bg_class("green"), do: "bg-green-500" - defp stat_bg_class("purple"), do: "bg-purple-500" - defp stat_bg_class("red"), do: "bg-red-500" - defp stat_bg_class("yellow"), do: "bg-yellow-500" - defp stat_bg_class("indigo"), do: "bg-indigo-500" - defp stat_bg_class(_), do: "bg-gray-500" end diff --git a/lib/foedus_web/components/ui/icon.ex b/lib/foedus_web/components/ui/icon.ex index f3bf8b2..7a0a224 100644 --- a/lib/foedus_web/components/ui/icon.ex +++ b/lib/foedus_web/components/ui/icon.ex @@ -15,7 +15,7 @@ defmodule FoedusWeb.Components.UI.Icon do <.icon name="check-circle" class="w-4 h-4 text-green-500" /> """ attr :name, :string, required: true - attr :class, :string, default: nil + attr :class, :any, default: nil def icon(%{name: "hero-" <> _} = assigns) do ~H""" diff --git a/lib/foedus_web/live/contract_template_live/show.html.heex b/lib/foedus_web/live/contract_template_live/show.html.heex index b83c7fa..134bf9d 100644 --- a/lib/foedus_web/live/contract_template_live/show.html.heex +++ b/lib/foedus_web/live/contract_template_live/show.html.heex @@ -66,7 +66,7 @@ Back <.link - patch={~p"/contract_templates/#{@contract_template}/show/edit"} + patch={~p"/contract_templates/#{@contract_template.id}/edit"} phx-click={JS.push_focus()} > <.button class="inline-flex items-center justify-center gap-2 hover:text-indigo-600 hover:bg-gray-50 text-indigo-600 font-medium px-4 py-2.5 rounded-xl shadow-sm transition-all duration-200 border border-white"> diff --git a/lib/foedus_web/live/contractor_live/show.ex b/lib/foedus_web/live/contractor_live/show.ex index 2d9b67a..4dba1fc 100644 --- a/lib/foedus_web/live/contractor_live/show.ex +++ b/lib/foedus_web/live/contractor_live/show.ex @@ -28,7 +28,4 @@ defmodule FoedusWeb.ContractorLive.Show do defp page_title(:show), do: "Show Contractor" defp page_title(:edit), do: "Edit Contractor" - - defp information_section_title(%{entity_type: :company}), do: "Company Information" - defp information_section_title(_contractor), do: "Personal Information" end diff --git a/lib/foedus_web/live/contractor_live/show.html.heex b/lib/foedus_web/live/contractor_live/show.html.heex index 6e473a9..9973823 100644 --- a/lib/foedus_web/live/contractor_live/show.html.heex +++ b/lib/foedus_web/live/contractor_live/show.html.heex @@ -62,8 +62,7 @@ - + /> diff --git a/lib/foedus_web/live/signer_live/show.ex b/lib/foedus_web/live/signer_live/show.ex index 26caf94..64ab763 100644 --- a/lib/foedus_web/live/signer_live/show.ex +++ b/lib/foedus_web/live/signer_live/show.ex @@ -34,25 +34,4 @@ defmodule FoedusWeb.SignerLive.Show do name = String.trim("#{first} #{last}") if name == "", do: "Signer ##{signer.id}", else: name end - - defp format_document(document) when is_binary(document) do - document - |> String.replace(~r/[^\d]/, "") - |> case do - <> -> - "#{a}.#{b}.#{c}-#{d}" - - <> -> - "#{a}.#{b}.#{c}/#{d}-#{e}" - - doc -> - doc - end - end - - defp format_document(nil), do: "N/A" - - defp format_date(%Date{} = date), do: Calendar.strftime(date, "%d/%m/%Y") - defp format_date(nil), do: "N/A" - defp format_date(_), do: "N/A" end diff --git a/lib/foedus_web/live/user_confirmation_instructions_live.ex b/lib/foedus_web/live/user_auth/user_confirmation_instructions_live.ex similarity index 88% rename from lib/foedus_web/live/user_confirmation_instructions_live.ex rename to lib/foedus_web/live/user_auth/user_confirmation_instructions_live.ex index 2257b19..d4bf074 100644 --- a/lib/foedus_web/live/user_confirmation_instructions_live.ex +++ b/lib/foedus_web/live/user_auth/user_confirmation_instructions_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserConfirmationInstructionsLive do +defmodule FoedusWeb.UserAuth.UserConfirmationInstructionsLive do use FoedusWeb, :live_view alias Foedus.Accounts @@ -21,8 +21,7 @@ defmodule FoedusWeb.UserConfirmationInstructionsLive do

- <.link href={~p"/users/register"}>Register - | <.link href={~p"/users/log_in"}>Log in + <.link href={~p"/users/log_in"}>Log in

""" diff --git a/lib/foedus_web/live/user_confirmation_live.ex b/lib/foedus_web/live/user_auth/user_confirmation_live.ex similarity index 92% rename from lib/foedus_web/live/user_confirmation_live.ex rename to lib/foedus_web/live/user_auth/user_confirmation_live.ex index 1f6ba97..dfb5b0b 100644 --- a/lib/foedus_web/live/user_confirmation_live.ex +++ b/lib/foedus_web/live/user_auth/user_confirmation_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserConfirmationLive do +defmodule FoedusWeb.UserAuth.UserConfirmationLive do use FoedusWeb, :live_view alias Foedus.Accounts @@ -16,8 +16,7 @@ defmodule FoedusWeb.UserConfirmationLive do

- <.link href={~p"/users/register"}>Register - | <.link href={~p"/users/log_in"}>Log in + <.link href={~p"/users/log_in"}>Log in

""" diff --git a/lib/foedus_web/live/user_forgot_password_live.ex b/lib/foedus_web/live/user_auth/user_forgot_password_live.ex similarity index 91% rename from lib/foedus_web/live/user_forgot_password_live.ex rename to lib/foedus_web/live/user_auth/user_forgot_password_live.ex index 720c9da..4b0fa75 100644 --- a/lib/foedus_web/live/user_forgot_password_live.ex +++ b/lib/foedus_web/live/user_auth/user_forgot_password_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserForgotPasswordLive do +defmodule FoedusWeb.UserAuth.UserForgotPasswordLive do use FoedusWeb, :live_view alias Foedus.Accounts @@ -29,9 +29,6 @@ defmodule FoedusWeb.UserForgotPasswordLive do

- <.link href={~p"/users/register"} class="font-semibold text-indigo-600 hover:underline"> - Register - | <.link href={~p"/users/log_in"} class="font-semibold text-indigo-600 hover:underline"> Log in diff --git a/lib/foedus_web/live/user_login_live.ex b/lib/foedus_web/live/user_auth/user_login_live.ex similarity index 80% rename from lib/foedus_web/live/user_login_live.ex rename to lib/foedus_web/live/user_auth/user_login_live.ex index 4006ace..82fc12f 100644 --- a/lib/foedus_web/live/user_login_live.ex +++ b/lib/foedus_web/live/user_auth/user_login_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserLoginLive do +defmodule FoedusWeb.UserAuth.UserLoginLive do use FoedusWeb, :live_view def render(assigns) do @@ -7,18 +7,6 @@ defmodule FoedusWeb.UserLoginLive do

<.header class="text-center mb-8"> Log in to account - <:subtitle> - - Don't have an account? - <.link - navigate={~p"/users/register"} - class="font-semibold text-indigo-600 hover:underline" - > - Sign up - - for an account now. - - <.simple_form diff --git a/lib/foedus_web/live/user_reset_password_live.ex b/lib/foedus_web/live/user_auth/user_reset_password_live.ex similarity index 93% rename from lib/foedus_web/live/user_reset_password_live.ex rename to lib/foedus_web/live/user_auth/user_reset_password_live.ex index 93ce512..d4bd6c3 100644 --- a/lib/foedus_web/live/user_reset_password_live.ex +++ b/lib/foedus_web/live/user_auth/user_reset_password_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserResetPasswordLive do +defmodule FoedusWeb.UserAuth.UserResetPasswordLive do use FoedusWeb, :live_view alias Foedus.Accounts @@ -31,8 +31,7 @@ defmodule FoedusWeb.UserResetPasswordLive do

- <.link href={~p"/users/register"}>Register - | <.link href={~p"/users/log_in"}>Log in + <.link href={~p"/users/log_in"}>Log in

""" diff --git a/lib/foedus_web/live/user_settings_live.ex b/lib/foedus_web/live/user_auth/user_settings_live.ex similarity index 99% rename from lib/foedus_web/live/user_settings_live.ex rename to lib/foedus_web/live/user_auth/user_settings_live.ex index d76496c..2ce4429 100644 --- a/lib/foedus_web/live/user_settings_live.ex +++ b/lib/foedus_web/live/user_auth/user_settings_live.ex @@ -1,4 +1,4 @@ -defmodule FoedusWeb.UserSettingsLive do +defmodule FoedusWeb.UserAuth.UserSettingsLive do use FoedusWeb, :live_view alias Foedus.Accounts diff --git a/lib/foedus_web/live/user_registration_live.ex b/lib/foedus_web/live/user_registration_live.ex deleted file mode 100644 index 15ae795..0000000 --- a/lib/foedus_web/live/user_registration_live.ex +++ /dev/null @@ -1,100 +0,0 @@ -defmodule FoedusWeb.UserRegistrationLive do - use FoedusWeb, :live_view - - alias Foedus.Accounts - alias Foedus.Accounts.User - - def render(assigns) do - ~H""" -
-
- <.header class="text-center mb-8"> - Register for an account - <:subtitle> - - Already registered? - <.link - navigate={~p"/users/log_in"} - class="font-semibold text-indigo-600 hover:underline" - > - Log in - - to your account now. - - - - - <.simple_form - for={@form} - id="registration_form" - phx-submit="save" - phx-change="validate" - phx-trigger-action={@trigger_submit} - action={~p"/users/log_in?_action=registered"} - method="post" - class="space-y-6" - > - <.error :if={@check_errors}> - Oops, something went wrong! Please check the errors below. - - - <.input field={@form[:email]} type="email" label="Email" required /> - <.input field={@form[:password]} type="password" label="Password" required /> - - <:actions> - <.button - phx-disable-with="Creating account..." - class="w-full bg-indigo-600 hover:bg-indigo-700 text-white px-4 py-2 rounded-lg" - > - Create an account - - - -
-
- """ - end - - def mount(_params, _session, socket) do - changeset = Accounts.change_user_registration(%User{}) - - socket = - socket - |> assign(trigger_submit: false, check_errors: false) - |> assign_form(changeset) - - {:ok, socket, temporary_assigns: [form: nil]} - end - - def handle_event("save", %{"user" => user_params}, socket) do - case Accounts.register_user(user_params) do - {:ok, user} -> - {:ok, _} = - Accounts.deliver_user_confirmation_instructions( - user, - &url(~p"/users/confirm/#{&1}") - ) - - changeset = Accounts.change_user_registration(user) - {:noreply, socket |> assign(trigger_submit: true) |> assign_form(changeset)} - - {:error, %Ecto.Changeset{} = changeset} -> - {:noreply, socket |> assign(check_errors: true) |> assign_form(changeset)} - end - end - - def handle_event("validate", %{"user" => user_params}, socket) do - changeset = Accounts.change_user_registration(%User{}, user_params) - {:noreply, assign_form(socket, Map.put(changeset, :action, :validate))} - end - - defp assign_form(socket, %Ecto.Changeset{} = changeset) do - form = to_form(changeset, as: "user") - - if changeset.valid? do - assign(socket, form: form, check_errors: false) - else - assign(socket, form: form) - end - end -end diff --git a/lib/foedus_web/router.ex b/lib/foedus_web/router.ex index b4ba86e..87582f6 100644 --- a/lib/foedus_web/router.ex +++ b/lib/foedus_web/router.ex @@ -1,6 +1,5 @@ defmodule FoedusWeb.Router do use FoedusWeb, :router - import FoedusWeb.UserAuth pipeline :browser do @@ -13,37 +12,27 @@ defmodule FoedusWeb.Router do plug :fetch_current_user end - # Enable LiveDashboard and Swoosh mailbox preview in development if Application.compile_env(:foedus, :dev_routes) do - # If you want to use the LiveDashboard in production, you should put - # it behind authentication and allow only admins to access it. - # If your application does not have an admins-only section yet, - # you can use Plug.BasicAuth to set up some basic authentication - # as long as you are also using SSL (which you should anyway). import Phoenix.LiveDashboard.Router scope "/dev" do pipe_through :browser - live_dashboard "/dashboard", metrics: FoedusWeb.Telemetry forward "/mailbox", Plug.Swoosh.MailboxPreview end end - ## Authentication routes - scope "/", FoedusWeb do pipe_through [:browser, :redirect_if_user_is_authenticated] live_session :redirect_if_user_is_authenticated, on_mount: [{FoedusWeb.UserAuth, :redirect_if_user_is_authenticated}] do live "/", HomeLive.Index, :index - # live "/users/register", UserRegistrationLive, :new - # live "/users/reset_password", UserForgotPasswordLive, :new - # live "/users/reset_password/:token", UserResetPasswordLive, :edit - live "/users/log_in", UserLoginLive, :new live "/onboarding", OnboardingLive.Index, :index + + live "/users/reset_password", UserAuth.UserForgotPasswordLive, :new + live "/users/reset_password/:token", UserAuth.UserResetPasswordLive, :edit end post "/users/log_in", UserSessionController, :create @@ -54,10 +43,11 @@ defmodule FoedusWeb.Router do live_session :require_authenticated_user, on_mount: [{FoedusWeb.UserAuth, :ensure_authenticated}] do - live "/users/settings", UserSettingsLive, :edit - live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email + live "/users/settings", UserAuth.UserSettingsLive, :edit + live "/users/settings/confirm_email/:token", UserAuth.UserSettingsLive, :confirm_email live "/dashboard", DashboardLive.Index + live "/contractors", ContractorLive.Index, :index live "/contractors/:id/edit", ContractorLive.Index, :edit live "/contractors/:id", ContractorLive.Show, :show @@ -65,13 +55,12 @@ defmodule FoedusWeb.Router do live "/contract_templates", ContractTemplateLive.Index, :index live "/contract_templates/new", ContractTemplateLive.Index, :new live "/contract_templates/:id/edit", ContractTemplateLive.Index, :edit + live "/contract_templates/:id", ContractTemplateLive.Show, :show live "/signers", SignerLive.Index, :index live "/signers/new", SignerLive.Index, :new live "/signers/:id/edit", SignerLive.Index, :edit live "/signers/:id", SignerLive.Show, :show - - live "/contract_templates/:id", ContractTemplateLive.Show, :show end end @@ -84,8 +73,8 @@ defmodule FoedusWeb.Router do live_session :current_user, on_mount: [{FoedusWeb.UserAuth, :mount_current_user}] do - live "/users/confirm/:token", UserConfirmationLive, :edit - live "/users/confirm", UserConfirmationInstructionsLive, :new + live "/users/confirm/:token", UserAuth.UserConfirmationLive, :edit + live "/users/confirm", UserAuth.UserConfirmationInstructionsLive, :new end end end