Skip to content

Commit

Permalink
Count usage charges as recurring option
Browse files Browse the repository at this point in the history
  • Loading branch information
forsbergplustwo committed Sep 13, 2023
1 parent cfb7ed1 commit d9f9539
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 24 deletions.
10 changes: 7 additions & 3 deletions app/controllers/imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def new

def create
@import = current_user.imports.new(source: Import.sources[:csv_file], **import_params)

if @import.save!
@import.user.count_usage_charges_as_recurring = import_params.dig(:user_attributes, :count_usage_charges_as_recurring)
if @import.save
redirect_to @import, notice: "Import successfully created."
else
flash.now[:alert] = "Import failed to create."
Expand All @@ -37,7 +37,11 @@ def set_import
end

def import_params
params.require(:import).permit(:import_type, :payouts_file)
params.require(:import).permit(
:import_type,
:payouts_file,
user_attributes: [:count_usage_charges_as_recurring]
)
end

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

def update
if @partner_api_credential.update(partner_api_credential_params)
redirect_to @partner_api_credential, notice: "Partner api credential was successfully updated.", status: :see_other
redirect_to edit_partner_api_credential_path(@partner_api_credential), notice: "Partner api credential was successfully updated.", status: :see_other
else
render :edit, status: :unprocessable_entity
end
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/users/usage_charge_preferences_controller.rb

This file was deleted.

