From 95cbd6a9b93a7d5cf405b42e5537725f307f4ae4 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 25 Sep 2024 18:24:34 +0100 Subject: [PATCH] Fix: Profile Picture upload --- lib/atomic/accounts.ex | 4 +++- lib/atomic_web/components/sidebar.ex | 7 ++++--- .../live/profile_live/form_component.ex | 18 +++--------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/lib/atomic/accounts.ex b/lib/atomic/accounts.ex index 97b67564c..9396fac3c 100644 --- a/lib/atomic/accounts.ex +++ b/lib/atomic/accounts.ex @@ -485,6 +485,7 @@ defmodule Atomic.Accounts do def update_user_picture(%User{} = user, attrs \\ %{}) do user |> User.picture_changeset(attrs) + |> IO.inspect() |> Repo.update() end @@ -500,10 +501,11 @@ defmodule Atomic.Accounts do {:error, %Ecto.Changeset{}} """ - def update_user(%User{} = user, attrs \\ %{}, _after_save \\ &{:ok, &1}) do + def update_user(%User{} = user, attrs \\ %{}, after_save \\ &{:ok, &1}) do user |> User.changeset(attrs) |> Repo.update() + |> after_save(after_save) end @doc """ diff --git a/lib/atomic_web/components/sidebar.ex b/lib/atomic_web/components/sidebar.ex index 23277ee1b..eea8310c7 100644 --- a/lib/atomic_web/components/sidebar.ex +++ b/lib/atomic_web/components/sidebar.ex @@ -5,6 +5,7 @@ defmodule AtomicWeb.Components.Sidebar do alias Phoenix.LiveView.JS import AtomicWeb.Components.Icon alias Atomic.Organizations + import AtomicWeb.Components.Avatar attr :current_user, :map, required: true attr :current_organization, :map, required: true @@ -122,7 +123,7 @@ defmodule AtomicWeb.Components.Sidebar do <:wrapper> @@ -190,9 +191,9 @@ defmodule AtomicWeb.Components.Sidebar do defp user_image(user) do if user.profile_picture do - Uploaders.ProfilePicture.url({user, user.profile_picture}, :original) + Atomic.Uploaders.ProfilePicture.url({user, user.profile_picture}, :original) else - nil + "" end end diff --git a/lib/atomic_web/live/profile_live/form_component.ex b/lib/atomic_web/live/profile_live/form_component.ex index e1184b64d..7483eb94c 100644 --- a/lib/atomic_web/live/profile_live/form_component.ex +++ b/lib/atomic_web/live/profile_live/form_component.ex @@ -13,12 +13,9 @@ defmodule AtomicWeb.ProfileLive.FormComponent do
-
+
<%= label(f, :name, "Profile Picture", class: "mt-3 mb-1 text-sm font-medium text-gray-700") %> - -
- <.live_component module={ImageUploader} id="uploader-profile-picture" uploads={@uploads} target={@myself} /> -
+ <.live_component module={ImageUploader} id="uploader-profile-picture" uploads={@uploads} target={@myself} />
@@ -48,22 +45,13 @@ defmodule AtomicWeb.ProfileLive.FormComponent do """ end - @impl true - def mount(socket) do - {:ok, - socket - |> allow_upload(:image, - accept: Uploaders.ProfilePicture.extension_whitelist(), - max_entries: 1 - )} - end - @impl true def update(%{user: user} = assigns, socket) do changeset = Accounts.change_user(user) {:ok, socket + |> allow_upload(:image, accept: Uploaders.ProfilePicture.extension_whitelist(), max_entries: 1) |> assign(assigns) |> assign(:changeset, changeset)} end