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 $90/y
</p> </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>
<div id="selected-addons" class="flex flex-col"> <div id="selected-addons" class="flex flex-col">
<div <div
@ -140,9 +147,7 @@
</div> </div>
</div> </div>
<section <section class="flex flex-row">
class="flex flex-row"
>
<p class="grow"> <p class="grow">
Total (per Total (per
<span <span
@ -150,7 +155,11 @@
>year</span >year</span
>) >)
</p> </p>
<p th:text="|$${formData.fullOrderPrice}/${formData.periodCostLabel}|">$120</p> <p
th:text="|$${formData.fullOrderPrice}/${formData.periodCostLabel}|"
>
$120
</p>
</section> </section>
<!-- Step 3 end --> <!-- Step 3 end -->
@ -166,9 +175,11 @@
hx-target="#form-step" hx-target="#form-step"
href="step3.html" href="step3.html"
class="ml-6 text-sm font-semibold md:pb-3 md:ml-20 md:text-base text-cool-gray" 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 >Go Back</a
> >
<div class="grow"></div> <div class="grow"></div>
<input type="hidden" name="form-confirmed" value="true" />
<input <input
type="submit" 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" 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._ import scala.jdk.CollectionConverters._
object Models { 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 /** Labels and form info which dynamically depend on user answers e.g plan
* name 'Arcade (Yearly)' vs 'Pro (Monthly)' * name 'Arcade (Yearly)' vs 'Pro (Monthly)'
*/ */
@ -88,7 +79,7 @@ object Models {
) )
case 4 => case 4 =>
this.copy( this.copy(
step4 = this.step4, step4 = this.step4.fromFormData(rawData),
currentStep = nextStep currentStep = nextStep
) )
case _ => this case _ => this
@ -200,7 +191,7 @@ object Models {
val addonsStrings = fieldValues val addonsStrings = fieldValues
.groupMap(_._1)(_._2) .groupMap(_._1)(_._2)
.getOrElse("addon-services", Array.empty[String]) .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 val addons = addonsStrings.map(Addons.valueOf(_)).toSet
Step3(addons, submitted = true) Step3(addons, submitted = true)
@ -209,7 +200,20 @@ object Models {
final case class Step4( final case class Step4(
override val submitted: Boolean = false override val submitted: Boolean = false
) extends StepAnswers { ) 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)
}
} }
} }
} }