Skip to content

Commit

Permalink
fix webhook data
Browse files Browse the repository at this point in the history
  • Loading branch information
jenbutongit committed Jul 1, 2020
1 parent a2badf6 commit 4de54bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 22 additions & 6 deletions runner/src/server/plugins/builder/pages/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SummaryViewModel {
repeatCounter++
if(repeatCounter !== required) {
relevantPages.push(nextPage)
nextPage = relevantPages[relevantPages.length - otherRepeatPagesInSection.length + 1]
nextPage = relevantPages[relevantPages.length - otherRepeatPagesInSection.length]
// repeatCounter = 0
} else {
repeatCounter = 0
Expand Down Expand Up @@ -241,12 +241,22 @@ class SummaryViewModel {
}

parseDataForWebhook (model, relevantPages, details) {
const questions = relevantPages.map(page => {
let counter = {}
const questions = relevantPages.map((page, i) => {
const category = page.section?.name ?? null
const fields = []
page.components.formItems.forEach(item => {
const isRepeatable = page.repeatField
if(isRepeatable) {
const pageCount = counter[page.path]
if(pageCount || pageCount === 0) {
counter[page.path]++
} else {
counter[page.path] = 0
}
}
page.components.formItems.forEach((item => {
const detail = details.find(d => d.name === category)
const detailItem = detail.items.find(detailItem => detailItem.name === item.name)
const detailItem = (isRepeatable ? detail.items[counter[page.path]] : detail.items).find(detailItem => detailItem.name === item.name)
const answer = (typeof detailItem.rawValue === 'object') ? detailItem.value : detailItem.rawValue
fields.push({
key: item.name,
Expand All @@ -269,7 +279,7 @@ class SummaryViewModel {
})
}
}
})
}))

let question = ''
if (page.title) {
Expand All @@ -278,11 +288,17 @@ class SummaryViewModel {
question = page.components.formItems.map(item => this.toEnglish(item.title)).join(', ')
}

return {
let webhookObject = {
category,
question,
fields
}

if(isRepeatable) {
webhookObject.index = counter[page.path]
}

return webhookObject
})

// default name if no name is provided
Expand Down
2 changes: 0 additions & 2 deletions runner/views/partials/summary-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ <h2 class="govuk-heading-m">{{data.title}}</h2>
{% endif %}
<dl class="govuk-summary-list">
{% for item in data.items %}
{{ summaryRow(item) }}

{% if not hide %}
{%- if item | isArray %}
<h2 class="govuk-heading-m govuk-!-margin-top-4 govuk-!-margin-bottom-0">{{data.title}} {{ loop.index }}</h2>
Expand Down

0 comments on commit 4de54bb

Please sign in to comment.