redirect to new note after publishing from dashboard

This commit is contained in:
Inhji 2023-07-04 06:59:43 +02:00
parent c2785d014c
commit faa7acd064

View file

@ -30,14 +30,18 @@ defmodule ChiyaWeb.AdminHomeLive do
|> Map.put_new("published_at", NaiveDateTime.local_now()) |> Map.put_new("published_at", NaiveDateTime.local_now())
case Chiya.Notes.create_note(params) do case Chiya.Notes.create_note(params) do
{:ok, _note} -> {:ok, note} ->
{:noreply, socket |> put_flash(:info, "Note created!")} {:noreply, socket
|> put_flash(:info, "Note created!")
|> push_navigate(to: ~p"/note/#{note.slug}")}
{:error, %Ecto.Changeset{} = changeset} -> {:error, %Ecto.Changeset{} = changeset} ->
IO.inspect(changeset) IO.inspect(changeset)
{:noreply, {:noreply,
socket |> put_flash(:error, "Could not create note!") |> assign(form: to_form(changeset))} socket
|> put_flash(:error, "Could not create note!")
|> assign(form: to_form(changeset))}
end end
end end
@ -58,7 +62,7 @@ defmodule ChiyaWeb.AdminHomeLive do
<.simple_form for={@form} phx-change="validate" phx-submit="save"> <.simple_form for={@form} phx-change="validate" phx-submit="save">
<.input field={@form[:content]} type="textarea" /> <.input field={@form[:content]} type="textarea" />
<:actions> <:actions>
<.button>Save</.button> <.button>Publish</.button>
</:actions> </:actions>
</.simple_form> </.simple_form>
</section> </section>