Skip to content

Commit

Permalink
Fix profile show
Browse files Browse the repository at this point in the history
  • Loading branch information
lurnid committed Nov 22, 2024
1 parent 6c6c4c2 commit 0d298bf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 45 deletions.
20 changes: 0 additions & 20 deletions lib/maker_passport_web/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
<main class="px-4 py-20 sm:px-6 lg:px-8">
<div class="mx-auto max-w-6xl">
<.flash_group flash={@flash} />
<%= if @current_user && !@current_user.profile_complete do %>
<div class="bg-yellow-50 border-l-4 border-yellow-400 p-4">
<div class="flex">
<div class="flex-shrink-0">
<!-- Heroicon name: mini/exclamation-triangle -->
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path d="M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 6a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 6zm0 9a1 1 0 100-2 1 1 0 000 2z" />
</svg>
</div>
<div class="ml-3">
<p class="text-sm text-yellow-700">
Your profile is incomplete.
<.link navigate={~p"/profiles/#{@current_user.profile.id}"} class="font-medium underline hover:text-yellow-600">
Complete your profile here
</.link>
</p>
</div>
</div>
</div>
<% end %>
<%= @inner_content %>
</div>
</main>
22 changes: 22 additions & 0 deletions lib/maker_passport_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,28 @@
</div>
</div>
<ul tabindex="0" class="dropdown-content menu bg-slate-50 rounded-box z-[1] w-52 p-2 shadow-lg border mt-1">
<li>
<%= if !@current_user.profile_complete do %>
<div class="bg-yellow-50 border-l-4 border-yellow-400 p-4">
<div class="flex">
<div class="flex-shrink-0">
<!-- Heroicon name: mini/exclamation-triangle -->
<svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path d="M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 6a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 6zm0 9a1 1 0 100-2 1 1 0 000 2z" />
</svg>
</div>
<div class="ml-3">
<p class="text-sm text-yellow-700">
Your profile is incomplete.
<.link navigate={~p"/profiles/#{@current_user.profile.id}/edit-profile"} class="font-medium underline hover:text-yellow-600">
Complete your profile here
</.link>
</p>
</div>
</div>
</div>
<% end %>
</li>
<li>
<.link
href={~p"/profiles/#{@current_user.profile.id}"}
Expand Down
49 changes: 26 additions & 23 deletions lib/maker_passport_web/live/profile_live/show.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,37 @@ defmodule MakerPassportWeb.ProfileLive.Show do
alias MakerPassport.Maker.Skill

@impl true
def mount(_params, _session, socket) do
user = socket.assigns.current_user
profile = Maker.get_profile_with_skills_by_user_id!(user.id)
def mount(_params, session, socket) do
{:ok, socket}
end

@impl true
def handle_params(%{"id" => id} = params, _, socket) do
profile = Maker.get_profile!(id)
skills = ordered_skills(profile)

socket =
socket
|> assign(:user_id, user.id)
|> assign_new(:form, fn ->
to_form(Maker.change_profile(profile))
end)
|> assign_new(:skills_form, fn ->
to_form(Skill.changeset(%Skill{}))
end)
|> assign(:profile, profile)
|> assign(:skills, skills)
|> assign(temporary_assigns: [skills: []])
{:ok, socket}
|> assign(:page_title, page_title(socket.assigns.live_action))

{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end

defp apply_action(socket, :show, _params) do
socket
end

defp apply_action(socket, :edit_profile, _params) do
socket
|> assign_new(:form, fn ->
to_form(Maker.change_profile(socket.assigns.profile))
end)
|> assign_new(:skills_form, fn ->
to_form(Skill.changeset(%Skill{}))
end)
|> assign(:page_title, "Edit Profile")
end

defp ordered_skills(profile) do
Expand All @@ -40,17 +54,6 @@ defmodule MakerPassportWeb.ProfileLive.Show do
{:noreply, socket}
end

@impl true
def handle_params(%{"id" => id}, _, socket) do
profile = Maker.get_profile!(id)

socket =
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:profile, profile)
{:noreply, socket}
end

@impl true
def handle_event("save_skill", %{"search-field" => skill_name}, socket) do
save_skill(socket, skill_name, socket.assigns.profile)
Expand Down
5 changes: 3 additions & 2 deletions lib/maker_passport_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule MakerPassportWeb.Router do
pipe_through :browser

live "/", HomeLive.Index, :index
live "/profiles", ProfileLive.Index, :index
end

# Other scopes may use custom stacks.
Expand Down Expand Up @@ -69,12 +70,10 @@ defmodule MakerPassportWeb.Router do
live "/users/settings", UserSettingsLive, :edit
live "/users/settings/confirm_email/:token", UserSettingsLive, :confirm_email

live "/profiles", ProfileLive.Index, :index
# live "/profiles/new", ProfileLive.Index, :new

# live "/profiles/me", ProfileLive.MyProfile
# live "/profiles/me/edit", ProfileLive.MyProfile, :edit
live "/profiles/:id", ProfileLive.Show, :show
live "/profiles/:id/edit-profile", ProfileLive.Show, :edit_profile
# live "/profiles/:id/edit", ProfileLive.Index, :edit
# live "/profiles/:id/show/edit", ProfileLive.Show, :edit
Expand All @@ -90,6 +89,8 @@ defmodule MakerPassportWeb.Router do
on_mount: [{MakerPassportWeb.UserAuth, :mount_current_user}] do
live "/users/confirm/:token", UserConfirmationLive, :edit
live "/users/confirm", UserConfirmationInstructionsLive, :new

live "/profiles/:id", ProfileLive.Show, :show
end
end
end

0 comments on commit 0d298bf

Please sign in to comment.