Skip to content

Commit

Permalink
Merge branch 'main' into jl/landing
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiaslobo committed Dec 23, 2024
2 parents b55aefa + 77e4d4e commit 6f1a345
Show file tree
Hide file tree
Showing 25 changed files with 829 additions and 194 deletions.
1 change: 1 addition & 0 deletions assets/css/components.css
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@import "components/avatar.css";
@import "components/field.css";
27 changes: 27 additions & 0 deletions assets/css/components/avatar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* Avatar */

.safira-avatar {
@apply font-medium leading-none flex shrink-0 items-center justify-center select-none;
}

/* Avatar - sizes */

.safira-avatar--xs {
@apply h-8 w-8 text-xs;
}

.safira-avatar--sm {
@apply h-12 w-12 text-lg;
}

.safira-avatar--md {
@apply h-16 w-16 text-lg;
}

.safira-avatar--lg {
@apply h-20 w-20 text-4xl;
}

.safira-avatar--xl {
@apply h-24 w-24 text-4xl;
}
57 changes: 57 additions & 0 deletions lib/safira/accounts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,27 @@ defmodule Safira.Accounts do
|> Repo.update()
end

@doc """
Links a credential to an attendee.
## Examples
iex> link_credential(credential_id, attendee_id)
{:ok, %Credential{}}
iex> link_credential(credential_id, attendee_id)
{:error, %Ecto.Changeset{}}
"""
def link_credential(credential_id, attendee_id) do
credential = get_credential!(credential_id)
attendee = get_attendee!(attendee_id)

credential
|> Credential.changeset(%{attendee_id: attendee.id})
|> Repo.update()
end

@doc """
Deletes a credential.
Expand Down Expand Up @@ -614,6 +635,42 @@ defmodule Safira.Accounts do
Credential.changeset(credential, attrs)
end

@doc """
Checks if a credential exists.
## Examples
iex> credential_exists?(123)
true
iex> credential_exists?(456)
false
"""
def credential_exists?(id) do
Credential
|> where([c], c.id == ^id)
|> Repo.exists?()
end

@doc """
Checks if a credential is linked to an attendee.
## Examples
iex> credential_linked?(credential_id)
true
iex> credential_linked?(credential_id)
false
"""
def credential_linked?(credential_id) do
credential = get_credential!(credential_id)

credential.attendee_id != nil
end

@doc """
Gets a single credential associated to the given attendee.
Expand Down
4 changes: 3 additions & 1 deletion lib/safira_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ defmodule SafiraWeb do
use Phoenix.LiveView,
layout: {SafiraWeb.Layouts, :app}

import SafiraWeb.Components.Avatar
import SafiraWeb.Components.Button

unquote(html_helpers())
Expand All @@ -74,6 +75,7 @@ defmodule SafiraWeb do
use Phoenix.LiveView,
layout: {SafiraWeb.Layouts, :backoffice}

import SafiraWeb.Components.Avatar
import SafiraWeb.Components.EnsurePermissions
import SafiraWeb.BackofficeHelpers

Expand All @@ -91,7 +93,7 @@ defmodule SafiraWeb do
def live_component do
quote do
use Phoenix.LiveComponent

import SafiraWeb.Components.Avatar
unquote(html_helpers())
end
end
Expand Down
Loading

0 comments on commit 6f1a345

Please sign in to comment.