Skip to content

Commit

Permalink
Merge pull request #2018 from brave-intl/staging
Browse files Browse the repository at this point in the history
Release 2019-07-01
  • Loading branch information
yachtcaptain23 authored Jul 2, 2019
2 parents 03cb320 + de7d77d commit 9db97ae
Show file tree
Hide file tree
Showing 48 changed files with 431 additions and 878 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/admin/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/* Position tooltip above the element */
[data-tooltip]:before {
position: absolute;
bottom: 150%;
bottom: 100%;
left: 50%;
margin-bottom: 5px;
margin-left: -80px;
Expand All @@ -36,7 +36,7 @@
/* Triangle hack to make tooltip look like a speech bubble */
[data-tooltip]:after {
position: absolute;
bottom: 150%;
bottom: 100%;
left: 50%;
margin-left: -5px;
width: 0;
Expand Down
5 changes: 1 addition & 4 deletions app/assets/stylesheets/pages/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,14 @@
}

&-alert {
width: 60%;

#promo-panel-alert {
font-size: 14px;
font-weight: 600;
color: #006192;
padding: 30px 30px 35px 70px;
margin-right: 20px;
background-color: white;
background-color: rgba(255, 255, 255, 0.6);
text-align: left;
opacity: 0.5;
border-radius: 10px;
background-image: url(asset-path("icn-info.png"));
background-position: center left 15px;
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/admin/promo_registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Admin::PromoRegistrationsController < AdminController
def for_referral_code
publisher = Publisher.find(params[:publisher_id])
promo_registration = publisher.promo_registrations.find_by(referral_code: params[:referral_code])
render :unauthorized and return if promo_registration.nil?
render json: promo_registration.stats_by_date.to_json
end
end
5 changes: 5 additions & 0 deletions app/controllers/admin/publishers/referrals_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Admin::Publishers::ReferralsController < Admin::PublishersController
def show
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Referrals" }).to_json
end
end
1 change: 1 addition & 0 deletions app/controllers/admin/publishers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def show
@publisher = Publisher.find(params[:id])
@navigation_view = Views::Admin::NavigationView.new(@publisher).as_json.merge({ navbarSelection: "Dashboard" }).to_json
@potential_referral_payment = @publisher.most_recent_potential_referral_payment
@referral_owner_status = Promo::Client.new.owner_state.find(id: params[:id])
@current_user = current_user
end

Expand Down
44 changes: 0 additions & 44 deletions app/controllers/admin/referrals_controller.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/controllers/promo_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def create

if @publisher_has_verified_channel
if @publisher.channels.where(verified: true).count > 5
RegisterPublisherForPromoJob.perform_later(publisher: @publisher)
Promo::RegisterPublisherForPromoJob.perform_later(publisher: @publisher)
redirect_to home_publishers_path, notice: t("promo.activated.please_wait")
else
Promo::PublisherChannelsRegistrar.new(publisher: @publisher).perform
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/publishers/promo_registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Publishers::PromoRegistrationsController < PublishersController
def for_referral_code
promo_registration = current_publisher.promo_registrations.find_by(referral_code: params[:referral_code])
promo_registration = current_publisher.admin? ?
PromoRegistration.find_by(referral_code: params[:referral_code]) :
current_publisher.promo_registrations.find_by(referral_code: params[:referral_code])
render :unauthorized and return if promo_registration.nil?
render json: promo_registration.stats_by_date.to_json
end
Expand Down
21 changes: 17 additions & 4 deletions app/helpers/publishers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ def publisher_overall_bat_balance(publisher)
balance = I18n.t("helpers.publisher.balance_unavailable")
sentry_catcher do
publisher = publisher.become_subclass
amount = publisher.wallet&.overall_balance&.amount_bat
amount = publisher.balance if publisher.partner?

if publisher.partner?
amount = publisher.balance
elsif publisher.only_user_funds?
amount = publisher.wallet&.contribution_balance&.amount_bat
else
amount = publisher.wallet&.overall_balance&.amount_bat
end

balance = '%.2f' % amount if amount.present?
end

Expand All @@ -51,8 +58,14 @@ def publisher_converted_overall_balance(publisher)
return if publisher.default_currency == "BAT" || publisher.default_currency.blank?

publisher = publisher&.become_subclass
balance = publisher.wallet&.overall_balance&.amount_default_currency
balance = publisher.balance_in_currency if publisher.partner?

if publisher.partner?
balance = publisher.balance_in_currency
elsif publisher.only_user_funds?
balance = publisher.wallet&.contribution_balance&.amount_default_currency
else
balance = publisher.wallet&.overall_balance&.amount_default_currency
end

if balance.present?
I18n.t("helpers.publisher.balance_pending_approximate",
Expand Down
21 changes: 5 additions & 16 deletions app/javascript/packs/chart/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from "react";
import moment from "moment";
import Chart from "chart.js";

class ReactChart extends React.Component {
export default class ReactChart extends React.Component {
constructor(props) {
super(props);
this.chartRef = React.createRef();
Expand Down Expand Up @@ -40,10 +40,7 @@ class ReactChart extends React.Component {
});
} else {
this.chart.data = this.getData(this.props.data);
this.chart.options = this.getOptions(
this.props.title,
this.getSuggestedMax(this.props.data)
);
this.chart.options = this.getOptions(this.props.title, this.getSuggestedMax(this.props.data));
this.chart.update();
}
}
Expand Down Expand Up @@ -128,10 +125,8 @@ class ReactChart extends React.Component {
var currentMax = 0;
Object.keys(data).forEach(function(key) {
var value = data[key];
currentMax =
value.retrievals > currentMax ? value.retrievals : currentMax;
currentMax =
value.first_runs > currentMax ? value.first_runs : currentMax;
currentMax = value.retrievals > currentMax ? value.retrievals : currentMax;
currentMax = value.first_runs > currentMax ? value.first_runs : currentMax;
currentMax = value.finalized > currentMax ? value.finalized : currentMax;
});
return Math.ceil((currentMax / 95) * 100);
Expand All @@ -154,12 +149,6 @@ class ReactChart extends React.Component {
}

render() {
return (
<div>
{this.props.data && <canvas id="chart-canvas" ref={this.chartRef} />}
</div>
);
return <div>{this.props.data && <canvas id="chart-canvas" ref={this.chartRef} />}</div>;
}
}

export default ReactChart;
19 changes: 10 additions & 9 deletions app/javascript/packs/referral_charts.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import "babel-polyfill";
import styled from "brave-ui/theme";
import Select from "brave-ui/components/formControls/select";
import ControlWrapper from "brave-ui/components/formControls/controlWrapper";
import { PrimaryButton } from "../publishers/ReferralChartsStyle";
// import "../publishers/dashboard_chart";
import routes from "../views/routes";
import Chart from "./chart/Chart";
import ReactChart from "./chart/Chart";
import { ThemeProvider } from "brave-ui/theme";
import Theme from "brave-ui/theme/brave-default";

Expand All @@ -27,10 +26,11 @@ export default class ReferralCharts extends React.Component {

async viewReferralCodeStats() {
const node = this.selectMenuRef.current;
var url = routes.publishers.promo_registrations.show.path.replace(
"{id}",
this.props.publisherId
);
var url =
this.props.scope === "admin"
? routes.admin.promo_registrations.show.path.replace("{publisher_id}", this.props.publisherId)
: routes.publishers.promo_registrations.show.path.replace("{id}", this.props.publisherId);

url = url.replace("{referral_code}", node.state.value);
const result = await fetch(url, {
headers: {
Expand Down Expand Up @@ -71,21 +71,22 @@ export default class ReferralCharts extends React.Component {
View stats
</PrimaryButton>
</div>
<Chart data={this.state.data} title={this.state.title} />
<ReactChart data={this.state.data} title={this.state.title} />
</React.Fragment>
);
}
}

export function renderReferralCharts() {
export function renderReferralCharts(scope) {
const { value } = document.getElementById("referrals-hidden-tags");
const publisherId = document.getElementById("publisher_id").value;
if (value === undefined) {
return;
}
let referralCodes = JSON.parse(value);
let props = {
referralCodes: referralCodes
referralCodes: referralCodes,
scope: scope
};
ReactDOM.render(
<ReferralCharts {...props} publisherId={publisherId} />,
Expand Down
11 changes: 2 additions & 9 deletions app/javascript/packs/views/admin/referrals/Referrals.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
import * as React from "react";
import * as ReactDOM from "react-dom";
import Referrals from "../../../../views/admin/referrals/Referrals";
import { renderReferralCharts } from "../../../../packs/referral_charts";

document.addEventListener("DOMContentLoaded", () => {
const node = document.getElementById("referrals_data");
const data = JSON.parse(node.getAttribute("data"));
ReactDOM.render(
<Referrals data={data} />,
document
.getElementById("main-content")
.appendChild(document.createElement("div"))
);
renderReferralCharts("admin");
});
7 changes: 1 addition & 6 deletions app/javascript/packs/views/referrals/Referrals.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@ import * as ReactDOM from "react-dom";
import Referrals from "../../../views/referrals/Referrals";

document.addEventListener("DOMContentLoaded", () => {
ReactDOM.render(
<Referrals />,
document.body.appendChild(
document.getElementsByClassName("main-content")[0]
)
);
ReactDOM.render(<Referrals />, document.body.appendChild(document.getElementsByClassName("main-content")[0]));
});
91 changes: 0 additions & 91 deletions app/javascript/publishers/dashboard_chart.js

This file was deleted.

Loading

0 comments on commit 9db97ae

Please sign in to comment.