Skip to content

Commit

Permalink
feat: add slug field
Browse files Browse the repository at this point in the history
  • Loading branch information
AfonsoMartins26 committed Oct 3, 2024
1 parent da8d768 commit 1854bf2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/atomic_web/components/sidebar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ defmodule AtomicWeb.Components.Sidebar do

defp user_image(user) do
if user.profile_picture do
Atomic.Uploaders.ProfilePicture.url({user, user.profile_picture}, :original)
Atomic.Uploaders.ProfilePicture.url({user.profile_picture, user}, :original)
else
""
nil
end
end

Expand Down
7 changes: 4 additions & 3 deletions lib/atomic_web/live/profile_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ defmodule AtomicWeb.ProfileLive.FormComponent do
<div class="grid grid-cols-1 gap-6 md:grid-cols-2">
<!-- Section for profile picture upload -->
<div class="flex flex-col items-center pr-4">
<%= if @user.profile_picture != NULL do %>
<%= if @user.profile_picture != nil do %>
<%= label(f, :name, "Profile Picture", class: "mt-3 mb-1 text-sm font-medium text-gray-700") %>
<div class="mb-4 border-4">
<.avatar name={@user.name} color={:light_gray} class="h-36 w-36 rounded-full border-4 border-white text-4xl" type={:user} src={Uploaders.ProfilePicture.url({@user.profile_picture, @user}, :original)} />
Expand All @@ -28,10 +28,11 @@ defmodule AtomicWeb.ProfileLive.FormComponent do
</div>
<div class="flex flex-col gap-6">
<!-- Name, phone number, email fields -->
<div class="grid grid-cols-1 gap-4">
<div class="grid grid-cols-1 gap-2">
<.field field={f[:name]} type="text" placeholder="Name" class="w-full" />
<.field field={f[:phone_number]} type="text" placeholder="Phone Number" class="w-full" />
<.field field={f[:email]} type="email" placeholder="Email" class="w-full" />
<.field field={f[:slug]} type="text" placeholder="User Name" class="w-full" />
</div>
<!-- Social media fields positioned below name, phone, and email -->
<div class="grid w-full gap-x-4 gap-y-4 sm:grid-cols-1 md:grid-cols-4">
Expand Down Expand Up @@ -106,7 +107,7 @@ defmodule AtomicWeb.ProfileLive.FormComponent do
{:noreply,
socket
|> put_flash(:success, flash_text)
|> push_navigate(to: ~p"/profile/#{user_params["slug"]}")}
|> push_navigate(to: ~p"/profile/#{user_params["slug"] || user.slug}")}

{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign(socket, :changeset, changeset)}
Expand Down
11 changes: 0 additions & 11 deletions lib/atomic_web/live/profile_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,8 @@
</div>
<% end %>
</div>
<!-- Edit Button for Current User -->
<%= if @is_current_user do %>
<div class="mt-4 flex justify-start">
<.button patch={Routes.profile_edit_path(@socket, :edit, @user)}>
<%= gettext("Edit") %>
</.button>
</div>
<% end %>
</div>
</div>
<!-- Divider -->
<div class="py-6 mb-2 border-b border-zinc-200"></div>

<%= if @is_current_user do %>
<div class="w-24 flex justify-end">
<.button patch={~p"/profile/#{@user}/edit"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ defmodule Atomic.Repo.Migrations.CreateUsersAuthTables do
add :slug, :citext
add :role, :string, null: false, default: "student"

add :socials, :map

add :hashed_password, :string, null: false

add :confirmed_at, :naive_datetime
Expand Down

0 comments on commit 1854bf2

Please sign in to comment.