Skip to content

Add flow for existing users to accept new policies - #1160

Open
AndrewKostka wants to merge 1 commit into
mainfrom
T401223
Open

Add flow for existing users to accept new policies#1160
AndrewKostka wants to merge 1 commit into
mainfrom
T401223

Conversation

@AndrewKostka

Copy link
Copy Markdown
Contributor

Bug: T401223

@github-actions

Copy link
Copy Markdown

Deployment previews on netlify for branch refs/pull/1160/merge will be at the following locations (when build is done):

Comment thread src/backend/api.js
const { data } = await axios.get('/v1/policies/current')
return data.items
}
export const getMissingPolicies = async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMissingPolicies and getCurrentPolicies looks similar (same response shape), only the path differs.
You can consider writing getPolicies(path) or something like getPoliciesByStatus('missing' |'current') ti reduce repetition.

Comment thread src/backend/api.js
const { data } = await axios.get('/v1/policies/missing')
return data.items
}
export const acceptPolicies = async (policyIds) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

acceptPolicies doesn't return anything. It can return response.data or something

Comment thread src/store/error.js
}
}

const state = getDefaultState()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exporting a singleton state object is a bit off to me. Does it lead to a shared state across store instances?

Comment thread src/store/error.js

const getters = {
hasLatestError: state => !!state.latestError,
latestError: state => state.latestError,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action name latestError conflicts conceptually with the getter latestError, which makes usage and debugging confusing (dispatch('latestError') vs getters.latestError). Rename the action to something imperative like reportLatestError or setLatestError to clarify intent.

Comment thread src/store/policies.js
try {
commit('setMissingPolicies', await api.getMissingPolicies())
} catch (error) {
commit('failedToGetMissingPolicies', true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failedToGetMissingPolicies flag is set to true on error. But if I understand correctly, it is never reset to false on succesful fetch?

Comment thread src/store/policies.js
commit('setMissingPolicies', await api.getMissingPolicies())
} catch (error) {
commit('failedToGetMissingPolicies', true)
dispatch('latestError', {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dispatch('latestError', ...) call is not awaited or returned. Consider return await dispatch('latestError', ...) (or at least await)

Comment thread src/App.vue
hasMissingPolicies: function () {
return this.$route.meta.requiresAuth &&
!this.$route.meta.requiresAuth.excludeFromPolicyChecks &&
this.$store.getters.missingPolicies?.length

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really get this bit...
hasMissingPolicies returns missingPolicies?.length, which is a number (or worst case undefined). Since this is used in v-if, is it less error-prone to return an explicit boolean (for example, (this.$store.getters.missingPolicies?.length ?? 0) > 0)?

onContactForm () {
this.$router.push('/contact')
},
async onAccept () {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inFlight is set back to false only on the success path. If acceptPolicies throws/rejects or fails in general, inFlight will remain true and the UI will be stuck.
try/catch/finally can wrap the dispatch so inFlight is always reset

Please accept the updated
<PolicyList
:policies="policies"
article=""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

article is empty, if the prop is optional, omit it

)
await this.$store.dispatch('acceptPolicies', policyIds)
this.inFlight = false
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional:
Add tests for the modal actions:

  1. clicking “Contact Form” navigates to /contact
  2. “Continue” is disabled until the checkbox is checked
  3. onAccept re-enables the UI even when acceptPolicies rejects (error path).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants