File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ defmodule CesiumLinkWeb.RedirectLive.Index do
20
20
|> assign ( :redirect , Redirects . get_redirect! ( id ) )
21
21
end
22
22
23
+ defp apply_action ( socket , :delete , % { "id" => id } ) do
24
+ socket
25
+ |> assign ( :page_title , "Delete Redirect" )
26
+ |> assign ( :redirect , Redirects . get_redirect! ( id ) )
27
+ end
28
+
23
29
defp apply_action ( socket , :new , _params ) do
24
30
socket
25
31
|> assign ( :page_title , "New Redirect" )
@@ -42,7 +48,10 @@ defmodule CesiumLinkWeb.RedirectLive.Index do
42
48
redirect = Redirects . get_redirect! ( id )
43
49
{ :ok , _ } = Redirects . delete_redirect ( redirect )
44
50
45
- { :noreply , stream_delete ( socket , :redirects , redirect ) }
51
+ { :noreply ,
52
+ stream_delete ( socket , :redirects , redirect )
53
+ |> push_patch ( to: ~p" /admin/redirects" )
54
+ |> put_flash ( :info , "Redirect deleted successfully" ) }
46
55
end
47
56
48
57
defp get_redirect_url ( % Redirect { slug: slug , type: type } ) do
Original file line number Diff line number Diff line change 37
37
< . icon name = "hero-pencil " class = "w-5 h-5 " />
38
38
</ . link >
39
39
</: action >
40
- <: action :let = { { id , redirect } } >
41
- < . link phx-click = { JS . push ( "delete" , value: % { id: redirect . id } ) |> hide ( "# #{ id } " ) } data-confirm = " Are you sure? " >
40
+ <: action :let = { { _id , redirect } } >
41
+ < . link patch = { ~p " /admin/redirects/ #{ redirect } /delete " } >
42
42
< . icon name = "hero-trash " class = "w-5 h-5 " />
43
43
</ . link >
44
44
</: action >
47
47
< . modal :if = { @ live_action in [ :new , :edit ] } id = "redirect-modal " show on_cancel = { JS . patch ( ~p" /admin/redirects" ) } >
48
48
< . live_component module = { CesiumLinkWeb.RedirectLive.FormComponent } id = { @ redirect . id || :new } title = { @ page_title } action = { @ live_action } redirect = { @ redirect } patch = { ~p" /admin/redirects" } />
49
49
</ . modal >
50
+
51
+ < . modal :if = { @ live_action == :delete } id = "delete-modal " show on_cancel = { JS . patch ( ~p" /admin/redirects" ) } >
52
+ < div >
53
+ < . header >
54
+ <%= gettext ( "Delete Redirect" ) %>
55
+ <: subtitle >
56
+ <%= gettext ( "Are you sure you want to delete this redirect? This action is irreversible." ) %>
57
+ </: subtitle >
58
+ </ . header >
59
+ < div class = "mt-8 w-full gap-2 flex flex-row " >
60
+ < . link patch = { ~p" /admin/redirects" } class = "w-full outline-none " >
61
+ < . button class = "w-full " >
62
+ <%= gettext ( "Cancel" ) %>
63
+ </ . button >
64
+ </ . link >
65
+ < . button phx-click = "delete " phx-value-id = { @ redirect . id } class = "w-full " >
66
+ <%= gettext ( "Confirm" ) %>
67
+ </ . button >
68
+ </ div >
69
+ </ div >
70
+ </ . modal >
Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ defmodule CesiumLinkWeb.Router do
85
85
live "/redirects" , RedirectLive.Index , :index
86
86
live "/redirects/new" , RedirectLive.Index , :new
87
87
live "/redirects/:id/edit" , RedirectLive.Index , :edit
88
+ live "/redirects/:id/delete" , RedirectLive.Index , :delete
88
89
89
90
live "/qrcode" , QRCodeLive.Index , :index
90
91
end
You can’t perform that action at this time.
0 commit comments