Skip to content

Commit

Permalink
fix: resolved form fields blank when typing
Browse files Browse the repository at this point in the history
  • Loading branch information
douglastofoli committed Nov 29, 2023
1 parent 60e607f commit 28b2eab
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 33 deletions.
8 changes: 7 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ if ! test -d apps/plataforma_digital/assets/node_modules && test -f apps/platafo
cd apps/plataforma_digital/assets && npm install && cd $PWD
fi

USE_LOCAL_POSTGRES=false

# Setup postgresql
if test -d "/Applications/Postgres.app"; then
export DATABASE_USER="$(whoami)"
export DATABASE_PASSWORD=""
else
elif $USE_LOCAL_POSTGRES; then
# postges related
export DATABASE_USER="peapescarte"
export DATABASE_PASSWORD="peapescarte"
Expand All @@ -45,4 +47,8 @@ else
# creates local databse
echo "CREATE DATABASE $PG_DATABASE;" | postgres --single -E postgres
fi
else
export DATABASE_USER="postgres"
export DATABASE_PASSWORD="postgres"
export PG_DATABASE="peapescarte_dev"
fi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule ModuloPesquisa.Handlers.IManageRelatoriosHandler do
alias ModuloPesquisa.Schemas.RelatorioPesquisa

@callback change_relatorio_pesquisa(RelatorioPesquisa.t(), map()) :: Ecto.Changeset.t()
@callback list_relatorios(sorter) :: list(RelatorioPesquisa.t())
when sorter: function
@callback list_relatorios_from_pesquisador(id, sorter) :: list(RelatorioPesquisa.t())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ defmodule ModuloPesquisa.Models.RelatorioPesquisa do
|> validate_inclusion(:status, @status)
|> foreign_key_constraint(:pesquisador_id)
|> validate_period()
|> put_limit_date()
end

defp put_limit_date(changeset) do
report_type = get_field(changeset, :tipo)
today = Date.utc_today()

limit_date =
case report_type do
:mensal -> Date.from_iso8601!("#{today.year}-#{today.month}-15")
:trimestral -> Date.from_iso8601!("#{today.year}-#{today.month}-10")
:anual -> today
nil -> changeset
end

put_change(changeset, :data_limite, limit_date)
end

defp validate_period(changeset) do
Expand Down
4 changes: 2 additions & 2 deletions apps/plataforma_digital/assets/css/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ footer {
@apply h-screen;
}

header > nav {
header>nav {
@apply h-full;
}

Expand Down Expand Up @@ -182,4 +182,4 @@ footer {
@import "./pages/app/researcher/relatorio/report.scss";

// Páginas de Erros
@import "./errors/404.scss";
@import "./errors/404.scss";
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ defmodule PlataformaDigital.DesignSystem do
<.button style="primary" submit> Submissão </.button>
"""

attr(:name, :string, default: "")
attr(:value, :string, default: "")
attr(:style, :string, values: ~w(primary secondary link), required: true)
attr(:submit, :boolean, default: false)
attr(:disabled, :boolean, default: false)
Expand All @@ -126,6 +128,8 @@ defmodule PlataformaDigital.DesignSystem do
def button(assigns) do
~H"""
<button
name={@name}
value={@value}
type={if @submit, do: "submit", else: "button"}
class={["btn", "btn-#{@style}", @class]}
phx-click={@click}
Expand Down Expand Up @@ -324,7 +328,6 @@ defmodule PlataformaDigital.DesignSystem do
attr(:placeholder, :string, required: false, default: "")
attr(:value, :string, default: "")
attr(:valid, :boolean, required: false, default: nil)
attr(:field, Phoenix.HTML.FormField)
attr(:class, :string, default: "")

slot(:label, required: false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ defmodule PlataformaDigital.Pesquisa.Relatorio.FormComponent do
<%= @form_title %>
</.text>
<.form for={@form} phx-target={@myself} phx-change="validate" phx-submit="save">
<.form
for={@form}
id="relatorio-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<div class="input-date-group" style="display: flex;">
<.text_input type="date" label="Início período" field={@form[:data_inicio]} />
<.text_input type="date" label="Fim periodo" field={@form[:data_fim]} />
Expand Down Expand Up @@ -86,7 +92,11 @@ defmodule PlataformaDigital.Pesquisa.Relatorio.FormComponent do

@impl true
def handle_event("save", %{"save" => "send-report", "relatorio_pesquisa" => params}, socket) do
params = put_in(params, ["status"], "entregue")
params =
params
|> put_in(["status"], "entregue")
|> put_in(["data_entrega"], Date.utc_today())

handle_store(socket, socket.assigns.action, params)
end

Expand Down Expand Up @@ -117,19 +127,17 @@ defmodule PlataformaDigital.Pesquisa.Relatorio.FormComponent do
end
end

# defp get_data_limite(%{tipo_relatorio: tipo_relatorio, today: today}) do
# case tipo_relatorio do
# "mensal" -> Date.from_iso8601!("#{today.year}-#{today.month}-15")
# "trimestral" -> Date.from_iso8601!("#{today.year}-#{today.month}-10")
# "anual" -> Date.utc_today()
# end
# end

defp notify_parent(msg), do: send(self(), {__MODULE__, msg})

defp report_field(assigns) do
~H"""
<.text_area field={@field} disabled={@disabled} class="report-field">
<.text_area
id={@field.id}
name={@field.name}
value={@field.value}
disabled={@disabled}
class="report-field"
>
<:label>
<.text size="h3" color="text-blue-100">
<%= @label %>
Expand Down
36 changes: 18 additions & 18 deletions apps/plataforma_digital/lib/plataforma_digital/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,47 @@ defmodule PlataformaDigital.Router do
import PlataformaDigital.Authentication

pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, {PlataformaDigital.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug :fetch_current_user
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_live_flash)
plug(:put_root_layout, {PlataformaDigital.Layouts, :root})
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
plug(:fetch_current_user)
end

scope "/" do
storybook_assets()
end

scope "/", PlataformaDigital do
pipe_through :browser
pipe_through(:browser)

get "/", LandingController, :show
get("/", LandingController, :show)

live_storybook("/storybook", backend_module: PlataformaDigital.Storybook)
end

scope "/", PlataformaDigital do
pipe_through [:browser, :redirect_if_user_is_authenticated]
pipe_through([:browser, :redirect_if_user_is_authenticated])

get "/acessar", LoginController, :show
post "/acessar", LoginController, :create
get("/acessar", LoginController, :show)
post("/acessar", LoginController, :create)
end

scope "/app/pesquisa", PlataformaDigital do
pipe_through :browser
pipe_through(:browser)
# pipe_through [:browser, :require_authenticated_user]

live_session :require_authenticated_user,
on_mount: [{PlataformaDigital.Authentication, :ensure_authenticated}] do
live "/perfil", Pesquisa.ProfileLive
live "/pesquisadores", Pesquisa.ListPesquisadorLive
live("/perfil", Pesquisa.ProfileLive)
live("/pesquisadores", Pesquisa.ListPesquisadorLive)

scope "/relatorios" do
live "/", Pesquisa.Relatorio.ListReportLive
live "/new", Pesquisa.RelatorioLive.Index, :new
live "/:id", Pesquisa.RelatorioLive.Index, :edit
live("/", Pesquisa.Relatorio.ListReportLive)
live("/new", Pesquisa.RelatorioLive.Index, :new)
live("/edit/:id", Pesquisa.RelatorioLive.Index, :edit)
end
end
end
Expand Down

0 comments on commit 28b2eab

Please sign in to comment.