2021-03-09 20:55:59 -05:00
|
|
|
defmodule Shift73kWeb.ShiftTemplateLive.DeleteComponent do
|
|
|
|
use Shift73kWeb, :live_component
|
|
|
|
|
2021-03-11 16:57:20 -05:00
|
|
|
alias Shift73k.Shifts.Templates
|
2021-03-09 20:55:59 -05:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def update(assigns, socket) do
|
|
|
|
socket
|
|
|
|
|> assign(assigns)
|
|
|
|
|> live_okreply()
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def handle_event("confirm", %{"id" => id, "subject" => subject}, socket) do
|
|
|
|
id
|
2021-03-11 16:57:20 -05:00
|
|
|
|> Templates.get_shift_template()
|
|
|
|
|> Templates.delete_shift_template()
|
2021-03-09 20:55:59 -05:00
|
|
|
|> case do
|
|
|
|
{:ok, _} ->
|
|
|
|
flash = {:info, "Shift template deleted successfully: \"#{subject}\""}
|
|
|
|
send(self(), {:put_flash_message, flash})
|
|
|
|
|
|
|
|
socket
|
|
|
|
|> push_event("modal-please-hide", %{})
|
|
|
|
|> live_noreply()
|
|
|
|
|
|
|
|
{:error, _} ->
|
|
|
|
flash =
|
|
|
|
{:error,
|
|
|
|
"Some error trying to delete shift template \"#{subject}\". Possibly already deleted? Reloading list..."}
|
|
|
|
|
|
|
|
send(self(), {:put_flash_message, flash})
|
|
|
|
|
|
|
|
socket
|
|
|
|
|> push_event("modal-please-hide", %{})
|
|
|
|
|> live_noreply()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|