15 changes: 13 additions & 2 deletions app/javascript/libraries/dirty-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class DirtyForm {

setupFieldsTracking() {
this.fields.forEach(field => {
this.initialValues[field.name] = field.value
// If input save value, if checkbox save checked
if (field.type == 'checkbox') {
this.initialValues[field.name] = field.checked
} else {
this.initialValues[field.name] = field.value
}

switch (field.tagName) {
case 'TRIX-EDITOR':
Expand Down Expand Up @@ -91,7 +96,13 @@ class DirtyForm {

valueChanged = (event) => {
const field = event.target
if (this.initialValues[field.name] != field.value) {
let value
if (field.type == 'checkbox') {
value = field.checked
} else {
value = field.value
}
if (this.initialValues[field.name] != value) {
this.markAsDirty()
}
}
Expand Down
6 changes: 4 additions & 2 deletions app/models/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Import < ApplicationRecord
has_one_attached :payouts_file, dependent: :destroy
has_one :partner_api_credential, through: :user

accepts_nested_attributes_for :user, update_only: true

ACCEPTED_FILE_TYPES = %w[text/csv application/zip].freeze

enum source: {
Expand Down Expand Up @@ -74,8 +76,8 @@ def broadcast_status_update
broadcast_replace_to(
[user, :imports],
target: dom_id(self, :status),
partial: "imports/status",
locals: {import: self}
partial: "shared/status",
locals: {resource: self}
)
end
end
8 changes: 0 additions & 8 deletions app/views/home/import.js.erb

This file was deleted.

1 change: 0 additions & 1 deletion app/views/home/reset_metrics.js.erb

This file was deleted.

6 changes: 6 additions & 0 deletions app/views/imports/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@
multiple: false,
) %>
<% end %>

<%= form_layout.with_item do %>
<%= polaris_text(variant: :bodySm, color: :subdued) { t(".payouts_file_help_text") } %>
<% end %>

<%= form_layout.with_item do %>
<%= render "users/count_usage_charges_as_recurring_fields", form: form %>
<% end %>


<%= form_layout.with_item do %>
<%= polaris_button(
submit: true,
Expand Down
6 changes: 5 additions & 1 deletion app/views/partner_api_credentials/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@
<% end %>

<% form_layout.with_item do %>
<%= form.polaris_text_field :access_token, label: t(".access_token"), type: :password, required: true %>
<%= form.polaris_text_field :access_token, value: partner_api_credential.access_token, label: t(".access_token"), type: :password, required: true %>
<% end %>

<%= form_layout.with_item do %>
<%= render "users/count_usage_charges_as_recurring_fields", form: form %>
<% end %>

<%= form_layout.with_item do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form.fields_for current_user do |user_fields| %>
<%= user_fields.polaris_check_box :count_usage_charges_as_recurring,
label: t('user.count_usage_charges_as_recurring'),
help_text: t('user.count_usage_charges_as_recurring_help_text')
%>
<% end %>
2 changes: 1 addition & 1 deletion config/credentials.yml.enc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
XL60N/R5cI7fYEzAjH4H9WHEEw5zd4XBvOmwJXmUKH2x5/4Npf4Q+LN5mRHr6zE6EqHAl6T/brKvWmNxVdp9e9H/jhNsgssfjjeVPUDbHcEgX6GMiYnX+jve18Az/eEGLSxwAmdiZ86y2UzfWa3CB0ZL/b5SKqt9CqpyMAsBcgwHHF9OO3PgnnZsgMdvUyRyCgsQnHzx4q2ppszj/0P3iZyjHzJUWjs7Xvk3NFPWD5jfyo1sn9lY6Ro0TvfAqJ8Qi5Rla4N7kbrxttQjTOaJQf0cb49rGMgDW4YxjcJv4vn5d2Q24ph31fKwY6+0MAuaDRLcYYAphZDUIqB7xHxSeCDAK+m6QrEDpceNeT0C42LdnVZe9s7kjOC2j27ESbx6/VaN4cG0hV3kv/3TJfxDdYOKdvFkgpcBcj9UPddY95ZVFYcgGfnJra0YmLA4dv/Hm0Tbp9uYS14y6jf8ivV5y9DslNamm74PBFGzxFfcDADnfUXBH5EeJrJOSQDuCSy2rWmeRBTKikjw336WdjQcEUfWqxsHR0qbZ2FB2HngeMDMz4QsxAqksOgJz2+kmVFu6J3BXzYJr3MeC/YJK0eattMTOJgJhAtiC0iVfsNLguxfCLRBYixy9QTHfxzPm0q+XJkeszWQnS+ul9mp19arfsSgyoc33cjT9WJbFZlX3uJvDxswNjVJMLypkPhLVX0Y0BY3zTCmpdNLbkNlQFqR8UTnri6tuygd91032KmybUi0SrDxmfvIn8qyU70f1mPzFfF21gdQQ5dJEg3La5viR4icdLIMl/w0ox7EuZAXWOSUep13TTuOp+oTBQfuvlY4QUhxNew3FQFuXYYvKtD9BIsuGnEjzOShY9wzr2N7uRnDkNS0EQlZgYNOTPGoyzSIxjly73tQ1Z70jmLf9rO/p7ZlAQANifcNM0GR3e8VjNvZ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zuGf8EgwKdwDt6Qo1phL2CrKSxKlgt7AzelbFgYxqbQdEhX1wp2URb2rkV8YYuUSuhcF7sdHVkbQaT/f/x0Co/SH3v+y0TWjF2x4h9Zy9rLdgeQ9zo9fXpT3LZjX4J4lMcpLpF3y1xyQk7qV11Mr8Y1ILHGRDAZ3S53Gw0FAAYtLMAZvL6QEWGjqdKA==--LLrijQWggZIixUnb--b5k/IfLJFg7ok6kWb7S0Xg==
3 changes: 3 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ en:
title: "No %{resource} yet"
description: "Import your payouts data to get started."
footer_html: If you don’t want to upload historical data, connect your %{url} data source.
user:
count_usage_charges_as_recurring: "Count usage charges as recurring revenue"
count_usage_charges_as_recurring_help_text: "Usage charges are counted as one-time revenue by default."
devise:
sign_in: "Log in"
sign_out: "Log out"
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20230911110717_create_partner_api_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CreatePartnerApiCredentials < ActiveRecord::Migration[7.0]
def change
create_table :partner_api_credentials do |t|
t.references :user, null: false, foreign_key: true, index: {unique: true}
t.string :access_token, null: false
t.integer :organization_id, null: false
t.string :access_token, null: false, length: 510
t.string :organization_id, null: false, length: 510
t.string :status, null: false
t.text :status_message

Expand Down
2 changes: 1 addition & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d9f9539

Please sign in to comment.