diff --git a/assets/css/app.css b/assets/css/app.css index f0b959f..9ecc0e7 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -11,95 +11,110 @@ body { } .stepper { - font-family: sans-serif; - background: var(--bg-color); - & > div { - h2 { - font-size: 2.3rem; - color: var(--secondary); - text-align: center; - } - .radio-grid { - display: grid; - grid-gap: 2rem; - grid-template-columns: repeat(3, 1fr); - margin-top: 1rem; - label { - height: 20rem; - position: relative; - input { - visibility: hidden; - z-index: -99; - position: absolute; - } - input + span { - border: 1px var(--primary) solid; - border-radius: 2rem; - overflow: hidden; - cursor: pointer; - background: white; - display: flex; - flex-direction: column; - align-items: center; - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - span:first-child { - display: flex; - flex: 1 0 0; - justify-content: center; - align-items: center; + form { + font-family: sans-serif; + background: var(--bg-color); + & > div { + h2 { + font-size: 2.3rem; + color: var(--secondary); + text-align: center; + } + .radio-grid { + display: grid; + grid-gap: 2rem; + grid-template-columns: repeat(3, 1fr); + margin-top: 1rem; + label { + height: 20rem; + position: relative; + input { + visibility: hidden; + z-index: -99; + position: absolute; } - span:nth-child(2) { - flex: 0 0 4rem; - background: var(--gray); + input + span { + border: 1px var(--primary) solid; + border-radius: 2rem; + overflow: hidden; + cursor: pointer; + background: white; display: flex; - width: 100%; - justify-content: center; + flex-direction: column; align-items: center; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + span:first-child { + display: flex; + flex: 1 0 0; + justify-content: center; + align-items: center; + } + span:nth-child(2) { + flex: 0 0 4rem; + background: var(--gray); + display: flex; + width: 100%; + justify-content: center; + align-items: center; + } + } + input:checked + span { + border-color: var(--secondary); + } + svg { + color: var(--secondary); + fill: currentColor; + width: 8rem; + height: 8rem; } } - input:checked + span { - border-color: var(--secondary); - } - svg { - color: var(--secondary); - fill: currentColor; - width: 8rem; - height: 8rem; - } - } - } - .form-container { - background: var(--container); - border-radius: 2rem; - padding: 3rem; - display: grid; - grid-gap: 1rem; - .separator { - background: white; - height: 5px; } - .form-grid { + .form-container { + background: var(--container); + border-radius: 2rem; + padding: 3rem; display: grid; - grid-gap: 0.5rem; - grid-template-columns: 2fr 3fr 30px; - align-items: center; - input[type="text"] { - font-weight: bold; - border: var(--primary) 1px solid; - text-align: right; - } - .unit { - text-align: right; + grid-gap: 1rem; + .separator { + background: white; + height: 5px; } - .comment { - grid-column: 1 / -1; - font-size: 1.5rem; + .form-grid { + display: grid; + grid-gap: 0.5rem; + grid-template-columns: 2fr 3fr 30px; + align-items: center; + input[type="text"] { + font-weight: bold; + border: var(--primary) 1px solid; + text-align: right; + } + .unit { + text-align: right; + } + .comment { + grid-column: 1 / -1; + font-size: 1.5rem; + } } } } + + .step { + height: 5px; + position: relative; + div { + position: absolute; + transition: width 0.5s; + top: 0; + left: 0; + height: 100%; + background: var(--primary); + } + } } } diff --git a/assets/js/app.js b/assets/js/app.js index 04ef613..accbc35 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -1,7 +1,8 @@ +import axios from 'axios'; import 'alpinejs'; import wNumb from 'wnumb'; -var units = { +var units = window.units = { currency: wNumb({ mark: ',', thousand: '.', @@ -13,7 +14,7 @@ var units = { mark: ',', thousand: '', prefix: '', - suffix: ' %', + suffix: '', decimals: 2 }) }; @@ -26,7 +27,7 @@ window.stepper = { makler: 0.0357 }, units: units, - step: 2, + step: 0, greetings: [ { value: 'frau', label: 'Frau' }, { value: 'herr', label: 'Herr' }, @@ -40,7 +41,7 @@ window.stepper = { { value: 'dr', label: 'Dr' }, ], value: { - kind: 'kauf', + kind: null, kauf: { kaufpreis: 300000, modernisierung: 0, @@ -82,5 +83,11 @@ window.stepper = { /* Methods */ svg(icon) { return ``; + }, + + submit() { + axios.post('/wp-admin/admin-ajax.php?action=stepper_submit', { + ...this.value + }); } }; diff --git a/package.json b/package.json index c61731e..6e80b21 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "license": "ISC", "dependencies": { "alpinejs": "^2.7.3", + "axios": "^0.21.0", "cross-env": "^7.0.2", "laravel-mix": "^5.0.7", "postcss-nested": "^4.0", diff --git a/src/Stepper.php b/src/Stepper.php index dd845ee..7c71b58 100644 --- a/src/Stepper.php +++ b/src/Stepper.php @@ -26,6 +26,7 @@ class Stepper { public function init() { add_action('wp_enqueue_scripts', [ $this, 'enqueue' ]); + add_action('wp_ajax_nopriv_stepper_submit', [ $this, 'onSubmit' ]); add_shortcode('stepper', [ $this, 'handle' ]); } @@ -50,4 +51,13 @@ class Stepper { @change="'.$prop.' = units.'.$modifier.'.from($event.target.value)"'; } + public function onSubmit() { + json_decode(file_get_contents('php://input')); + wp_mail('info@jonas-ruettgers.de', 'Neue Finanzierungs-Anfrage', $this->twig->render('mail.twig.htm', json_decode(file_get_contents('php://input'), true)), [ + 'From' => 'philipp@aweos.de' + ]); + + die(); + } + } diff --git a/views/mail.twig.htm b/views/mail.twig.htm new file mode 100644 index 0000000..b6c23ee --- /dev/null +++ b/views/mail.twig.htm @@ -0,0 +1,21 @@ +Eine neue Anfrage ist eingetroffen. + +Name: {{firstname}} {{lastname}} +Adresse: {{zip}} {{location}} +Tel: {{phone}} +Mail: {{email}} + +Anfrage für: {{kind}} + +{% if kind == 'kauf' %} +* Kaufpreis: {{kauf.kaufpreis}} € +* Modernisierung: {{kauf.modernisierung}} € +* Baukosten: {{kauf.baukosten}} € +* Eigenkapital: {{kauf.eigenkapital}} € +{% endif %} +{% if kind == 'bau' %} +* Grundstückspreis: {{bau.grundstueckspreis}} € +* Bezahlt: {{bau.bezahlt}} € +* Baukosten: {{bau.baukosten}} € +* Eigenkapital: {{bau.eigenkapital}} € +{% endif %} diff --git a/views/stepper.twig.htm b/views/stepper.twig.htm index 7f28559..ce6c90e 100644 --- a/views/stepper.twig.htm +++ b/views/stepper.twig.htm @@ -1,5 +1,5 @@ -