Skip to content

Commit 3aa1cfd

Browse files
committed
feat: adapt /go sidebar based on whether previewed user exists
1 parent 452f0ea commit 3aa1cfd

File tree

1 file changed

+97
-14
lines changed

1 file changed

+97
-14
lines changed

lib/algora_web/live/org/dashboard_live.ex

Lines changed: 97 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ defmodule AlgoraWeb.Org.DashboardLive do
4646

4747
defp list_contributors(_current_org), do: []
4848

49+
defp get_previewed_user(%{last_context: "repo/" <> repo} = _current_org) do
50+
case String.split(repo, "/") do
51+
[repo_owner, _repo_name] ->
52+
Repo.one(from u in User, where: u.provider_login == ^repo_owner and not is_nil(u.handle))
53+
54+
_ ->
55+
nil
56+
end
57+
end
58+
59+
defp get_previewed_user(_current_org), do: nil
60+
4961
@impl true
5062
def mount(_params, _session, %{assigns: %{live_action: :preview, current_org: nil}} = socket) do
5163
{:ok, socket}
@@ -85,6 +97,7 @@ defmodule AlgoraWeb.Org.DashboardLive do
8597
|> assign(:installations, installations)
8698
|> assign(:experts, experts)
8799
|> assign(:contributors, contributors)
100+
|> assign(:previewed_user, get_previewed_user(current_org))
88101
|> assign(:matches, matches)
89102
|> assign(:developers, developers)
90103
|> assign(:has_more_bounties, false)
@@ -1122,9 +1135,54 @@ defmodule AlgoraWeb.Org.DashboardLive do
11221135
id="send_login_code_form"
11231136
phx-submit="send_login_code"
11241137
>
1125-
<.input field={@login_form[:login_code]} type="text" label="Login code" required />
1138+
<.input
1139+
field={@login_form[:login_code]}
1140+
type="text"
1141+
label="Login code"
1142+
placeholder="123456"
1143+
required
1144+
/>
11261145
<.button phx-disable-with="Signing in..." class="w-full py-5">
1127-
Submit
1146+
✨ Get in ✨
1147+
</.button>
1148+
</.simple_form>
1149+
"""
1150+
end
1151+
1152+
defp achievement_todo(%{achievement: %{id: :complete_signin_status}} = assigns) do
1153+
~H"""
1154+
<.simple_form
1155+
:if={!@secret}
1156+
for={@login_form}
1157+
id="send_login_code_form"
1158+
phx-submit="send_login_code"
1159+
>
1160+
<.input
1161+
field={@login_form[:email]}
1162+
type="email"
1163+
label="Email"
1164+
placeholder="[email protected]"
1165+
required
1166+
/>
1167+
<.button phx-disable-with="Signing in..." class="w-full py-5">
1168+
Sign in
1169+
</.button>
1170+
</.simple_form>
1171+
<.simple_form
1172+
:if={@secret}
1173+
for={@login_form}
1174+
id="send_login_code_form"
1175+
phx-submit="send_login_code"
1176+
>
1177+
<.input
1178+
field={@login_form[:login_code]}
1179+
type="text"
1180+
label="Login code"
1181+
placeholder="123456"
1182+
required
1183+
/>
1184+
<.button phx-disable-with="Signing in..." class="w-full py-5">
1185+
✨ Get in ✨
11281186
</.button>
11291187
</.simple_form>
11301188
"""
@@ -1166,17 +1224,29 @@ defmodule AlgoraWeb.Org.DashboardLive do
11661224
defp assign_achievements(socket) do
11671225
current_org = socket.assigns.current_org
11681226

1169-
status_fns = [
1170-
{&personalize_status/1, "Personalize Algora", nil},
1171-
{&complete_signup_status/1, "Complete signup", nil},
1172-
{&connect_github_status/1, "Connect GitHub", nil},
1173-
{&install_app_status/1, "Install Algora in #{current_org.name}", nil},
1174-
{&create_bounty_status/1, "Create a bounty", nil},
1175-
{&reward_bounty_status/1, "Reward a bounty", nil},
1176-
{&create_contract_status/1, "Contract a developer",
1177-
if(current_org.handle, do: [patch: ~p"/#{current_org.handle}/dashboard?action=create_contract"])},
1178-
{&share_with_friend_status/1, "Share Algora with a friend", nil}
1179-
]
1227+
status_fns =
1228+
case socket.assigns.previewed_user do
1229+
nil ->
1230+
[
1231+
{&personalize_status/1, "Personalize Algora", nil},
1232+
{&complete_signup_status/1, "Complete signup", nil},
1233+
{&connect_github_status/1, "Connect GitHub", nil},
1234+
{&install_app_status/1, "Install Algora in #{current_org.name}", nil},
1235+
{&create_bounty_status/1, "Create a bounty", nil},
1236+
{&reward_bounty_status/1, "Reward a bounty", nil},
1237+
{&create_contract_status/1, "Contract a developer",
1238+
if(current_org.handle, do: [patch: ~p"/#{current_org.handle}/dashboard?action=create_contract"])},
1239+
{&share_with_friend_status/1, "Share Algora with a friend", nil}
1240+
]
1241+
1242+
_ ->
1243+
[
1244+
{&complete_signin_status/1, "Sign in to your account", nil},
1245+
{&create_contract_status/1, "Contract a developer",
1246+
if(current_org.handle, do: [patch: ~p"/#{current_org.handle}/dashboard?action=create_contract"])},
1247+
{&share_with_friend_status/1, "Share Algora with a friend", nil}
1248+
]
1249+
end
11801250

11811251
{achievements, _} =
11821252
Enum.reduce_while(status_fns, {[], false}, fn {status_fn, name, path}, {acc, found_current} ->
@@ -1209,6 +1279,13 @@ defmodule AlgoraWeb.Org.DashboardLive do
12091279
end
12101280
end
12111281

1282+
defp complete_signin_status(socket) do
1283+
case socket.assigns.current_user do
1284+
%User{handle: handle} when is_binary(handle) -> :completed
1285+
_ -> :upcoming
1286+
end
1287+
end
1288+
12121289
defp connect_github_status(socket) do
12131290
case socket.assigns.current_user do
12141291
%User{provider_login: login} when is_binary(login) -> :completed
@@ -1636,7 +1713,13 @@ defmodule AlgoraWeb.Org.DashboardLive do
16361713
~H"""
16371714
<aside class="scrollbar-thin fixed top-16 right-0 bottom-0 hidden w-96 h-full overflow-y-auto border-l border-border bg-background p-4 pt-6 sm:p-6 md:p-8 lg:flex lg:flex-col">
16381715
<div :if={length(@achievements) > 1} class="pb-12">
1639-
<h2 class="text-xl font-semibold leading-none tracking-tight">Getting started</h2>
1716+
<h2 class="text-xl font-semibold leading-none tracking-tight">
1717+
<%= if @previewed_user do %>
1718+
Get back in
1719+
<% else %>
1720+
Getting started
1721+
<% end %>
1722+
</h2>
16401723
<nav class="pt-6">
16411724
<ol role="list" class="space-y-6">
16421725
<%= for achievement <- @achievements do %>

0 commit comments

Comments
 (0)