Skip to content

Commit

Permalink
Merge pull request #66 from hmrc/DAC6-3043-cya
Browse files Browse the repository at this point in the history
Dac6 3043: Update Check your answers
  • Loading branch information
Vishakha1903 authored Jun 6, 2024
2 parents 442fce4 + 47dfae9 commit c7257ce
Show file tree
Hide file tree
Showing 35 changed files with 690 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package controllers.addFinancialInstitution

import com.google.inject.Inject
import controllers.actions.{DataRequiredAction, DataRetrievalAction, IdentifierAction}
import controllers.actions._
import models.UserAnswers
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import viewmodels.checkAnswers.CheckYourAnswersViewModel._
import viewmodels.govuk.summarylist._
import views.html.addFinancialInstitution.CheckYourAnswersView

Expand All @@ -36,11 +38,17 @@ class CheckYourAnswersController @Inject() (

def onPageLoad(): Action[AnyContent] = (identify andThen getData andThen requireData) {
implicit request =>
val list = SummaryListViewModel(
rows = Seq.empty
)
val ua: UserAnswers = request.userAnswers

Ok(view(list))
val financialInstitutionList = SummaryListViewModel(getFinancialInstitutionSummaries(ua))
val firstContactList = SummaryListViewModel(getFirstContactSummaries(ua))
val secondContactList = SummaryListViewModel(getSecondContactSummaries(ua))

Ok(view(financialInstitutionList, firstContactList, secondContactList))
}

def confirmAndAdd(): Action[AnyContent] = (identify andThen getData andThen requireData) {
Redirect(routes.CheckYourAnswersController.onPageLoad())
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class IsThisAddressController @Inject() (
case None => form
case Some(value) => form.fill(value)
}
Ok(view(preparedForm, mode, getFinancialInstitutionName(ua), address.head.toAddress.get))
Ok(view(preparedForm, mode, getFinancialInstitutionName(ua), address.head.toAddress))

case None => Redirect(controllers.routes.JourneyRecoveryController.onPageLoad())
}
Expand All @@ -80,7 +80,7 @@ class IsThisAddressController @Inject() (
.bindFromRequest()
.fold(
formWithErrors =>
Future.successful(BadRequest(view(formWithErrors, mode, getFinancialInstitutionName(request.userAnswers), address.head.toAddress.get))),
Future.successful(BadRequest(view(formWithErrors, mode, getFinancialInstitutionName(request.userAnswers), address.head.toAddress))),
value =>
for {
updatedAnswers <- Future.fromTry(ua.set(IsThisAddressPage, value))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import repositories.SessionRepository
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.Text
import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.RadioItem
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController
import utils.AddressHelper.formatAddress
import utils.ContactHelper
import views.html.addFinancialInstitution.SelectAddressView

Expand Down Expand Up @@ -97,13 +98,4 @@ class SelectAddressController @Inject() (
}
}

private def formatAddress(address: AddressLookup): String = {
val lines = Seq(address.addressLine1, address.addressLine2, address.addressLine3, address.addressLine4).flatten.mkString(", ")
val county = address.county.fold("")(
county => s"$county, "
)

s"$lines, ${address.town}, $county${address.postcode}"
}

}
26 changes: 14 additions & 12 deletions app/models/AddressLookup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ case class AddressLookup(addressLine1: Option[String],
postcode: String
) {

val toAddress: Option[Address] =
for {
line1 <- addressLine1
line2 = addressLine2
line3 = addressLine3
.map(
l => s"$l $town"
)
.getOrElse(town)
line4 = addressLine4
safePostcode = Option(postcode)
} yield Address(line1, line2, line3, line4, safePostcode, Country.GB)
val toAddress: Address = {

val line1 = addressLine1.getOrElse("")
val line2 = addressLine2
val line3 = addressLine3
.map(
l => s"$l $town"
)
.getOrElse(town)
val line4 = addressLine4
val safePostcode = Option(postcode)

Address(line1, line2, line3, line4, safePostcode, Country.GB)
}

}

Expand Down
78 changes: 78 additions & 0 deletions app/utils/AddressHelper.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package utils

import models.{Address, AddressLookup}
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent

object AddressHelper {

def formatAddress(address: AddressLookup): String = {
val lines = Seq(
address.addressLine1,
address.addressLine2,
address.addressLine3,
address.addressLine4,
address.town,
address.postcode,
address.county
)
.collect {
case s: String => s
case Some(s) => s
}
lines.mkString(", ")
}

def formatAddress(address: Address): String = {
val lines = Seq(address.addressLine1,
address.addressLine2,
address.addressLine3,
address.addressLine4,
address.country,
address.postCode,
address.country.description
)
.collect {
case s: String => s
case Some(s) => s
}
lines.mkString(", ")
}

def formatAddressBlock(address: Address): HtmlContent = {
val lines = Seq(address.addressLine1,
address.addressLine2,
address.addressLine3,
address.addressLine4,
address.country,
address.postCode,
address.country.description
)
.collect {
case s: String => s
case Some(s) => s
}
val block = lines
.map(
line => s"<p class='govuk-!-margin-top-0 govuk-!-margin-bottom-0'>$line</p>"
)
.mkString("")
HtmlContent(block)
}

}
43 changes: 43 additions & 0 deletions app/viewmodels/checkAnswers/AddressLookupSummary.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package viewmodels.checkAnswers

import models.{CheckMode, UserAnswers}
import pages.addFinancialInstitution.AddressLookupPage
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import utils.AddressHelper.formatAddressBlock
import viewmodels.checkAnswers.CheckYourAnswersViewModel.accessibleActionItem
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

object AddressLookupSummary {

def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] =
answers.get(AddressLookupPage).map {
answer =>
SummaryListRowViewModel(
key = "mainAddress.checkYourAnswersLabel",
value = ValueViewModel(formatAddressBlock(answer.head.toAddress)),
actions = Seq(
accessibleActionItem("site.change", controllers.addFinancialInstitution.routes.WhereIsFIBasedController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("mainAddress.change.hidden"))
)
)
}

}
89 changes: 89 additions & 0 deletions app/viewmodels/checkAnswers/CheckYourAnswersViewModel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package viewmodels.checkAnswers

import models.UserAnswers
import pages.addFinancialInstitution._
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.content.HtmlContent
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.{ActionItem, SummaryListRow}
import viewmodels.govuk.summarylist._

object CheckYourAnswersViewModel {

def accessibleActionItem(messageKey: String, href: String)(implicit messages: Messages): ActionItem =
ActionItemViewModel(
content = HtmlContent(
s"""
|<span aria-hidden="true">${messages(messageKey)}</span>
|""".stripMargin
),
href = href
)

private def getAddressRow(ua: UserAnswers)(implicit messages: Messages) = {
val addressLookup = AddressLookupSummary.row(ua)
val nonUkAddress = NonUkAddressSummary.row(ua)
val ukAddress = UkAddressSummary.row(ua)

(addressLookup.isDefined, nonUkAddress.isDefined, ukAddress.isDefined) match {
case (false, false, true) => ukAddress
case (false, true, false) => nonUkAddress
case (true, false, false) => addressLookup
case (_, _, _) => None
}

}

private def getGIINRows(ua: UserAnswers)(implicit messages: Messages): Seq[SummaryListRow] = {
val sendReports = ua.get(SendReportsPage)
val haveGIIN = ua.get(HaveGIINPage)

(sendReports, haveGIIN) match {
case (Some(true), None) => Seq(WhatIsGIINSummary.row(ua)).flatten
case (Some(false), Some(true)) => Seq(HaveGIINSummary.row(ua), WhatIsGIINSummary.row(ua)).flatten
case (Some(false), Some(false)) => Seq(HaveGIINSummary.row(ua)).flatten
case (_, _) => Seq.empty
}
}

def getFinancialInstitutionSummaries(ua: UserAnswers)(implicit messages: Messages): Seq[SummaryListRow] =
Seq(
ReportForRegisteredBusinessSummary.row(ua),
NameOfFinancialInstitutionSummary.row(ua),
HaveUniqueTaxpayerReferenceSummary.row(ua),
WhatIsUniqueTaxpayerReferenceSummary.row(ua),
SendReportsSummary.row(ua),
getGIINRows(ua),
getAddressRow(ua)
).flatten

def getFirstContactSummaries(ua: UserAnswers)(implicit messages: Messages): Seq[SummaryListRow] = Seq(
FirstContactNameSummary.row(ua),
FirstContactEmailSummary.row(ua),
FirstContactPhoneNumberSummary.row(ua)
).flatten

def getSecondContactSummaries(ua: UserAnswers)(implicit messages: Messages): Seq[SummaryListRow] =
Seq(
SecondContactExistsSummary.row(ua),
SecondContactNameSummary.row(ua),
SecondContactEmailSummary.row(ua),
SecondContactPhoneNumberSummary.row(ua)
).flatten

}
3 changes: 2 additions & 1 deletion app/viewmodels/checkAnswers/FirstContactEmailSummary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import pages.addFinancialInstitution.FirstContactEmailPage
import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.checkAnswers.CheckYourAnswersViewModel.accessibleActionItem
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

Expand All @@ -33,7 +34,7 @@ object FirstContactEmailSummary {
key = "firstContactEmail.checkYourAnswersLabel",
value = ValueViewModel(HtmlFormat.escape(answer).toString),
actions = Seq(
ActionItemViewModel("site.change", controllers.addFinancialInstitution.routes.FirstContactEmailController.onPageLoad(CheckMode).url)
accessibleActionItem("site.change", controllers.addFinancialInstitution.routes.FirstContactEmailController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("firstContactEmail.change.hidden"))
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import models.{CheckMode, UserAnswers}
import pages.addFinancialInstitution.FirstContactHavePhonePage
import play.api.i18n.Messages
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.checkAnswers.CheckYourAnswersViewModel.accessibleActionItem
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

Expand All @@ -34,7 +35,7 @@ object FirstContactHavePhoneSummary {
key = "firstContactHavePhone.checkYourAnswersLabel",
value = ValueViewModel(value),
actions = Seq(
ActionItemViewModel("site.change", controllers.addFinancialInstitution.routes.FirstContactHavePhoneController.onPageLoad(CheckMode).url)
accessibleActionItem("site.change", controllers.addFinancialInstitution.routes.FirstContactHavePhoneController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("firstContactHavePhone.change.hidden"))
)
)
Expand Down
3 changes: 2 additions & 1 deletion app/viewmodels/checkAnswers/FirstContactNameSummary.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import pages.addFinancialInstitution.FirstContactNamePage
import play.api.i18n.Messages
import play.twirl.api.HtmlFormat
import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow
import viewmodels.checkAnswers.CheckYourAnswersViewModel.accessibleActionItem
import viewmodels.govuk.summarylist._
import viewmodels.implicits._

Expand All @@ -33,7 +34,7 @@ object FirstContactNameSummary {
key = "firstContactName.checkYourAnswersLabel",
value = ValueViewModel(HtmlFormat.escape(answer).toString),
actions = Seq(
ActionItemViewModel("site.change", controllers.addFinancialInstitution.routes.FirstContactNameController.onPageLoad(CheckMode).url)
accessibleActionItem("site.change", controllers.addFinancialInstitution.routes.FirstContactNameController.onPageLoad(CheckMode).url)
.withVisuallyHiddenText(messages("firstContactName.change.hidden"))
)
)
Expand Down
Loading

0 comments on commit c7257ce

Please sign in to comment.