Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/pearl/accounts/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ defmodule Pearl.Accounts.User do
field :type, Ecto.Enum, values: [:attendee, :staff, :company], default: :attendee
field :allows_marketing, :boolean, default: false
field :cv, Uploaders.CV.Type
field :notes, :string
field :university, :string
field :city, :string
field :dietary_restrictions, :string

# has_one :ticket, Pearl.Tickets.Ticket, on_delete: :delete_all
has_one :attendee, Attendee, on_delete: :delete_all
has_one :staff, Staff, on_delete: :delete_all, on_replace: :update
has_one :company, Company, on_delete: :delete_all
Expand Down
103 changes: 103 additions & 0 deletions lib/pearl/catalog.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
defmodule Pearl.Catalog do
@moduledoc """
Listas para preencher selects de formulários.
"""

def universities do
[
# Universidades Públicas
"Universidade de Lisboa",
"Universidade do Porto",
"Universidade de Coimbra",
"Universidade Nova de Lisboa",
"Universidade do Minho",
"Universidade de Aveiro",
"Universidade da Beira Interior",
"Universidade de Évora",
"Universidade do Algarve",
"Universidade de Trás-os-Montes e Alto Douro",
"Universidade da Madeira",
"Universidade dos Açores",
"Universidade Aberta",
"ISCTE - Instituto Universitário de Lisboa",

# Institutos Politécnicos
"Instituto Politécnico de Lisboa",
"Instituto Politécnico do Porto",
"Instituto Politécnico de Coimbra",
"Instituto Politécnico de Leiria",
"Instituto Politécnico de Setúbal",
"Instituto Politécnico de Viseu",
"Instituto Politécnico de Santarém",
"Instituto Politécnico de Viana do Castelo",
"Instituto Politécnico de Castelo Branco",
"Instituto Politécnico de Beja",
"Instituto Politécnico de Bragança",
"Instituto Politécnico da Guarda",
"Instituto Politécnico de Portalegre",
"Instituto Politécnico de Tomar",
"Instituto Politécnico do Cávado e do Ave",

# Privadas
"Universidade Católica Portuguesa",
"Universidade Lusófona",
"Universidade Lusíada",
"Universidade Fernando Pessoa",
"Universidade Europeia",
"Universidade Autónoma de Lisboa",
"Universidade Portucalense",
"Universidade Atlântica",

# Outra
"Outra / Externo"
]
end

def cities do
# Lista simplificada dos principais concelhos/cidades para não ser gigante
[
"Lisboa",
"Porto",
"Vila Nova de Gaia",
"Amadora",
"Braga",
"Funchal",
"Coimbra",
"Setúbal",
"Almada",
"Agualva-Cacém",
"Queluz",
"Rio Tinto",
"Barreiro",
"Aveiro",
"Viseu",
"Odivelas",
"Leiria",
"Guimarães",
"Faro",
"Matosinhos",
"Loures",
"Póvoa de Varzim",
"Maia",
"Évora",
"Portimão",
"Viana do Castelo",
"Castelo Branco",
"Covilhã",
"Guarda",
"Vila Real",
"Ponta Delgada",
"Santarém",
"Figueira da Foz",
"Caldas da Rainha",
"Torres Vedras",
"Vila Franca de Xira",
"Valongo",
"Gondomar",
"Vila do Conde",
"Barcelos",
"Outra"
]
|> Enum.sort()
end
end
143 changes: 62 additions & 81 deletions lib/pearl_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,16 @@ defmodule PearlWeb.CoreComponents do

@doc """
Renders an input with label and error messages.

A `Phoenix.HTML.FormField` may be passed as argument,
which is used to retrieve the input name, id, and values.
Otherwise all attributes may be passed explicitly.

## Types

This function accepts all HTML input types, considering that:

* You may also set `type="select"` to render a `<select>` tag

* `type="checkbox"` is used exclusively to render boolean values

* For live file uploads, see `Phoenix.Component.live_file_input/1`

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
for more information. Unsupported types, such as hidden and radio,
are best written directly in your templates.

## Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />
...
"""
attr :id, :any, default: nil
attr :name, :any
attr :label, :string, default: nil
attr :value, :any

# Add this new attribute
attr :variant, :atom, values: [:default, :flushed], default: :default

attr :type, :string,
default: "text",
values: ~w(checkbox color date datetime-local email file month number password
Expand Down Expand Up @@ -339,17 +320,22 @@ defmodule PearlWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name} class={@wrapper_class}>
<.label for={@id}>{@label}</.label>
<select
id={@id}
name={@name}
class={"mt-2 block w-full rounded-md border border-gray-300 bg-white shadow-sm focus:border-zinc-400 focus:ring-0 sm:text-sm #{@class}"}
multiple={@multiple}
{@rest}
>
<option :if={@prompt} value="">{@prompt}</option>
{Phoenix.HTML.Form.options_for_select(@options, @value)}
</select>
<.error :for={msg <- @errors}>{msg}</.error>
<div class="w-full">
<select
id={@id}
name={@name}
class={[
input_class(@variant),
@class
]}
multiple={@multiple}
{@rest}
>
<option :if={@prompt} value="">{@prompt}</option>
{Phoenix.HTML.Form.options_for_select(@options, @value)}
</select>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
</div>
"""
end
Expand All @@ -358,74 +344,69 @@ defmodule PearlWeb.CoreComponents do
~H"""
<div phx-feedback-for={@name} class={@wrapper_class}>
<.label for={@id}>{@label}</.label>
<textarea
id={@id}
name={@name}
class={[
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6",
"min-h-[6rem] phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400",
@class,
@errors == [] && "border-zinc-300 focus:border-zinc-400",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %></textarea>
<.error :for={msg <- @errors}>{msg}</.error>
<div class="w-full">
<textarea
id={@id}
name={@name}
class={[
input_class(@variant),
"min-h-24",
@class,
input_border(@variant, @errors)
]}
{@rest}
><%= Phoenix.HTML.Form.normalize_value("textarea", @value) %></textarea>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
</div>
"""
end

def input(%{type: "handle"} = assigns) do
def input(assigns) do
~H"""
<div phx-feedback-for={@name} class={@wrapper_class}>
<.label for={@id}>{@label}</.label>
<div class={[
"mt-2 flex bg-white w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6",
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400 select-none",
@class,
@errors == [] && "border-zinc-300 focus:border-zinc-400",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}>
<span class="pl-3 self-center text-zinc-600 border-r pr-2 mr-3 border-zinc-400/50">@</span>
<div class="w-full">
<input
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"block w-full border-none focus:outline-none focus:ring-transparent mr-4 text-zinc-900 sm:text-sm sm:leading-6 border-0 ring-0 py-[0.5rem]",
@class
input_class(@variant),
@class,
input_border(@variant, @errors)
]}
{@rest}
/>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
end

# All other inputs text, datetime-local, url, password, etc. are handled here...
def input(assigns) do
~H"""
<div phx-feedback-for={@name} class={@wrapper_class}>
<.label for={@id}>{@label}</.label>
<input
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6",
"phx-no-feedback:border-zinc-300 phx-no-feedback:focus:border-zinc-400",
@class,
@errors == [] && "border-zinc-300 focus:border-zinc-400",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
/>
<.error :for={msg <- @errors}>{msg}</.error>
</div>
"""
defp input_class(:default) do
"mt-2 block w-full rounded-lg text-dark focus:ring-0 sm:text-sm sm:leading-6 bg-surface border-0"
end

defp input_class(:flushed) do
"block w-full px-0 py-2 border-0 border-b border-dark-muted/30 focus:border-primary focus:ring-0 bg-transparent text-dark placeholder-dark-muted/60 focus:outline-none transition-colors sm:text-sm"
end

defp input_border(:default, errors) do
if errors == [] do
"border-transparent focus:border-primary"
else
"border-danger-400 focus:border-danger-400"
end
end

defp input_border(:flushed, errors) do
if errors == [] do
""
else
"border-danger-500 focus:border-danger-500 text-danger-500 placeholder-danger-300"
end
end

@doc """
Expand Down
Loading
Loading