feat(15): jump from step4 to step2

here hidden 'form-confirmed' input will result in 'submitted' attribute
of Step4 answer to be set,
but this field is explicitly excluded on the hx-post from the Back
and Change links, this seems OK, i guess!
This commit is contained in:
efim 2023-07-15 17:15:21 +00:00
parent 3133a9aa8c
commit dd590e1530
2 changed files with 32 additions and 17 deletions

View File

@ -122,7 +122,14 @@
>
$90/y
</p>
<p>Change</p>
<a
hx-post="/submit-step/4/2"
hx-swap="outerHTML"
hx-target="#form-step"
href="step3.html"
hx-params="not form-confirmed"
>Change</a
>
</div>
<div id="selected-addons" class="flex flex-col">
<div
@ -140,9 +147,7 @@
</div>
</div>
<section
class="flex flex-row"
>
<section class="flex flex-row">
<p class="grow">
Total (per
<span
@ -150,7 +155,11 @@
>year</span
>)
</p>
<p th:text="|$${formData.fullOrderPrice}/${formData.periodCostLabel}|">$120</p>
<p
th:text="|$${formData.fullOrderPrice}/${formData.periodCostLabel}|"
>
$120
</p>
</section>
<!-- Step 3 end -->
@ -166,9 +175,11 @@
hx-target="#form-step"
href="step3.html"
class="ml-6 text-sm font-semibold md:pb-3 md:ml-20 md:text-base text-cool-gray"
hx-params="not form-confirmed"
>Go Back</a
>
<div class="grow"></div>
<input type="hidden" name="form-confirmed" value="true" />
<input
type="submit"
class="grid place-content-center mr-3 w-24 h-10 text-sm font-semibold text-white rounded md:mr-24 md:w-32 md:h-12 md:text-base md:rounded-lg bg-purplish-blue"

View File

@ -4,15 +4,6 @@ import java.util.UUID
import scala.jdk.CollectionConverters._
object Models {
val testAnsw = Answers(
sessionId = "id1",
currentStep = 1,
step1 = StepAnswers.Step1("Test Name", "some@email.com", "+9876", true),
step2 = StepAnswers.Step2(PlanType.Advanced, true, true),
step3 = StepAnswers.Step3(Set(Addons.LargerStorage), true),
step4 = StepAnswers.Step4(true)
)
/** Labels and form info which dynamically depend on user answers e.g plan
* name 'Arcade (Yearly)' vs 'Pro (Monthly)'
*/
@ -88,7 +79,7 @@ object Models {
)
case 4 =>
this.copy(
step4 = this.step4,
step4 = this.step4.fromFormData(rawData),
currentStep = nextStep
)
case _ => this
@ -200,7 +191,7 @@ object Models {
val addonsStrings = fieldValues
.groupMap(_._1)(_._2)
.getOrElse("addon-services", Array.empty[String])
println(s"in step 3 got strings $addonsStrings")
println(s"in step 3 got strings ${addonsStrings.mkString(", ")}")
val addons = addonsStrings.map(Addons.valueOf(_)).toSet
Step3(addons, submitted = true)
@ -209,7 +200,20 @@ object Models {
final case class Step4(
override val submitted: Boolean = false
) extends StepAnswers {
override def fromFormData(rawData: String): Step4 = Step4(true)
override def fromFormData(rawData: String): Step4 =
{
val fieldValues = rawData
.split("&").filterNot(_.isEmpty())
.map { field =>
println(s"working with field $field")
val Array(name, value) = field.split("=")
name -> value
}
.toMap
val isConfirmed = fieldValues.contains("form-confirmed")
Step4(isConfirmed)
}
}
}
}