Skip to content

Commit

Permalink
feat: add simple_form
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Nov 18, 2024
1 parent 58582ed commit ddf3adc
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 29 deletions.
14 changes: 14 additions & 0 deletions lib/safira/accounts/spotlights.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Safira.Spotlights do
use Ecto.Schema
import Ecto.Changeset

schema "spotlights" do
field :duration, :integer
end

def change_spotlight(spotlight, attrs \\ %{}) do
spotlight
|> cast(attrs, [:duration])
|> validate_required([:duration])
end
end
28 changes: 0 additions & 28 deletions lib/safira/uploaders/spotlight.ex

This file was deleted.

29 changes: 29 additions & 0 deletions lib/safira/uploaders/spotlights.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule Safira.Uploaders.Spotlight do
@moduledoc """
Spotlight image uploader.
"""
use Safira.Uploader

alias Safira.Contest.Spotlight

@versions [:original]
@extension_whitelist ~w(.svg .png)

def validate({file, _}) do
file_extension = file.file_name |> Path.extname() |> String.downcase()
Enum.member?(extension_whitelist(), file_extension)
end

def storage_dir(_, {_file, %Spotlight{} = spotlight}) do
"uploads/contest/spotlights/#{spotlight.id}"
end

def filename(version, _) do
version
end

def extension_whitelist do
@extension_whitelist
end
end

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule SafiraWeb.Backoffice.SpotlightLive.FormComponent do
use SafiraWeb, :live_component

alias Safira.Spotlights

import SafiraWeb.Components.Forms

@impl true
Expand All @@ -9,7 +11,11 @@ defmodule SafiraWeb.Backoffice.SpotlightLive.FormComponent do
<div>
<.page title={@title}>
<div class="w-full space-y-2">
<.field field={@form[:duration]} type="text" label="Duration" required />
<.simple_form for={@form} id="spotlight-form">
<div>
<.field field={@form[:duration]} type="text" label="Duration" required />
</div>
</.simple_form>
</div>
</.page>
</div>
Expand Down

0 comments on commit ddf3adc

Please sign in to comment.