Skip to content

Instantly share code, notes, and snippets.

@knewter
Forked from adamrobbie/gist:f821f3c95e4a3185c4c2
Last active January 11, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knewter/4b50ec39187affdedce7 to your computer and use it in GitHub Desktop.
Save knewter/4b50ec39187affdedce7 to your computer and use it in GitHub Desktop.
HRFlow discussion
My current understanding of the process..
- 1 upload excel
- 2 hrflow creates form collector and a set of participant flows
- 3 form collector sends emails to participants with a link to the appropriate HRFORM
- upon completion of the partiicpant form, HRForms uses the completionURL to let us know
- if they have a spouse (unsure from the weird payload how this is deteremined, marriage status etc), we should send an email to the spouse with another HRForm url
- JOSH: (we should get this from marriage status - I was checking for spouse email I think?)
- upon that completion we'll receive another post to our submitform endpoint and fetch the data again and send the event along to the participant flow.
- eventually we want the participant fsm to complete with a signed boolean, unsure when this is determined as from the code this is assumed to happen.
- JOSH: This happens when we get their data back at all at present, if there is no spouse. if there is a spouse, this happens when we get the spouse's data.
I get the rest of it though, upon completion post to GtGo etc...
1) Where is the appropriate place to send the spouse email.
- in the participant FSM or a new FSM for the spouse ( but i don’t think thats right)
- The participant FSM - it enters a different state if there's a spouse, but it's still the same flow.
- i'm guessing we can use the same HRForms access token for the spouse form as we did with the partiicpant form
- This is actually unlikely. There were issues with the spouse form not being 100% fleshed out when I departed, so this wasn't yet resolved. Basically we'd need a separate access token we get back after creating the spouse form.
- to generate the token for our app we need the id of the flow which is not accessible from within the participant FSM so maybe we add the flow id like we do with the parent flow
- yup we need the flow id.
- Or we do it in the controller with access to the spouse data after retrieving said data from HRForms.get_form_data/3
- Not the controller, imo.
- but if we do it in the controller how do we not sent it twice (use a different completionURL endpoint for the spouse form maybe?
2) Upon completion of the spouse form and HRForms posts to our completion webhook
I've included the relavant code below for reference and commenting purposes
```
# FIXME: Not committing this because presently we get name: nil for the spouse email form field
# spouse = data |> Enum.find(fn(field) -> field["name"] == "spouse" end)
# if(spouse) do
# HRFlows.Flow.handle_event(flow, {:receive_signature_and_spouse_information, %{signed: true, spouse: %{first_name: spouse["first"], last_name: spouse["last"]}})
# else
# HRFlows.Flow.handle_event(flow, {:receive_signature_and_spouse_information, %{signed: true, spouse: nil}})
# end
HRFlows.Flow.handle_event(flow, {:receive_signature_and_spouse_information, %{signed: true, spouse: nil}})
```
```
defmodule HRFlows.GenFlowTypes.GrantThornton.FormsCollection.ParticipantCollector do
require Logger
defmodule Participant do
defstruct [:first_name, :last_name, :email, :employer_name, :agreement_date, :due_date, :member_firm_name, :spouse, :signed, :spouse_signed]
end
defmodule Data do
defstruct participant: %Participant{}, token: nil, parent_flow_id: nil
end
use HRFlows.GenFlowTypes.FSM, initial_state: :waiting_for_token, initial_data: %Data{}
@twenty_minutes 20 * 60 * 1_000
defgstate waiting_for_token, timeout: @twenty_minutes do
defgevent receive_token(token), transitions_to: [:waiting_for_signature_and_spouse_information], data: data do
next_state(:waiting_for_signature_and_spouse_information, %Data{ data | token: token })
end
end
defgstate waiting_for_signature_and_spouse_information, timeout: @twenty_minutes do
defgevent receive_signature_and_spouse_information(%{signed: signed, spouse: spouse = %{first_name: _spouse_first_name, last_name: _spouse_last_name, email: _spouse_email}}), transitions_to: [:waiting_for_spouse_signature], data: data do
next_state(:waiting_for_spouse_signature, %Data{data | participant: %Participant{data.participant | spouse: spouse, signed: signed}})
end
defgevent receive_signature_and_spouse_information(%{signed: signed, spouse: nil}), transitions_to: [:complete], data: data do
{:ok, parent_flow} = HRFlows.Store.get(HRFlows.Flow, data.parent_flow_id)
data = %Data{data | participant: %Participant{data.participant | signed: signed}}
HRFlows.Flow.handle_event(parent_flow, {:receive_data, data.participant})
:ok = GTGO.complete(data.participant.email)
next_state(:complete, data)
end
end
defgstate waiting_for_spouse_signature, timeout: @twenty_minutes do
defgevent receive_spouse_signature(%{signed: signed}), transitions_to: [:complete], data: data do
{:ok, parent_flow} = HRFlows.Store.get(HRFlows.Flow, data.parent_flow_id)
HRFlows.Flow.handle_event(parent_flow, {:receive_data, data.participant})
:ok = GTGO.complete(data.participant.email)
next_state(:complete, %Data{ data | participant: %Participant{data.participant | spouse_signed: signed}})
end
end
defgstate complete, timeout: @twenty_minutes
end
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment