-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplified Employer Search #17
Changes from 3 commits
906abf0
c2901ac
ab5c530
90d17e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ def entry | |
|
||
def employer_search | ||
@argyle_user_token = fetch_and_store_argyle_token | ||
@companies = fetch_employers | ||
@query = search_params[:query] | ||
@employers = @query.blank? ? [] : fetch_employers(@query) | ||
end | ||
|
||
def summary | ||
|
@@ -71,8 +72,8 @@ def fetch_and_store_argyle_token | |
parsed['user_token'] | ||
end | ||
|
||
def fetch_employers | ||
res = Net::HTTP.get(URI.parse(ITEMS_ENDPOINT), {"Authorization" => "Basic #{Rails.application.credentials.argyle[:api_key]}"}) | ||
def fetch_employers(query = '') | ||
res = Net::HTTP.get(URI.parse("#{ITEMS_ENDPOINT}?mapping_status=verified,mapped&q=#{query}"), {"Authorization" => "Basic #{Rails.application.credentials.argyle[:api_key]}"}) | ||
allthesignals marked this conversation as resolved.
Show resolved
Hide resolved
|
||
parsed = JSON.parse(res) | ||
|
||
parsed['results'] | ||
|
@@ -84,4 +85,8 @@ def fetch_payroll | |
|
||
parsed['results'] | ||
end | ||
|
||
def search_params | ||
params.permit(:query) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You didn't actually have to do this since the params aren't being passed into an ActiveRecord model, and you're extracting exactly the param key you want, but I guess it never hurts! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tdooner oooh! I never know when to use |
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import loadScript from 'load-script'; | ||
import metaContent from "./meta"; | ||
import CSRF from './csrf'; | ||
|
||
const ARGYLE_TOKENS_REFRESH = '/api/argyle/tokens'; | ||
|
||
|
@@ -24,7 +25,12 @@ export function initializeArgyle(Argyle, userToken, callbacks) { | |
} | ||
|
||
export const updateToken = async updateToken => { | ||
const response = await fetch(ARGYLE_TOKENS_REFRESH, { method: 'post' }).then(response => response.json()); | ||
const response = await fetch(ARGYLE_TOKENS_REFRESH, { | ||
method: 'post', | ||
headers: { | ||
'X-CSRF-Token': CSRF.token, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. Rails used to have a way to do this out-of-the-box, but I googled and it looks like it was deprecated in Rails 7. If we end up making a lot of these fetch requests, maybe there is some way we can abstract this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Login.gov (lol) has a pretty good library for this but it's not published. Could "crib" it instead |
||
}, | ||
}).then(response => response.json()); | ||
|
||
updateToken(response.token); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Borrowed from https://github.com/18F/identity-idp/blob/59bc8bb6c47402f386d9248bfad3c0803f68187e/app/javascript/packages/request/index.ts#L25-L59 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "borrowed", lol, make sure to give it back when you're done! |
||
export default class CSRF { | ||
static get token(): string | null { | ||
return this.#tokenMetaElement?.content || null; | ||
} | ||
|
||
static set token(value: string | null) { | ||
if (!value) { | ||
return; | ||
} | ||
|
||
if (this.#tokenMetaElement) { | ||
this.#tokenMetaElement.content = value; | ||
} | ||
|
||
this.#paramInputElements.forEach((input) => { | ||
input.value = value; | ||
}); | ||
} | ||
|
||
static get param(): string | undefined { | ||
return this.#paramMetaElement?.content; | ||
} | ||
|
||
static get #tokenMetaElement(): HTMLMetaElement | null { | ||
return document.querySelector('meta[name="csrf-token"]'); | ||
} | ||
|
||
static get #paramMetaElement(): HTMLMetaElement | null { | ||
return document.querySelector('meta[name="csrf-param"]'); | ||
} | ||
|
||
static get #paramInputElements(): NodeListOf<HTMLInputElement> { | ||
return document.querySelectorAll(`input[name="${this.param}"]`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%= turbo_frame_tag 'employers' do %> | ||
<div class="usa-card-group"> | ||
<% @employers.each do |employer| %> | ||
<div class="usa-card usa-card--flag usa-card--media-right flex-1"> | ||
<div class="usa-card__container"> | ||
<div class="usa-card__header"> | ||
<h2 class="usa-card__heading"><%= employer['name'] %></h2> | ||
</div> | ||
<div class="display-none usa-card__media usa-card__media--inset"> | ||
<div class="usa-card__img"> | ||
<img | ||
src="<%= employer['logo_url'] %>" | ||
alt="A placeholder image" | ||
/> | ||
</div> | ||
</div> | ||
<div class="usa-card__footer"> | ||
<button | ||
data-action="click->cbv-flows#select" | ||
data-item-id="<%= employer['id'] %>" | ||
class="usa-button usa-button--outline" | ||
type="button" | ||
> | ||
Select | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> | ||
<% end %> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