-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1492: Check Sync Status On Reconnect (#243)
* Adds an interstitial synchronizations page * Periodically check account status * Update app/app/controllers/cbv/synchronizations_controller.rb Co-authored-by: Tom Dooner <[email protected]> * Show status * Show icons for updated statuses * Switch to grid * Indicator spin; remove old indicator css * Remove unused * Rearrange order * Fix spacing and responsive --------- Co-authored-by: Tom Dooner <[email protected]>
- Loading branch information
1 parent
85216de
commit b7d2915
Showing
18 changed files
with
206 additions
and
124 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,10 +1,26 @@ | ||
class PaystubsChannel < ApplicationCable::Channel | ||
periodically :check_pinwheel_account_synchrony, every: 5.seconds | ||
|
||
def subscribed | ||
cbv_flow = CbvFlow.find(connection.session[:cbv_flow_id]) | ||
stream_for cbv_flow | ||
@cbv_flow = CbvFlow.find(connection.session[:cbv_flow_id]) | ||
stream_for @cbv_flow | ||
end | ||
|
||
def unsubscribed | ||
# Any cleanup needed when channel is unsubscribed | ||
private | ||
|
||
def check_pinwheel_account_synchrony | ||
pinwheel_account = PinwheelAccount.find_by_pinwheel_account_id(params["account_id"]) | ||
|
||
if pinwheel_account.present? | ||
broadcast_to(@cbv_flow, { | ||
event: "cbv.status_update", | ||
account_id: pinwheel_account.pinwheel_account_id, | ||
employment: pinwheel_account.job_completed?("employment"), | ||
identity: pinwheel_account.job_completed?("identity"), | ||
paystubs: pinwheel_account.job_completed?("paystubs"), | ||
income: pinwheel_account.job_completed?("income"), | ||
has_fully_synced: pinwheel_account.has_fully_synced? | ||
}) | ||
end | ||
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,19 @@ | ||
class Cbv::SynchronizationsController < Cbv::BaseController | ||
helper_method :job_completed? | ||
|
||
def show | ||
account_id = params[:user][:account_id] | ||
|
||
@pinwheel_account = @cbv_flow.pinwheel_accounts.find_by(pinwheel_account_id: account_id) | ||
|
||
if @pinwheel_account && @pinwheel_account.has_fully_synced? | ||
redirect_to cbv_flow_payment_details_path(user: { account_id: @pinwheel_account.pinwheel_account_id }) | ||
end | ||
end | ||
|
||
private | ||
|
||
def job_completed?(job) | ||
@pinwheel_account.present? && @pinwheel_account.job_completed?(job) | ||
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
43 changes: 43 additions & 0 deletions
43
app/app/javascript/controllers/cbv/synchronizations_controller.js
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,43 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import * as ActionCable from '@rails/actioncable' | ||
|
||
export default class extends Controller { | ||
static targets = ["form", "userAccountId", "employmentJob", "identityJob", "paystubsJob", "incomeJob"]; | ||
|
||
cable = ActionCable.createConsumer(); | ||
|
||
updateIndicatorStatus(element, completed) { | ||
if (completed) { | ||
element.querySelector('.completed').classList.remove('display-none'); | ||
element.querySelector('.in-progress').classList.add('display-none'); | ||
} else { | ||
element.querySelector('.completed').classList.add('display-none'); | ||
element.querySelector('.in-progress').classList.remove('display-none'); | ||
} | ||
} | ||
|
||
connect() { | ||
this.cable.subscriptions.create({ channel: 'PaystubsChannel', account_id: this.userAccountIdTarget.value }, { | ||
connected: () => { | ||
console.log("Connected to the channel:", this); | ||
}, | ||
disconnected: () => { | ||
console.log("Disconnected"); | ||
}, | ||
received: (data) => { | ||
if (data.event === 'cbv.status_update') { | ||
if (data.has_fully_synced) { | ||
const accountId = data.account_id; | ||
this.userAccountIdTarget.value = accountId; | ||
this.formTarget.submit(); | ||
} | ||
|
||
this.updateIndicatorStatus(this.employmentJobTarget, data.employment); | ||
this.updateIndicatorStatus(this.identityJobTarget, data.identity); | ||
this.updateIndicatorStatus(this.paystubsJobTarget, data.paystubs); | ||
this.updateIndicatorStatus(this.incomeJobTarget, data.income); | ||
} | ||
} | ||
}); | ||
} | ||
} |
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,11 @@ | ||
<svg class="in-progress <%= completed ? "display-none" : "" %> usa-icon border-05 rotate border-base-light radius-pill padding-1 usa-icon--size-5" aria-hidden="true" focusable="false" role="img"> | ||
<use | ||
xlink:href="<%= asset_path("@uswds/uswds/dist/img/sprite.svg#autorenew") %>" | ||
></use> | ||
</svg> | ||
|
||
<svg class="completed <%= !completed ? "display-none" : "" %> usa-icon border-05 bg-primary text-white border-primary radius-pill padding-1 usa-icon--size-5" aria-hidden="true" focusable="false" role="img"> | ||
<use | ||
xlink:href="<%= asset_path("@uswds/uswds/dist/img/sprite.svg#check") %>" | ||
></use> | ||
</svg> |
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,46 @@ | ||
<% content_for :title, t(".header") %> | ||
<div data-controller="cbv-synchronizations"> | ||
<h1> | ||
<%= t(".header") %> | ||
</h1> | ||
<p class="usa-prose"> | ||
<%= t(".fetching_payroll_description") %> | ||
</p> | ||
<%= form_with url: next_path, method: :get, class: "display-none", data: { 'cbv-synchronizations-target': "form" } do |f| %> | ||
<input type="hidden" name="user[account_id]" value="<%= params[:user][:account_id] %>" data-cbv-synchronizations-target="userAccountId"> | ||
<% end %> | ||
<div | ||
class="grid-container" | ||
> | ||
<div class="grid-row"> | ||
<div | ||
class="tablet:grid-col-2 grid-col-fill" | ||
data-cbv-synchronizations-target="incomeJob" | ||
> | ||
<%= render partial: "cbv/synchronizations/indicator", locals: { completed: job_completed?("income") } %> | ||
<h4 class="margin-top-2px"><%= t(".jobs.income") %></h4> | ||
</div> | ||
<div | ||
class="tablet:grid-col-2 grid-col-fill" | ||
data-cbv-synchronizations-target="employmentJob" | ||
> | ||
<%= render partial: "cbv/synchronizations/indicator", locals: { completed: job_completed?("employment") } %> | ||
<h4 class="margin-top-2px"><%= t(".jobs.employment") %></h4> | ||
</div> | ||
<div | ||
class="tablet:grid-col-2 grid-col-fill" | ||
data-cbv-synchronizations-target="paystubsJob" | ||
> | ||
<%= render partial: "cbv/synchronizations/indicator", locals: { completed: job_completed?("paystubs") } %> | ||
<h4 class="margin-top-2px"><%= t(".jobs.paystubs") %></h4> | ||
</div> | ||
<div | ||
class="tablet:grid-col-2 grid-col-fill" | ||
data-cbv-synchronizations-target="identityJob" | ||
> | ||
<%= render partial: "cbv/synchronizations/indicator", locals: { completed: job_completed?("identity") } %> | ||
<h4 class="margin-top-2px"><%= t(".jobs.identity") %></h4> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.