Skip to content

Commit c1f6040

Browse files
authored
Gem refer (#264)
* gem "refer" * Update en.yml * Create pay_charge_extensions.rb * omfg fix pay * Create index.html.erb * test * clipboard component https://www.stimulus-components.com/docs/stimulus-clipboard
1 parent 6b0ef9d commit c1f6040

27 files changed

Lines changed: 233 additions & 22 deletions

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ gem "ransack", "~> 4.2"
9797
gem "pay", "~> 8.0"
9898
gem "stripe", "~> 13.0"
9999
gem "profitable"
100+
101+
# business logic
102+
gem "refer"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ GEM
401401
rdoc (6.14.0)
402402
erb
403403
psych (>= 4.0.0)
404+
refer (1.0.2)
405+
rails (>= 7.1.0)
404406
regexp_parser (2.10.0)
405407
reline (0.6.1)
406408
io-console (~> 0.5)
@@ -572,6 +574,7 @@ DEPENDENCIES
572574
pundit (~> 2.3)
573575
rails (~> 8.0.1)
574576
ransack (~> 4.2)
577+
refer
575578
rubocop-rails-omakase
576579
selenium-webdriver
577580
simplecov (~> 0.22.0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
2+
<% @metrics.each do |metric| %>
3+
<div class="du-card du-bg-base-100 du-shadow-xl border">
4+
<div class="du-card-body space-y-2">
5+
<h2 class="du-card-title text-base-content/70 text-sm uppercase tracking-wider"><%= metric[:title] %></h2>
6+
<p class="text-4xl font-bold text-primary">
7+
<% if metric[:type] == :money %>
8+
<%= number_to_currency(metric[:value].to_f/100) %>
9+
<% elsif metric[:type] == :number %>
10+
<%= number_with_delimiter(metric[:value]) %>
11+
<% end %>
12+
</p>
13+
<p class="text-sm text-base-content/60"><%= metric[:subtitle] %></p>
14+
</div>
15+
</div>
16+
<% end %>
17+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class MetricsGridComponent < ViewComponent::Base
2+
def initialize(metrics:)
3+
@metrics = metrics
4+
end
5+
end

app/components/page_component.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
</div>
99
</div>
1010

11+
<% if subtitle %>
12+
<p class="text-sm text-base-content/60">
13+
<%= subtitle %>
14+
</p>
15+
<% end %>
16+
1117
<div class="space-y-4">
1218
<%= content %>
1319
</div>

app/components/page_component.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
class PageComponent < ViewComponent::Base
22
renders_one :action_list
33

4-
def initialize(title:, full_width: false)
4+
def initialize(title:, full_width: false, subtitle: nil)
55
@title = title
66
@full_width = full_width
7+
@subtitle = subtitle
78
end
89

9-
attr_reader :title
10+
attr_reader :title, :subtitle
1011

1112
def width_class
1213
if @full_width == true

app/controllers/application_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base
55
before_action :authenticate_user!
66
before_action :set_current_organizations, if: :user_signed_in?
77

8+
set_referral_cookie
9+
810
def after_sign_in_path_for(resource)
911
stored_location_for(resource) || organizations_path
1012
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Users::ReferralsController < ApplicationController
2+
def index
3+
@referral_code = current_user.referral_codes.first_or_create
4+
@metrics = [
5+
{ title: t("users.referrals.index.clicks"), subtitle: t("users.referrals.index.clicks_description"), value: @referral_code.visits_count, type: :number },
6+
{ title: t("users.referrals.index.referrals"), subtitle: t("users.referrals.index.referrals_description"), value: @referral_code.referrals.count, type: :number },
7+
{ title: t("users.referrals.index.completed"), subtitle: t("users.referrals.index.completed_description"), value: @referral_code.referrals.completed.count, type: :number }
8+
]
9+
end
10+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
class Users::RegistrationsController < Devise::RegistrationsController
22
rate_limit to: 50, within: 3.minutes, only: :create, with: -> { redirect_to new_user_registration_url, alert: t("shared.errors.rate_limit") }
3+
4+
def create
5+
super do
6+
refer resource if resource.persisted?
7+
end
8+
end
39
end

app/javascript/controllers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { application } from "controllers/application"
66
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
77
eagerLoadControllersFrom("controllers", application)
88

9+
import Clipboard from "@stimulus-components/clipboard"
10+
application.register("clipboard", Clipboard)
911
// Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
1012
// import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
1113
// lazyLoadControllersFrom("controllers", application)

0 commit comments

Comments
 (0)