@@ -49,10 +49,6 @@ defmodule AlgoraWeb.Onboarding.DevLive do
49
49
50
50
@ impl true
51
51
def mount ( _params , _session , socket ) do
52
- if connected? ( socket ) do
53
- Phoenix.PubSub . subscribe ( Algora.PubSub , "auth:#{ socket . id } " )
54
- end
55
-
56
52
context = % {
57
53
country: socket . assigns . current_country ,
58
54
tech_stack: [ ] ,
@@ -94,6 +90,35 @@ defmodule AlgoraWeb.Onboarding.DevLive do
94
90
|> assign ( :signup_form , signup_form ) }
95
91
end
96
92
93
+ @ impl true
94
+ def render ( % { current_user: current_user } = assigns ) when not is_nil ( current_user ) do
95
+ ~H"""
96
+ < div
97
+ class = "w-screen h-screen fixed inset-0 bg-background z-[100] "
98
+ phx-hook = "LocalStateStore "
99
+ id = "onboarding-dev-page "
100
+ >
101
+ < div class = "flex items-center justify-center h-full " >
102
+ < svg
103
+ class = "mr-3 -ml-1 size-12 animate-spin text-success "
104
+ xmlns = "http://www.w3.org/2000/svg "
105
+ fill = "none "
106
+ viewBox = "0 0 24 24 "
107
+ >
108
+ < circle class = "opacity-25 " cx = "12 " cy = "12 " r = "10 " stroke = "currentColor " stroke-width = "4 " >
109
+ </ circle >
110
+ < path
111
+ class = "opacity-75 "
112
+ fill = "currentColor "
113
+ d = "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z "
114
+ >
115
+ </ path >
116
+ </ svg >
117
+ </ div >
118
+ </ div >
119
+ """
120
+ end
121
+
97
122
@ impl true
98
123
def render ( assigns ) do
99
124
~H"""
@@ -127,37 +152,37 @@ defmodule AlgoraWeb.Onboarding.DevLive do
127
152
{ :noreply , socket }
128
153
end
129
154
130
- @ impl true
131
- def handle_info ( { :authenticated , user } , socket ) do
132
- tech_stack = get_field ( socket . assigns . info_form . source , :tech_stack ) || [ ]
133
- intentions = get_field ( socket . assigns . info_form . source , :intentions ) || [ ]
134
-
135
- case user
136
- |> change (
137
- tech_stack: tech_stack ,
138
- seeking_bounties: "bounties" in intentions ,
139
- seeking_contracts: "contracts" in intentions ,
140
- seeking_jobs: "jobs" in intentions
141
- )
142
- |> Repo . update ( ) do
143
- { :ok , user } ->
144
- { :noreply , redirect ( socket , to: AlgoraWeb.UserAuth . generate_login_path ( user . email ) ) }
145
-
146
- { :error , changeset } ->
147
- Logger . error ( "Failed to update user #{ user . id } on onboarding: #{ inspect ( changeset ) } " )
148
- { :noreply , put_flash ( socket , :error , "Something went wrong. Please try again." ) }
149
- end
150
- end
151
-
152
155
@ impl true
153
156
def handle_event ( "restore_settings" , params , socket ) do
154
- { :noreply , LocalStore . restore ( socket , params ) }
157
+ socket = LocalStore . restore ( socket , params )
158
+
159
+ if user = socket . assigns [ :current_user ] do
160
+ tech_stack = get_field ( socket . assigns . info_form . source , :tech_stack ) || [ ]
161
+ intentions = get_field ( socket . assigns . info_form . source , :intentions ) || [ ]
162
+
163
+ case user
164
+ |> change (
165
+ tech_stack: tech_stack ,
166
+ seeking_bounties: "bounties" in intentions ,
167
+ seeking_contracts: "contracts" in intentions ,
168
+ seeking_jobs: "jobs" in intentions
169
+ )
170
+ |> Repo . update ( ) do
171
+ { :ok , user } ->
172
+ { :noreply , redirect ( socket , to: AlgoraWeb.UserAuth . generate_login_path ( user . email ) ) }
173
+
174
+ { :error , changeset } ->
175
+ Logger . error ( "Failed to update user #{ user . id } on onboarding: #{ inspect ( changeset ) } " )
176
+ { :noreply , put_flash ( socket , :error , "Something went wrong. Please try again." ) }
177
+ end
178
+ else
179
+ { :noreply , socket }
180
+ end
155
181
end
156
182
157
183
@ impl true
158
184
def handle_event ( "sign_in_with_github" , _params , socket ) do
159
- popup_url = Github . authorize_url ( % { socket_id: socket . id } )
160
- { :noreply , push_event ( socket , "open_popup" , % { url: popup_url } ) }
185
+ { :noreply , redirect ( socket , external: Github . authorize_url ( % { return_to: ~p" /onboarding/dev?checkpoint=1" } ) ) }
161
186
end
162
187
163
188
@ impl true
0 commit comments