@@ -15,21 +15,18 @@ defmodule LivebookWeb.Hub.NewLive do
1515
1616 @ impl true
1717 def mount ( _params , _session , socket ) do
18- socket =
19- assign ( socket ,
20- selected_option: "new-org" ,
21- page_title: "Workspace - Livebook" ,
22- requested_code: false ,
23- org: nil ,
24- verification_uri: nil ,
25- form: nil ,
26- button_label: nil ,
27- request_code_info: nil
28- )
29-
30- socket = assign_form ( socket , "new-org" )
31-
32- { :ok , socket }
18+ { :ok ,
19+ socket
20+ |> assign (
21+ page_title: "Workspace - Livebook" ,
22+ requested_code: false ,
23+ org: nil ,
24+ verification_uri: nil ,
25+ form: nil ,
26+ button_label: nil ,
27+ request_code_info: nil
28+ )
29+ |> assign_form ( ) }
3330 end
3431
3532 @ impl true
@@ -60,38 +57,31 @@ defmodule LivebookWeb.Hub.NewLive do
6057 Livebook Teams</ a > enables you to deploy notebooks as internal apps or turn Livebook into a controlled environment for runbooks and production operations.
6158 </ p >
6259 < p class = "mt-4 text-gray-700 " >
63- To use it, you need to create or join a Teams organization.
60+ To use it, you need to join a Teams organization.
6461 </ p >
6562 </ div >
66- <!-- TABS -->
6763 < div class = "flex flex-col space-y-4 " >
6864 < div class = "flex flex-col justify-center sm:items-center sm:m-auto " >
6965 < div class = "flex rounded-xl bg-gray-100 p-1 " >
7066 < ul class = "flex flex-col sm:flex-row md:flex-col lg:flex-row w-full list-none gap-1 " >
71- <!-- New Org -->
72- < . tab_button
73- id = "new-org "
74- selected = { @ selected_option }
75- title = "Create a new organization "
76- icon = "lightbulb-flash-line "
77- />
78- <!-- Join Org -->
79- < . tab_button
80- id = "join-org "
81- selected = { @ selected_option }
82- title = "Join an existing organization "
83- icon = "organization-chart "
84- />
67+ < li class = "group button flex w-full sm:w-72 items-center justify-center gap-1 md:gap-2 rounded-lg border py-3 md:py-2.5 px-5 transition-opacity duration-100 border-black/10 bg-white drop-shadow-sm hover:opacity-100! " >
68+ < . remix_icon
69+ icon = "organization-chart "
70+ class = "group-hover:text-blue-600 text-lg text-blue-600 "
71+ />
72+ < span class = "truncate text-sm font-medium " >
73+ Join an existing organization
74+ </ span >
75+ </ li >
8576 </ ul >
8677 </ div >
8778 </ div >
8879 </ div >
89- <!-- FORMS -->
90- < div :if = { @ selected_option } class = "flex flex-col space-y-4 " >
80+ < div class = "flex flex-col space-y-4 " >
9181 < . form
9282 :let = { f }
9383 for = { @ form }
94- id = { " #{ @ selected_option } - form"}
84+ id = " join-org- form "
9585 class = "flex flex-col space-y-4 "
9686 phx-submit = "save "
9787 phx-change = "validate "
@@ -102,7 +92,6 @@ defmodule LivebookWeb.Hub.NewLive do
10292 </ div >
10393
10494 < . password_field
105- :if = { @ selected_option == "join-org" }
10695 field = { f [ :teams_key ] }
10796 label = "Livebook Teams key "
10897 />
@@ -168,56 +157,7 @@ defmodule LivebookWeb.Hub.NewLive do
168157 """
169158 end
170159
171- defp tab_button ( assigns ) do
172- ~H"""
173- < li class = "group/toggle w-full " >
174- < button
175- type = "button "
176- id = { @ id }
177- aria-haspopup = "menu "
178- aria-expanded = "false "
179- data-state = "closed "
180- class = "w-full "
181- phx-click = "select_option "
182- phx-value-option = { @ id }
183- >
184- < div class = { [
185- "group button flex w-full sm:w-72 items-center justify-center gap-1 md:gap-2 rounded-lg border py-3 md:py-2.5 px-5 transition-opacity duration-100" ,
186- selected_tab_button ( @ id , @ selected )
187- ] } >
188- < . remix_icon
189- icon = { @ icon }
190- class = { [
191- "group-hover:text-blue-600 text-lg" ,
192- if @ selected == @ id do
193- "text-blue-600"
194- else
195- "text-gray-500"
196- end
197- ] }
198- />
199- < span class = "truncate text-sm font-medium " >
200- { @ title }
201- </ span >
202- </ div >
203- </ button >
204- </ li >
205- """
206- end
207-
208- defp selected_tab_button ( id , id ) ,
209- do: "border-black/10 bg-white drop-shadow-sm hover:opacity-100!"
210-
211- defp selected_tab_button ( _ , _ ) , do: "border-transparent text-gray-500 hover:text-gray-800"
212-
213160 @ impl true
214- def handle_event ( "select_option" , % { "option" => option } , socket ) do
215- { :noreply ,
216- socket
217- |> assign ( selected_option: option , requested_code: false , verification_uri: nil )
218- |> assign_form ( option ) }
219- end
220-
221161 def handle_event ( "validate" , % { "org" => attrs } , socket ) do
222162 changeset =
223163 socket . assigns . org
@@ -228,13 +168,7 @@ defmodule LivebookWeb.Hub.NewLive do
228168 end
229169
230170 def handle_event ( "save" , % { "org" => attrs } , socket ) do
231- result =
232- case socket . assigns . selected_option do
233- "new-org" -> Teams . create_org ( socket . assigns . org , attrs )
234- "join-org" -> Teams . join_org ( socket . assigns . org , attrs )
235- end
236-
237- case result do
171+ case Teams . join_org ( socket . assigns . org , attrs ) do
238172 { :ok , % { "device_code" => device_code } = response } ->
239173 attrs = Map . merge ( attrs , response )
240174 changeset = Teams . change_org ( socket . assigns . org , attrs )
@@ -314,7 +248,7 @@ defmodule LivebookWeb.Hub.NewLive do
314248
315249 def handle_info ( _any , socket ) , do: { :noreply , socket }
316250
317- defp assign_form ( socket , "join-org" ) do
251+ defp assign_form ( socket ) do
318252 org = % Org { emoji: random_emoji ( ) }
319253 changeset = Teams . change_org ( org )
320254
@@ -327,19 +261,6 @@ defmodule LivebookWeb.Hub.NewLive do
327261 |> assign_form ( changeset )
328262 end
329263
330- defp assign_form ( socket , "new-org" ) do
331- org = % Org { emoji: random_emoji ( ) , teams_key: Org . teams_key ( ) }
332- changeset = Teams . change_org ( org )
333-
334- socket
335- |> assign (
336- org: org ,
337- button_label: "Create" ,
338- request_code_info: "Verify your new organization"
339- )
340- |> assign_form ( changeset )
341- end
342-
343264 defp assign_form ( socket , % Ecto.Changeset { } = changeset ) do
344265 assign ( socket , form: to_form ( changeset ) )
345266 end
0 commit comments