feat(15): dynamic values in step 3 addon selection
This commit is contained in:
parent
6d827365ac
commit
4d9a7c3e12
|
@ -110,14 +110,21 @@
|
||||||
Add-ons help enhance your gaming experience.
|
Add-ons help enhance your gaming experience.
|
||||||
</p>
|
</p>
|
||||||
<div class="flex flex-col w-full text-sm md:text-base">
|
<div class="flex flex-col w-full text-sm md:text-base">
|
||||||
<label for="multiplayer-games" class="relative pl-6 h-20 md:w-full">
|
<label
|
||||||
|
th:each="addon: ${formData.availableAddons}"
|
||||||
|
for="multiplayer-games"
|
||||||
|
th:for="${addon}"
|
||||||
|
class="relative pl-6 h-20 md:w-full"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
id="multiplayer-games"
|
id="multiplayer-games"
|
||||||
|
th:id="${addon}"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
value="OnlineService"
|
value="OnlineService"
|
||||||
|
th:value="${addon}"
|
||||||
name="addon-services"
|
name="addon-services"
|
||||||
class="my-7 w-6 h-6 peer"
|
class="my-7 w-6 h-6 peer"
|
||||||
th:checked="${formData.userAnswers.step3.containsAddon('OnlineService')}"
|
th:checked="${formData.userAnswers.step3.containsAddon(addon)}"
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50"
|
class="absolute inset-y-0 inset-x-0 rounded-lg border border-cool-gray peer-checked:border-purplish-blue peer-checked:bg-magnolia/50"
|
||||||
|
@ -125,16 +132,24 @@
|
||||||
<div
|
<div
|
||||||
class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]"
|
class="grid place-content-center ml-20 h-full grid-cols-[1fr_100px]"
|
||||||
>
|
>
|
||||||
<h1>Online Service</h1>
|
<h1 th:text="${addon.name}">Online Service</h1>
|
||||||
<p>Access to multiplayer games</p>
|
<p th:text="${addon.description}">
|
||||||
<p class="col-start-2 row-span-2 row-start-1 self-center">
|
Access to multiplayer games
|
||||||
|
</p>
|
||||||
|
<p
|
||||||
|
class="col-start-2 row-span-2 row-start-1 self-center"
|
||||||
|
th:text="|+$${formData.addonCost(addon)}/${formData.periodCostLabel}|"
|
||||||
|
>
|
||||||
+$1/mo
|
+$1/mo
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<label
|
||||||
<label for="larger-storage" class="relative pl-6 h-20 md:w-full">
|
for="larger-storage"
|
||||||
|
class="relative pl-6 h-20 md:w-full"
|
||||||
|
th:remove="all"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
id="larger-storage"
|
id="larger-storage"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
@ -157,8 +172,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
|
<label
|
||||||
<label for="custom-profile" class="relative pl-6 h-20 md:w-full">
|
for="custom-profile"
|
||||||
|
class="relative pl-6 h-20 md:w-full"
|
||||||
|
th:remove="all"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
id="custom-profile"
|
id="custom-profile"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
<div id="selected-plan" class="grid grid-cols-[1fr_auto]">
|
<div id="selected-plan" class="grid grid-cols-[1fr_auto]">
|
||||||
<h2 th:text="${formData.fullPlanName}">Arcade (Monthly)</h2>
|
<h2 th:text="${formData.fullPlanName}">Arcade (Monthly)</h2>
|
||||||
<p
|
<p
|
||||||
th:text="|${formData.planCost}/${formData.periodCostLabel}|"
|
th:text="|$${formData.selectedPlanCost}/${formData.periodCostLabel}|"
|
||||||
class="row-span-2"
|
class="row-span-2"
|
||||||
>
|
>
|
||||||
$90/y
|
$90/y
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
>
|
>
|
||||||
<p th:text="${addon.name}" class="grow">Online service</p>
|
<p th:text="${addon.name}" class="grow">Online service</p>
|
||||||
<p
|
<p
|
||||||
th:text="|+${formData.addonCost(addon)}/${formData.periodCostLabel}|"
|
th:text="|+$${formData.addonCost(addon)}/${formData.periodCostLabel}|"
|
||||||
>
|
>
|
||||||
+$10/yr
|
+$10/yr
|
||||||
</p>
|
</p>
|
||||||
|
@ -149,7 +149,7 @@
|
||||||
>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 -->
|
||||||
|
|
|
@ -29,23 +29,13 @@ object Models {
|
||||||
def selectedPlanCost: Int = planCost(userAnswers.step2.planType)
|
def selectedPlanCost: Int = planCost(userAnswers.step2.planType)
|
||||||
|
|
||||||
def planCost(plan: PlanType): Int = {
|
def planCost(plan: PlanType): Int = {
|
||||||
val monthlyPlanCost = plan match {
|
val monthlyPlanCost = plan.monthlyCost
|
||||||
case PlanType.Arcade => 9
|
|
||||||
case PlanType.Advanced => 12
|
|
||||||
case PlanType.Pro => 15
|
|
||||||
}
|
|
||||||
if (userAnswers.step2.isYearly) yearlyCost(monthlyPlanCost)
|
if (userAnswers.step2.isYearly) yearlyCost(monthlyPlanCost)
|
||||||
else monthlyPlanCost
|
else monthlyPlanCost
|
||||||
}
|
}
|
||||||
|
|
||||||
def addonMontlyCost: Addons => Int = {
|
|
||||||
case Addons.OnlineService => 1
|
|
||||||
case Addons.LargerStorage => 2
|
|
||||||
case Addons.CustomProfile => 2
|
|
||||||
}
|
|
||||||
|
|
||||||
def addonCost(addon: Addons): Int = {
|
def addonCost(addon: Addons): Int = {
|
||||||
val monthCost = addonMontlyCost(addon)
|
val monthCost = addon.monthlyCost
|
||||||
if (userAnswers.step2.isYearly) yearlyCost(monthCost) else monthCost
|
if (userAnswers.step2.isYearly) yearlyCost(monthCost) else monthCost
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +49,8 @@ object Models {
|
||||||
}
|
}
|
||||||
|
|
||||||
def availablePlans = PlanType.values.toList.asJava
|
def availablePlans = PlanType.values.toList.asJava
|
||||||
|
|
||||||
|
def availableAddons = Addons.values.toList.asJava
|
||||||
}
|
}
|
||||||
|
|
||||||
final case class Answers(
|
final case class Answers(
|
||||||
|
@ -102,12 +94,18 @@ object Models {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PlanType:
|
enum PlanType(val monthlyCost: Int):
|
||||||
case Arcade, Advanced, Pro
|
case Arcade extends PlanType(9)
|
||||||
|
case Advanced extends PlanType(12)
|
||||||
enum Addons:
|
case Pro extends PlanType(15)
|
||||||
case OnlineService, LargerStorage, CustomProfile
|
def name(): String = {
|
||||||
|
this.toString().replaceAll("([a-z])([A-Z])", "$1 $2")
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Addons(val monthlyCost: Int, val description: String):
|
||||||
|
case OnlineService extends Addons(1, "Access to multiplayer games")
|
||||||
|
case LargerStorage extends Addons(2, "Extra 1TB of cloud storage")
|
||||||
|
case CustomProfile extends Addons(2, "Custom theme on your profile")
|
||||||
/** Change camel case into human readable. Adding single space before each
|
/** Change camel case into human readable. Adding single space before each
|
||||||
* uppercase
|
* uppercase
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue