Skip to content

Commit

Permalink
L’onglet inviter reste ouvert après un changement de territoire (#2075)
Browse files Browse the repository at this point in the history
  • Loading branch information
niladic authored Sep 30, 2024
1 parent 1b689f4 commit 706b865
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/controllers/ApplicationController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1243,10 +1243,18 @@ case class ApplicationController @Inject() (
def show(id: UUID): Action[AnyContent] =
loginAction.async { implicit request =>
withApplication(id) { application =>
val openedTab = request.flash
.get("opened-tab")
.orElse(
request
.getQueryString("onglet")
.map(value => if (value === "invitation") "invite" else "answer")
)
.getOrElse("answer")
showApplication(
application,
AnswerFormData.form(request.currentUser, false),
openedTab = request.flash.get("opened-tab").getOrElse("answer"),
openedTab = openedTab,
) { html =>
eventService.log(
EventType.ApplicationShowed,
Expand Down Expand Up @@ -1447,7 +1455,7 @@ case class ApplicationController @Inject() (
Redirect(
routes.ApplicationController.show(applicationId).withFragment("answer-error")
)
.flashing("answer-error" -> message, "opened-tab" -> "anwser")
.flashing("answer-error" -> message, "opened-tab" -> "answer")
)
} { files =>
val form =
Expand Down
7 changes: 6 additions & 1 deletion app/views/application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,12 @@ object application {
div(
"Territoire concerné : ",
views.helpers
.changeAreaSelect(selectedArea, Area.all, ApplicationController.show(application.id))
.changeAreaSelect(
selectedArea,
Area.all,
ApplicationController.show(application.id),
"onglet" -> "invitation"
)
),
views.helpers.forms.CSRFInput,
groupsWithUsersThatCanBeInvited.nonEmpty.some
Expand Down
15 changes: 13 additions & 2 deletions app/views/helpers/changeAreaSelect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@ import serializers.Keys

object changeAreaSelect {

def apply(currentArea: Area, selectableAreas: List[Area], redirectUrlPath: Call): Tag =
def apply(
currentArea: Area,
selectableAreas: List[Area],
redirectUrlPath: Call,
query: (String, String)*
): Tag = {
val queryString = {
val qs = query.map { case (key, value) => s"$key=$value" }.mkString("&")
if (qs.isEmpty) "" else (qs + "&")
}
val redirectUrlPrefix = s"$redirectUrlPath?$queryString${Keys.QueryParam.areaId}=";
select(
id := "changeAreaSelect",
name := "area",
data("current-area") := currentArea.id.toString,
data("redirect-url-prefix") := s"$redirectUrlPath?${Keys.QueryParam.areaId}=",
data("redirect-url-prefix") := redirectUrlPrefix,
selectableAreas.map(area =>
scalatags.Text.tags.option(
value := area.id.toString,
Expand All @@ -22,5 +32,6 @@ object changeAreaSelect {
)
)
)
}

}

0 comments on commit 706b865

Please sign in to comment.