Skip to content

Commit 719af2f

Browse files
committed
feat: org settings page
1 parent 42df38b commit 719af2f

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
defmodule AlgoraWeb.Org.SettingsLive do
2+
@moduledoc false
3+
use AlgoraWeb, :live_view
4+
5+
alias Algora.Accounts
6+
alias Algora.Accounts.User
7+
8+
def render(assigns) do
9+
~H"""
10+
<div class="container mx-auto max-w-7xl space-y-6 p-6">
11+
<div class="space-y-1">
12+
<h1 class="text-2xl font-bold">Settings</h1>
13+
<p class="text-muted-foreground">Update your settings and preferences</p>
14+
</div>
15+
16+
<.card>
17+
<.card_header>
18+
<.card_title>Account</.card_title>
19+
</.card_header>
20+
<.card_content>
21+
<.simple_form for={@form} phx-change="validate" phx-submit="save">
22+
<div class="flex flex-col gap-6">
23+
<div class="flex flex-col gap-2">
24+
<.input field={@form[:handle]} label="Handle" />
25+
<p class="text-sm text-muted-foreground flex items-center gap-1.5">
26+
<.icon name="tabler-alert-triangle" class="w-4 h-4" />
27+
Changing your handle can have unintended side effects.
28+
</p>
29+
</div>
30+
<.button class="ml-auto">Save</.button>
31+
</div>
32+
</.simple_form>
33+
</.card_content>
34+
</.card>
35+
36+
<.card>
37+
<.card_header>
38+
<.card_title>Public Profile</.card_title>
39+
</.card_header>
40+
<.card_content>
41+
<.simple_form for={@form} phx-change="validate" phx-submit="save">
42+
<div class="flex flex-col gap-6">
43+
<.input field={@form[:display_name]} label="Name" />
44+
<.input field={@form[:bio]} type="textarea" label="Bio" />
45+
<.input field={@form[:website_url]} label="Website" />
46+
<.input field={@form[:location]} label="Location" />
47+
<.input
48+
field={@form[:timezone]}
49+
label="Timezone"
50+
type="select"
51+
options={Algora.Time.list_friendly_timezones()}
52+
/>
53+
<.button class="ml-auto">Save</.button>
54+
</div>
55+
</.simple_form>
56+
</.card_content>
57+
</.card>
58+
</div>
59+
"""
60+
end
61+
62+
def mount(_params, _session, socket) do
63+
%{current_org: current_org} = socket.assigns
64+
65+
changeset = User.settings_changeset(current_org, %{})
66+
67+
{:ok,
68+
socket
69+
|> assign(current_org: current_org)
70+
|> assign_form(changeset)}
71+
end
72+
73+
def handle_event("validate", %{"user" => params}, socket) do
74+
changeset =
75+
socket.assigns.current_org
76+
|> User.settings_changeset(params)
77+
|> Map.put(:action, :validate)
78+
79+
{:noreply, assign_form(socket, changeset)}
80+
end
81+
82+
def handle_event("save", %{"user" => params}, socket) do
83+
case Accounts.update_settings(socket.assigns.current_org, params) do
84+
{:ok, user} ->
85+
{:noreply,
86+
socket
87+
|> assign(current_org: user)
88+
|> put_flash(:info, "Settings updated!")}
89+
90+
{:error, changeset} ->
91+
{:noreply, assign_form(socket, changeset)}
92+
end
93+
end
94+
95+
def handle_params(params, _url, socket) do
96+
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
97+
end
98+
99+
defp apply_action(socket, :edit, _params) do
100+
assign(socket, :page_title, "Settings")
101+
end
102+
103+
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
104+
assign(socket, :form, to_form(changeset))
105+
end
106+
end

lib/algora_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ defmodule AlgoraWeb.Router do
101101
live "/org/:org_handle/jobs/:id", Org.JobLive, :index
102102
live "/org/:org_handle/analytics", Org.AnalyticsLive, :index
103103
live "/org/:org_handle/chat", ChatLive, :index
104+
live "/org/:org_handle/settings", Org.SettingsLive, :edit
104105
end
105106

106107
live_session :org2,

0 commit comments

Comments
 (0)