Update the Book form to select publisher via the components.
This commit is contained in:
@@ -33,7 +33,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
label="Language"
|
label="Language"
|
||||||
/>
|
/>
|
||||||
<.input field={@form[:page_count]} type="number" label="Page count" />
|
<.input field={@form[:page_count]} type="number" label="Page count" />
|
||||||
<.input field={@form[:publisher_id]} type="text" label="Publisher" />
|
<.selected_publisher
|
||||||
|
publisher_form={@form[:publisher_id]}
|
||||||
|
notify_component={@myself}
|
||||||
|
/>
|
||||||
<.input
|
<.input
|
||||||
field={@form[:published]}
|
field={@form[:published]}
|
||||||
type="date"
|
type="date"
|
||||||
@@ -57,7 +60,10 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
label="Language"
|
label="Language"
|
||||||
/>
|
/>
|
||||||
<.input field={@form[:page_count]} type="number" label="Page count" />
|
<.input field={@form[:page_count]} type="number" label="Page count" />
|
||||||
<.input field={@form[:publisher_id]} type="text" label="Publisher" />
|
<.selected_publisher
|
||||||
|
publisher_form={@form[:publisher_id]}
|
||||||
|
notify_component={@myself}
|
||||||
|
/>
|
||||||
<.input
|
<.input
|
||||||
field={@form[:published]}
|
field={@form[:published]}
|
||||||
type="date"
|
type="date"
|
||||||
@@ -74,6 +80,21 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
</.cancel_button>
|
</.cancel_button>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.simple_form>
|
</.simple_form>
|
||||||
|
|
||||||
|
<.modal
|
||||||
|
:if={@select_publisher_open? == true}
|
||||||
|
id="select-publisher-modal"
|
||||||
|
show
|
||||||
|
on_cancel={JS.push("close-select-publisher", target: @myself)}
|
||||||
|
>
|
||||||
|
<.live_component
|
||||||
|
id="select-publisher"
|
||||||
|
module={SelectPublisher}
|
||||||
|
action={:edit}
|
||||||
|
current_user={@current_user}
|
||||||
|
notify_component={@myself}
|
||||||
|
/>
|
||||||
|
</.modal>
|
||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
@@ -252,6 +273,7 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
{:ok,
|
{:ok,
|
||||||
socket
|
socket
|
||||||
|> assign(assigns)
|
|> assign(assigns)
|
||||||
|
|> assign(:select_publisher_open?, false)
|
||||||
|> assign_form()}
|
|> assign_form()}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -315,4 +337,32 @@ defmodule DecentralisedBookIndexWeb.BookLive.FormComponent do
|
|||||||
_ -> ~p"/books"
|
_ -> ~p"/books"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def handle_event("select-publisher", %{"publisher" => publisher_id}, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> update(:form, fn form ->
|
||||||
|
form
|
||||||
|
|> AshPhoenix.Form.update_params(&Map.put(&1, "publisher_id", publisher_id))
|
||||||
|
end)
|
||||||
|
|> assign(:select_publisher_open?, false)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("open-select-publisher", _params, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:select_publisher_open?, true)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
|
|
||||||
|
def handle_event("close-select-publisher", _params, socket) do
|
||||||
|
socket =
|
||||||
|
socket
|
||||||
|
|> assign(:select_publisher_open?, false)
|
||||||
|
|
||||||
|
{:noreply, socket}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user