2021-11-09 11:20:10 +00:00
|
|
|
defmodule LiveBeatsWeb.SettingsLive do
|
|
|
|
use LiveBeatsWeb, :live_view
|
|
|
|
|
|
|
|
alias LiveBeats.Accounts
|
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
~H"""
|
|
|
|
<.title_bar>
|
|
|
|
Profile Settings
|
|
|
|
</.title_bar>
|
|
|
|
|
2022-02-02 20:48:47 +00:00
|
|
|
<div class="max-w-3xl px-4 mx-auto mt-6">
|
2022-08-03 13:40:11 +00:00
|
|
|
<.form
|
|
|
|
:let={f}
|
2024-04-09 00:53:14 +00:00
|
|
|
id="settings-form"
|
2022-08-03 13:40:11 +00:00
|
|
|
for={@changeset}
|
2024-04-09 00:53:14 +00:00
|
|
|
phx-change={
|
|
|
|
JS.push("validate",
|
|
|
|
loading:
|
|
|
|
"#settings-form, #settings-form button, #settings-form input, #settings-form [phx-feedback-for]"
|
|
|
|
)
|
|
|
|
}
|
2022-08-03 13:40:11 +00:00
|
|
|
phx-submit="save"
|
|
|
|
class="space-y-8 divide-y divide-gray-200"
|
|
|
|
>
|
2021-11-09 11:20:10 +00:00
|
|
|
<div class="space-y-8 divide-y divide-gray-200">
|
|
|
|
<div>
|
|
|
|
<div>
|
|
|
|
<p class="mt-1 text-sm text-gray-500">
|
|
|
|
This information will be displayed publicly so be careful what you share.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mt-6 grid grid-cols-1 gap-y-6 gap-x-4 sm:grid-cols-6">
|
|
|
|
<div class="sm:col-span-4">
|
|
|
|
<label for="username" class="block text-sm font-medium text-gray-700">
|
|
|
|
Username
|
|
|
|
</label>
|
|
|
|
<div class="mt-1 flex rounded-md shadow-sm">
|
|
|
|
<span class="inline-flex items-center px-3 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 sm:text-sm">
|
|
|
|
<%= URI.parse(LiveBeatsWeb.Endpoint.url()).host %>/
|
|
|
|
</span>
|
2022-08-03 13:40:11 +00:00
|
|
|
<%= text_input(f, :username,
|
|
|
|
class:
|
|
|
|
"flex-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full min-w-0 rounded-none rounded-r-md sm:text-sm border-gray-300"
|
|
|
|
) %>
|
|
|
|
<.error
|
|
|
|
field={:username}
|
|
|
|
input_name="user[username]"
|
2023-03-06 15:57:42 +00:00
|
|
|
errors={f.errors}
|
2022-08-03 13:40:11 +00:00
|
|
|
class="pt-2 pl-4 pr-4 ml-2 text-center"
|
|
|
|
/>
|
2021-11-09 11:20:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="sm:col-span-4">
|
|
|
|
<label for="username" class="block text-sm font-medium text-gray-700">
|
|
|
|
Email (from GitHub)
|
|
|
|
</label>
|
|
|
|
<div class="mt-1 flex rounded-md shadow-sm">
|
2022-08-03 13:40:11 +00:00
|
|
|
<%= text_input(f, :email,
|
|
|
|
disabled: true,
|
|
|
|
class:
|
|
|
|
"flex-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full min-w-0 rounded-md sm:text-sm border-gray-300 bg-gray-50"
|
|
|
|
) %>
|
2021-11-09 11:20:10 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="sm:col-span-4">
|
|
|
|
<label for="about" class="block text-sm font-medium text-gray-700">
|
|
|
|
Profile Tagline
|
|
|
|
</label>
|
|
|
|
<div class="mt-1">
|
2022-08-03 13:40:11 +00:00
|
|
|
<%= text_input(f, :profile_tagline,
|
|
|
|
class:
|
|
|
|
"flex-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full min-w-0 rounded-md sm:text-sm border-gray-300"
|
|
|
|
) %>
|
|
|
|
<.error
|
|
|
|
field={:profile_tagline}
|
|
|
|
input_name="user[profile_tagline]"
|
2023-03-06 15:57:42 +00:00
|
|
|
errors={f.errors}
|
2022-08-03 13:40:11 +00:00
|
|
|
class="pt-2 pl-4 pr-4 ml-2 text-center"
|
|
|
|
/>
|
2021-11-09 11:20:10 +00:00
|
|
|
</div>
|
|
|
|
<p class="text-sm text-gray-500">Write a short tagline for your beats page.</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="pt-5">
|
|
|
|
<div class="flex justify-end">
|
2022-08-03 13:40:11 +00:00
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
class="ml-3 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
|
|
|
|
>
|
2021-11-09 11:20:10 +00:00
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</.form>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
2022-02-15 03:51:14 +00:00
|
|
|
def mount(_params, _session, socket) do
|
2021-11-09 11:20:10 +00:00
|
|
|
changeset = Accounts.change_settings(socket.assigns.current_user, %{})
|
|
|
|
{:ok, assign(socket, changeset: changeset)}
|
|
|
|
end
|
|
|
|
|
2024-04-09 00:53:14 +00:00
|
|
|
def handle_params(_, _, socket), do: {:noreply, socket}
|
|
|
|
|
2021-11-09 11:20:10 +00:00
|
|
|
def handle_event("validate", %{"user" => params}, socket) do
|
|
|
|
changeset = Accounts.change_settings(socket.assigns.current_user, params)
|
2023-03-06 15:57:42 +00:00
|
|
|
{:noreply, assign(socket, changeset: Map.put(changeset, :action, :validate))}
|
2021-11-09 11:20:10 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def handle_event("save", %{"user" => params}, socket) do
|
2021-11-15 18:06:04 +00:00
|
|
|
case Accounts.update_public_settings(socket.assigns.current_user, params) do
|
2021-11-09 11:20:10 +00:00
|
|
|
{:ok, user} ->
|
|
|
|
{:noreply,
|
|
|
|
socket
|
|
|
|
|> assign(current_user: user)
|
|
|
|
|> put_flash(:info, "settings updated!")}
|
|
|
|
|
|
|
|
{:error, changeset} ->
|
|
|
|
{:noreply, assign(socket, changeset: changeset)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|