-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
540 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
defmodule Core.Helpdesk do | ||
@moduledoc """ | ||
The Helpdesk context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Core.Repo | ||
|
||
alias Core.Helpdesk.Ticket | ||
|
||
def list_open_tickets do | ||
from(t in Ticket, | ||
where: is_nil(t.completed_at), | ||
order_by: {:asc, :inserted_at}, | ||
preload: :user | ||
) | ||
|> Repo.all() | ||
end | ||
|
||
def close_ticket_by_id(id) do | ||
from(t in Ticket, where: t.id == ^id) | ||
|> Repo.update_all(set: [completed_at: DateTime.utc_now()]) | ||
end | ||
|
||
def create_ticket(user, attrs \\ %{}) do | ||
%Ticket{} | ||
|> Ticket.changeset(attrs) | ||
|> Ecto.Changeset.put_assoc(:user, user) | ||
|> Repo.insert() | ||
end | ||
|
||
def new_ticket_changeset(attrs \\ %{}) do | ||
Ticket.changeset(%Ticket{}, attrs) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule Core.Helpdesk.Ticket do | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
alias Core.Accounts.User | ||
|
||
schema "helpdesk_tickets" do | ||
belongs_to(:user, User) | ||
field(:description, :string) | ||
field(:title, :string) | ||
field(:completed_at, :utc_datetime) | ||
|
||
timestamps() | ||
end | ||
|
||
@doc false | ||
def changeset(ticket, attrs) do | ||
ticket | ||
|> cast(attrs, [:title, :description, :completed_at]) | ||
|> validate_required([:title, :description]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule CoreWeb.Admin.SupportTickets do | ||
use CoreWeb, :live_view | ||
alias Core.Helpdesk | ||
|
||
data(tickets, :any) | ||
|
||
def mount(_params, _session, socket) do | ||
{ | ||
:ok, | ||
socket |> assign(:tickets, Helpdesk.list_open_tickets()) | ||
} | ||
end | ||
|
||
def handle_event("close_ticket", %{"id" => id}, socket) do | ||
Helpdesk.close_ticket_by_id(id) | ||
{:noreply, socket |> assign(:tickets, Helpdesk.list_open_tickets())} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div> | ||
Admin | ||
<div :for={{ticket <- @tickets}}> | ||
<h1>{{ticket.title}}</h1> | ||
<p>{{ticket.description}}</p> | ||
<p> | ||
<a href="mailto:{{ticket.user.email}}">Contact {{ticket.user.email}}</a> | ||
</p> | ||
<button :on-click="close_ticket" phx-value-id={{ticket.id}}>Close ticket</button> | ||
</div> | ||
</div> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
defmodule CoreWeb.Support do | ||
use CoreWeb, :live_view | ||
use CoreWeb.Layouts.Workspace.Component, :support | ||
|
||
alias Surface.Components.Form | ||
alias EyraUI.Text.{Title3, BodyLarge} | ||
alias EyraUI.Spacing | ||
alias CoreWeb.Layouts.Workspace.Component, as: Workspace | ||
alias EyraUI.Form.{TextArea, TextInput} | ||
alias EyraUI.Text.{Title3} | ||
alias EyraUI.Button.SubmitButton | ||
alias Core.Helpdesk | ||
|
||
data(focus, :any, default: nil) | ||
data(data, :any, default: {}) | ||
|
||
def mount(_params, _session, socket) do | ||
{:ok, | ||
socket | ||
|> assign(:changeset, Helpdesk.new_ticket_changeset()) | ||
|> update_menus()} | ||
end | ||
|
||
def handle_event( | ||
"create_ticket", | ||
%{"ticket" => data}, | ||
%{assigns: %{current_user: user}} = socket | ||
) do | ||
case Helpdesk.create_ticket(user, data) do | ||
{:ok, _} -> | ||
{:noreply, | ||
socket | ||
|> put_flash(:info, dgettext("eyra-support", "ticket_created.info.flash")) | ||
|> push_redirect(to: Routes.live_path(socket, CoreWeb.Marketplace))} | ||
|
||
{:error, changeset} -> | ||
{:noreply, assign(socket, :changeset, changeset)} | ||
end | ||
end | ||
|
||
def handle_event("focus", %{"field" => field}, socket) do | ||
{:noreply, assign(socket, :focus, field)} | ||
end | ||
|
||
def handle_event("store_state", %{"ticket" => ticket}, socket) do | ||
{:noreply, assign(socket, :changeset, Helpdesk.new_ticket_changeset(ticket))} | ||
end | ||
|
||
def render(assigns) do | ||
~H""" | ||
<Workspace | ||
title={{ dgettext("eyra-support", "title") }} | ||
menus={{ @menus }} | ||
> | ||
<ContentArea> | ||
<Title3>{{dgettext("eyra-support", "form.title")}}</Title3> | ||
<BodyLarge>{{dgettext("eyra-support", "form.description")}} </BodyLarge> | ||
<Spacing value="S" /> | ||
<div x-data="{ focus: '{{@focus}}' }"> | ||
<Form for={{@changeset}} submit="create_ticket" change="store_state"> | ||
<TextInput field={{:title}} label_text={{dgettext("eyra-support", "ticket.title.label")}} /> | ||
<Spacing value="S" /> | ||
<TextArea field={{:description}} label_text={{dgettext("eyra-support", "ticket.description.label")}} /> | ||
<SubmitButton label={{ dgettext("eyra-support", "create_ticket.button") }} /> | ||
</Form> | ||
</div> | ||
</ContentArea> | ||
</Workspace> | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## "msgid"s in this file come from POT (.pot) files. | ||
## | ||
## Do not add, change, or remove "msgid"s manually here as | ||
## they're tied to the ones in the corresponding POT file | ||
## (with the same domain). | ||
## | ||
## Use "mix gettext.extract --merge" or "mix gettext.merge" | ||
## to merge POT files into PO files. | ||
msgid "" | ||
msgstr "" | ||
"Language: en\n" | ||
"Plural-Forms: nplurals=2\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## "msgid"s in this file come from POT (.pot) files. | ||
## | ||
## Do not add, change, or remove "msgid"s manually here as | ||
## they're tied to the ones in the corresponding POT file | ||
## (with the same domain). | ||
## | ||
## Use "mix gettext.extract --merge" or "mix gettext.merge" | ||
## to merge POT files into PO files. | ||
msgid "" | ||
msgstr "" | ||
"Language: en\n" | ||
"Plural-Forms: nplurals=2\n" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:64 | ||
msgid "form.description" | ||
msgstr "Fill out the form to create a support ticket. We will get back to you via email." | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:63 | ||
msgid "form.title" | ||
msgstr "Create Support Ticket" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:70 | ||
msgid "ticket.description.label" | ||
msgstr "Description of your support request" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:68 | ||
msgid "ticket.title.label" | ||
msgstr "Short title for your support request" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:58 | ||
msgid "title" | ||
msgstr "Support" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:72 | ||
msgid "create_ticket.button" | ||
msgstr "Submit" | ||
|
||
#, elixir-format | ||
#: lib/core_web/live/support.ex:39 | ||
msgid "ticket_created.info.flash" | ||
msgstr "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## This file is a PO Template file. | ||
## | ||
## "msgid"s here are often extracted from source code. | ||
## Add new translations manually only if they're dynamic | ||
## translations that can't be statically extracted. | ||
## | ||
## Run "mix gettext.extract" to bring this file up to | ||
## date. Leave "msgstr"s empty as changing them here as no | ||
## effect: edit them in PO (.po) files instead. | ||
msgid "" | ||
msgstr "" |
Oops, something went wrong.