Skip to content

Commit

Permalink
feat: Showing button to purchase or enter depending if user has paid …
Browse files Browse the repository at this point in the history
…or not. #1
  • Loading branch information
LuchoTurtle committed Dec 26, 2022
1 parent 0bfea37 commit fca1a42
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
6 changes: 6 additions & 0 deletions lib/app_web/controllers/page_html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@ defmodule AppWeb.PageHTML do
use AppWeb, :html

embed_templates "page_html/*"

def check_user_has_paid(person_id) do
user = UsersTable.fetch_user(person_id)

if user == nil, do: false, else: user.status
end
end
24 changes: 17 additions & 7 deletions lib/app_web/controllers/page_html/home.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,23 @@
<div class="w-full sm:w-auto">

<button class="relative inline-flex items-center justify-center p-0.5 mb-2 mr-2 overflow-hidden text-sm font-medium text-gray-900 rounded-lg group bg-gradient-to-br from-purple-600 to-blue-500 group-hover:from-purple-600 group-hover:to-blue-500 hover:text-white dark:text-white focus:ring-4 focus:outline-none focus:ring-blue-300 dark:focus:ring-blue-800">
<.link
href={~p"/purchase/checkout-session"}
method="post"
class="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0"
>
Purchase
</.link>
<%= if check_user_has_paid(@conn.assigns.person.id) do %>
<.link
href={~p"/dashboard"}
class="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0"
>
Enter
</.link>
<% else %>
<.link
href={~p"/purchase/checkout-session"}
method="post"
class="relative px-5 py-2.5 transition-all ease-in duration-75 bg-white dark:bg-gray-900 rounded-md group-hover:bg-opacity-0"
>
Purchase
</.link>
<% end %>

</button>
<.link
navigate={~p"/logout"}
Expand Down

0 comments on commit fca1a42

Please sign in to comment.