Skip to content

Commit

Permalink
fix: removed toast from form
Browse files Browse the repository at this point in the history
  • Loading branch information
theycallmehero committed Nov 8, 2021
1 parent 0deb8cc commit 30bd541
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
16 changes: 2 additions & 14 deletions lib/moon_web/pages/tutorials/add_data_using_form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ defmodule MoonWeb.Pages.Tutorials.AddDataUsingForm do
alias Moon.Components.Link
alias Moon.Components.Select
alias Moon.Components.TextInput
alias Moon.Components.Toast.Message
alias Moon.Components.ToastStack
alias MoonWeb.Components.Breadcrumbs
alias MoonWeb.Components.ExampleAndCode
alias MoonWeb.Components.Footer
Expand Down Expand Up @@ -83,8 +81,6 @@ defmodule MoonWeb.Pages.Tutorials.AddDataUsingForm do
<ExampleAndCode id="add_data_using_form_1">
<:example>
<ToastStack id="toast-stack-messages" />
<Form for={@user_changeset} change="update_user" submit="save_user" autocomplete="off">
<TopToDown>
<TextInput
Expand Down Expand Up @@ -165,21 +161,13 @@ defmodule MoonWeb.Pages.Tutorials.AddDataUsingForm do
end

def handle_event("save_user", _, socket) do
ToastStack.show(
%Message{message: "Details saved.", variant: "success"},
"toast-stack-messages"
)
user_changeset = Map.merge(socket.assigns.user_changeset, %{action: :insert})

{:noreply, socket}
{:noreply, assign(socket, user_changeset: user_changeset)}
end

def handle_event("clear_form", _, socket) do
user_changeset = User.changeset(%User{}, @default_user_map)
{:noreply, assign(socket, user_changeset: user_changeset)}
end

def handle_info({:hide_toast, toast_id}, socket) do
ToastStack.hide_toast(toast_id, "toasts")
{:noreply, socket}
end
end
13 changes: 5 additions & 8 deletions lib/moon_web/pages/tutorials/add_data_using_form/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ defmodule MoonWeb.Pages.Tutorials.AddDataUsingForm.User do
end

def changeset(user = %User{}, params \\ %{}) do
user_changeset =
user
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
|> validate_format(:email, ~r/@/)
|> validate_inclusion(:gender, ["female", "male", "other"])

Map.merge(user_changeset, %{action: :insert})
user
|> cast(params, @required_fields ++ @optional_fields)
|> validate_required(@required_fields)
|> validate_format(:email, ~r/@/)
|> validate_inclusion(:gender, ["female", "male", "other"])
end
end

0 comments on commit 30bd541

Please sign in to comment.