-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #458 from hmrc/SASS-9705
SASS-9705 - Foreign Property - Expenses section: Create 'Have you finished this section' page
- Loading branch information
Showing
10 changed files
with
459 additions
and
6 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
app/controllers/foreign/expenses/ForeignExpensesSectionCompleteController.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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 controllers.foreign.expenses | ||
|
||
import controllers.ControllerUtils.statusForPage | ||
import controllers.actions._ | ||
import forms.foreign.expenses.ForeignExpensesSectionCompleteFormProvider | ||
import models.JourneyPath.ForeignPropertyExpenses | ||
import models.{JourneyContext, NormalMode} | ||
import navigation.ForeignPropertyNavigator | ||
import pages.foreign.expenses.ForeignExpensesSectionCompletePage | ||
import play.api.i18n.{I18nSupport, MessagesApi} | ||
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} | ||
import repositories.SessionRepository | ||
import service.JourneyAnswersService | ||
import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController | ||
import views.html.foreign.expenses.ForeignExpensesSectionCompleteView | ||
|
||
import javax.inject.Inject | ||
import scala.concurrent.{ExecutionContext, Future} | ||
|
||
class ForeignExpensesSectionCompleteController @Inject()( | ||
override val messagesApi: MessagesApi, | ||
sessionRepository: SessionRepository, | ||
navigator: ForeignPropertyNavigator, | ||
identify: IdentifierAction, | ||
getData: DataRetrievalAction, | ||
requireData: DataRequiredAction, | ||
formProvider: ForeignExpensesSectionCompleteFormProvider, | ||
val controllerComponents: MessagesControllerComponents, | ||
view: ForeignExpensesSectionCompleteView, | ||
journeyAnswersService: JourneyAnswersService | ||
)(implicit ec: ExecutionContext) extends FrontendBaseController with I18nSupport { | ||
|
||
val form = formProvider() | ||
|
||
def onPageLoad(taxYear: Int, countryCode: String): Action[AnyContent] = (identify andThen getData andThen requireData) { | ||
implicit request => | ||
|
||
val preparedForm = request.userAnswers.get(ForeignExpensesSectionCompletePage(countryCode)) match { | ||
case None => form | ||
case Some(value) => form.fill(value) | ||
} | ||
|
||
Ok(view(preparedForm, taxYear, countryCode)) | ||
} | ||
|
||
def onSubmit(taxYear: Int, countryCode: String): Action[AnyContent] = (identify andThen getData andThen requireData).async { | ||
implicit request => | ||
|
||
form.bindFromRequest().fold( | ||
formWithErrors => | ||
Future.successful(BadRequest(view(formWithErrors, taxYear, countryCode))), | ||
|
||
value => | ||
for { | ||
updatedAnswers <- Future.fromTry(request.userAnswers.set(ForeignExpensesSectionCompletePage(countryCode), value)) | ||
_ <- sessionRepository.set(updatedAnswers) | ||
status <- journeyAnswersService.setStatus( | ||
JourneyContext( | ||
taxYear = taxYear, | ||
mtditid = request.user.mtditid, | ||
nino = request.user.nino, | ||
journeyPath = ForeignPropertyExpenses | ||
), | ||
status = statusForPage(value), | ||
request.user | ||
) | ||
} yield Redirect(navigator.nextPage(ForeignExpensesSectionCompletePage(countryCode), taxYear, NormalMode, request.userAnswers, updatedAnswers)) | ||
) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/forms/foreign/expenses/ForeignExpensesSectionCompleteFormProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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 forms.foreign.expenses | ||
|
||
import forms.mappings.Mappings | ||
import play.api.data.Form | ||
|
||
import javax.inject.Inject | ||
|
||
class ForeignExpensesSectionCompleteFormProvider @Inject() extends Mappings { | ||
|
||
def apply(): Form[Boolean] = | ||
Form( | ||
"foreignExpensesSectionComplete" -> boolean("haveYouFinishedThisSection.error.required") | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/pages/foreign/expenses/ForeignExpensesSectionCompletePage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 pages.foreign.expenses | ||
|
||
import models.ForeignProperty | ||
import pages.PageConstants.expensesPath | ||
import pages.QuestionPage | ||
import play.api.libs.json.JsPath | ||
|
||
case class ForeignExpensesSectionCompletePage(countryCode: String) extends QuestionPage[Boolean] { | ||
|
||
override def path: JsPath = JsPath \ expensesPath(ForeignProperty) \ countryCode.toUpperCase \ toString | ||
|
||
override def toString: String = "foreignExpensesSectionComplete" | ||
} |
49 changes: 49 additions & 0 deletions
49
app/views/foreign/expenses/ForeignExpensesSectionCompleteView.scala.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@* | ||
* 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. | ||
*@ | ||
|
||
@import controllers.foreign.expenses.routes | ||
@import viewmodels.LegendSize | ||
|
||
@this( | ||
layout: templates.Layout, | ||
formHelper: FormWithCSRF, | ||
govukErrorSummary: GovukErrorSummary, | ||
govukRadios: GovukRadios, | ||
govukButton: GovukButton | ||
) | ||
|
||
@(form: Form[_], taxYear: Int, countryCode: String)(implicit request: Request[_], messages: Messages) | ||
|
||
@layout(pageTitle = title(form, messages("haveYouFinishedThisSection.title"))) { | ||
|
||
@if(form.errors.nonEmpty) { | ||
@govukErrorSummary(ErrorSummaryViewModel(form)) | ||
} | ||
|
||
@formHelper(action = routes.ForeignExpensesSectionCompleteController.onSubmit(taxYear, countryCode), Symbol("autoComplete") -> "off") { | ||
|
||
@govukRadios( | ||
RadiosViewModel.yesNo( | ||
field = form("foreignExpensesSectionComplete"), | ||
legend = LegendViewModel(messages("haveYouFinishedThisSection.heading")).asPageHeading(LegendSize.Large) | ||
).withHint(HintViewModel(messages("haveYouFinishedThisSection.hint"))) | ||
) | ||
|
||
@govukButton( | ||
ButtonViewModel(messages("site.continue")).withId("continue") | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.