29 lines
828 B
Elixir
29 lines
828 B
Elixir
defmodule RecycledCloudWeb.SupportController do
|
|
use RecycledCloudWeb, :controller
|
|
|
|
alias RecycledCloud.SupportRequest
|
|
|
|
def new(conn, _params) do
|
|
conn
|
|
|> assign(:request_changeset, SupportRequest.changeset(%SupportRequest{}, %{}))
|
|
|> render("new.html")
|
|
end
|
|
|
|
def create(conn, %{"support_request" => request} = params) do
|
|
action = SupportRequest.changeset(%SupportRequest{}, request)
|
|
|> Ecto.Changeset.apply_action(:update)
|
|
case action do
|
|
{:ok, request} ->
|
|
SupportRequest.send(request)
|
|
|
|
conn
|
|
|> put_flash(:info, "Request has been sent. We'll come back to you.")
|
|
|> redirect(to: Routes.page_path(conn, :index))
|
|
|
|
{:error, changeset} ->
|
|
conn
|
|
|> assign(:request_changeset, changeset)
|
|
|> render("new.html")
|
|
end
|
|
end
|
|
end
|