From 273254566d817724bd9befb740bfcf600e30a101 Mon Sep 17 00:00:00 2001 From: Dirk Date: Thu, 18 Jul 2024 09:39:47 +0200 Subject: [PATCH] feat: add basic user detail step --- .../basic-user-details-step.js | 62 +++++++++++++++++++ .../loan-application-form.js | 6 +- .../loan-application-form/request-otp-step.js | 4 +- .../restore-previous-journey-step.js | 4 +- 4 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 blocks/loan-application-form/basic-user-details-step.js diff --git a/blocks/loan-application-form/basic-user-details-step.js b/blocks/loan-application-form/basic-user-details-step.js new file mode 100644 index 000000000..99f160bfb --- /dev/null +++ b/blocks/loan-application-form/basic-user-details-step.js @@ -0,0 +1,62 @@ +/* eslint-disable object-curly-newline */ +/* eslint-disable import/no-cycle */ +/* eslint-disable import/no-unresolved */ +import { Component } from 'preact'; +import { html } from 'htm/preact'; +import { hnodeAs } from './loan-application-form.js'; + +export default class BasicUserDetailsStep extends Component { + static parse(block) { + const [ + introWrapper, + guidanceWrapper, + disclaimerWrapper, + submitButtonWrapper, + ] = [...block.children].map((row) => row.firstElementChild); + const intro = introWrapper.children; + const guidance = guidanceWrapper.children; + const disclaimer = disclaimerWrapper.children; + const submitButton = submitButtonWrapper.firstElementChild; + return { intro, guidance, disclaimer, submitButton }; + } + + static defaults = { + into: html`

Introduction

`, + guidance: html`

guidance

`, + disclaimer: html`

Disclaimer

`, + submitButton: html``, + }; + + render() { + const { + intro, + guidance, + disclaimer, + submitButton, + } = this.props.config; + + return html` +
+
+ ${intro} +
+
+ + + + + +
+
+ ${guidance} +
+
+ + ${disclaimer} +
+
+ `; + } +} diff --git a/blocks/loan-application-form/loan-application-form.js b/blocks/loan-application-form/loan-application-form.js index 4aaaaa2eb..9ab3d808b 100644 --- a/blocks/loan-application-form/loan-application-form.js +++ b/blocks/loan-application-form/loan-application-form.js @@ -10,9 +10,10 @@ import { } from 'preact'; import { useState, useRef, useEffect } from 'preact/hooks'; import { html } from 'htm/preact'; +import { wrapTextNodes } from '../../scripts/aem.js'; import RequestOtpStep from './request-otp-step.js'; import RestorePreviousJourenyStep from './restore-previous-journey-step.js'; -import { wrapTextNodes } from '../../scripts/aem.js'; +import BasicUserDetailsStep from './basic-user-details-step.js'; export function hnodeAs(node, tagName, props = {}) { const copy = cloneElement(node, props); @@ -50,6 +51,7 @@ export function hnode(nodes) { const routes = { 'request-otp-step': RequestOtpStep, 'restore-previous-journey-step': RestorePreviousJourenyStep, + 'basic-user-details-step': BasicUserDetailsStep, }; export const LoanApplicationFormContext = createContext(); @@ -97,7 +99,7 @@ export function ConfiguredFormStep({ props, children: renderer }) { // the state accordingly ref.current.addEventListener('apply-update', ({ detail: update }) => { const parsedUpdate = new DOMParser().parseFromString(update, 'text/html'); - const configBlock = parsedUpdate.querySelector('.request-otp-step'); + const configBlock = parsedUpdate.querySelector(`.${name}`); wrapTextNodes(configBlock); const { attrs: newAttrs, config: newConfig } = parseConfig(configBlock, routes[name]); setAppliedAttrs(newAttrs); diff --git a/blocks/loan-application-form/request-otp-step.js b/blocks/loan-application-form/request-otp-step.js index 40539a46f..dcc22210e 100644 --- a/blocks/loan-application-form/request-otp-step.js +++ b/blocks/loan-application-form/request-otp-step.js @@ -45,7 +45,7 @@ export default class RequestOtpStep extends Component { ${hnodeAs(dealerOption, 'label', { for: 'dealer-journey' })} - +
${description}
@@ -54,7 +54,7 @@ export default class RequestOtpStep extends Component { - + `; } diff --git a/blocks/loan-application-form/restore-previous-journey-step.js b/blocks/loan-application-form/restore-previous-journey-step.js index 7e40e84eb..54d7709ae 100644 --- a/blocks/loan-application-form/restore-previous-journey-step.js +++ b/blocks/loan-application-form/restore-previous-journey-step.js @@ -30,7 +30,7 @@ export default class RestorePreviousJourenyStep extends Component {
${description} - +
- +
`; }