From: soufiane Date: Mon, 27 Mar 2023 10:11:19 +0000 (+0200) Subject: wip #5788 @7:30 Gestion des erreurs, correctifs js/css, refactorisation X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=af8da6fbf8b8209951d59e4e26ea02dbbcf0824e;p=pmi.git wip #5788 @7:30 Gestion des erreurs, correctifs js/css, refactorisation --- diff --git a/app/Http/Controllers/AjaxController.php b/app/Http/Controllers/AjaxController.php index 637ade4..bb226e7 100644 --- a/app/Http/Controllers/AjaxController.php +++ b/app/Http/Controllers/AjaxController.php @@ -492,16 +492,24 @@ class AjaxController extends CubistFrontController public function getuser() { $user = Auth::guard('web-clients')->user(); - $addressToArray = json_decode($user->address); - $checkBillingAddress = array_filter($addressToArray, function($n) { return $n->billing_address; }); - $checkDeliveryAddress = array_filter($addressToArray, function($n) { return $n->delivery_address; }); - - $data = [ - 'user' => $user, - 'address_billing' => key($checkBillingAddress) ?? "0", - 'address_delivery' => key($checkDeliveryAddress) ?? "0" - ]; - - return $data; + if($user) { + $addressToArray = json_decode($user->address); + $checkBillingAddress = array_filter($addressToArray, function ($n) { + return $n->billing_address; + }); + $checkDeliveryAddress = array_filter($addressToArray, function ($n) { + return $n->delivery_address; + }); + + $data = [ + 'user' => $user, + 'address_billing' => key($checkBillingAddress) ?? "0", + 'address_delivery' => key($checkDeliveryAddress) ?? "0" + ]; + + return $data; + }else{ + abort(401, 'Unauthorized'); + } } } diff --git a/resources/js/app.js b/resources/js/app.js index 2fd2d3a..597d816 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -116,12 +116,6 @@ const app = new Vue({ }, methods: { - resetUrlAccount() { - let hash = window.location.hash - let fullUrl = window.location.origin+window.location.pathname - if(hash) - history.pushState("", "", fullUrl); - }, saveCart(data) { let root = this; axios.post('/ajax/cart', data) @@ -160,11 +154,25 @@ const app = new Vue({ closeCart() { document.body.classList.remove('cart-open'); }, - //next code is for login and account page + + /** + * + * The following functions are used for login,register and account page + * + */ + resetUrlAccount() { + // Remove hash to url if exist to prevent to stay in same tab + // It used in account page when we navigate between different tab + let hash = window.location.hash, + fullUrl = window.location.origin+window.location.pathname + + if(hash) + history.pushState("", "", fullUrl); + }, toggleType(el) { this.type[el] = this.type[el] === "password" ? "text" : "password" }, - removeErrors() { + removeErrorsForm() { let errors = document.querySelector('.form-errors'), errorInput = document.querySelectorAll('.error') @@ -174,30 +182,12 @@ const app = new Vue({ errorInput[i].classList.remove('error'); } }, - checkEmailExist() { - let root = this, - data = { - email: root.email_signin - } - - axios.post('/ajax/check_email_exist', data) - .then(function (response) { - //do the verification before to set validateEmail true - root.validateEmail = true - if (response.data.length > 0) { - root.emailExist = true - } - }) - .catch(function (error) { - console.log('error', error) - }) - }, errorHandling(data, root){ if (data.response) { let errors = data.response.data.errors root.errorsForm = errors - root.removeErrors() + root.removeErrorsForm() for (let k in errors) { if(k.indexOf('.')){ @@ -215,6 +205,24 @@ const app = new Vue({ } } }, + checkEmailExist() { + let root = this, + data = { + email: root.email_signin + } + + axios.post('/ajax/check_email_exist', data) + .then(function (response) { + root.validateEmail = true + if (response.data.length > 0) { + root.emailExist = true + } + }) + .catch(function (error) { + root.errorHandling(error, root) + } + ) + }, signin() { let root = this, form = document.getElementById('signin-form'), @@ -222,10 +230,8 @@ const app = new Vue({ axios.post('/ajax/signin', data) .then(function (response) { - // - - let lastVisitedUrl = document.querySelector('[name="previous-url"]').getAttribute('content'); - let homeUrl = window.location.origin; + let lastVisitedUrl = document.querySelector('[name="previous-url"]').getAttribute('content'), + homeUrl = window.location.origin; if(lastVisitedUrl){ if(lastVisitedUrl.includes('pm-instrumentation')){ @@ -239,7 +245,8 @@ const app = new Vue({ }) .catch(function (error) { root.errorHandling(error, root) - }) + } + ) }, signup() { let root = this, @@ -248,44 +255,47 @@ const app = new Vue({ axios.post('/ajax/signup', data) .then(function (response) { - // - root.removeErrors() + + root.validateForm = true + + // Reset form + root.email_signin = '' + root.errorsForm = {} + root.removeErrorsForm() form.reset() window.scrollTo({ top: 0, behavior: "smooth" }) - root.validateForm = true - root.email_signin = '' - root.errorsForm = {} }) .catch(function (error) { root.errorHandling(error, root) - }) + } + ) }, - activeTab(tab){ + activeTab(tab) { this.tab = tab this.errorsForm = {} + this.removeErrorsForm() this.resetUrlAccount() - this.removeErrors() }, - getUser(){ + getUser() { let root = this + axios.post('/ajax/getuser') .then(function (response) { // root.user = response.data['user'] root.addresses = JSON.parse(root.user.address) - root.default_billing_address = 'billing'+response.data['address_billing'] root.default_delivery_address = 'delivery'+response.data['address_delivery'] }) .catch(function (error) { - - }) + } + ) }, - addAddressToForm(event){ + addAddressToForm(event) { let newAddress = { 'billing_address': '0', 'delivery_address': '0' @@ -293,11 +303,12 @@ const app = new Vue({ this.addresses.push(newAddress) - //disabled click at most once + // Disabled the click to add address at most once let target = event.target target.setAttribute('disabled', 'disabled') - setTimeout(function (){ + // Scrolling even the new address form + setTimeout(function () { let forms = document.querySelector('.form-portal').parentElement.parentElement.lastChild let top = forms.offsetTop - 60; @@ -307,12 +318,12 @@ const app = new Vue({ behavior: "smooth" }) - //enabled click after scroll is happened + // Enabled the click to add address after scroll is happened target.removeAttribute('disabled') }, 150) }, - update(id){ + update(id) { let root = this, form = document.getElementById(id), data = new FormData(form) @@ -320,30 +331,31 @@ const app = new Vue({ axios.post('/ajax/update', data) .then(function (response) { // - root.removeErrors() + root.removeErrorsForm() root.validateForm = true root.form[id] = response.data }) .catch(function (error) { root.errorHandling(error, root) - }) + } + ) }, - updateAddress(id){ + updateAddress(id) { let root = this, form = document.getElementById(id), data = new FormData(form) axios.post('/ajax/updateAddress', data) .then(function (response) { - // - root.removeErrors() + root.removeErrorsForm() root.validateForm = true }) .catch(function (error) { root.errorHandling(error, root) - }) + } + ) }, - deleteAddress(index, form){ + deleteAddress(index, form) { let root = this, form_ = document.getElementById(form), data = { @@ -367,10 +379,18 @@ const app = new Vue({ }) .catch(function (error) { - }) - + } + ) } }, + /** + * The following block of code is used for to close "modal confirm update/register" + * with escape key of keyboard or by clicking outside the modal + * + * Custom directive "close-outside" + * + * Eg.
+ */ directives: { 'close-outside': { twoWay: true, @@ -410,15 +430,6 @@ document.addEventListener('DOMContentLoaded', function () { } }); -/** - * The following block of code is used for to close "modal confirm update/register" - * with escape key of keyboard or by clicking outside the modal - */ - -/** - * end of block - */ - document.addEventListener('scroll', function () { checkScroll(); }, {passive: true}); diff --git a/resources/styles/components/my-account.styl b/resources/styles/components/my-account.styl index f2d424c..8b38140 100644 --- a/resources/styles/components/my-account.styl +++ b/resources/styles/components/my-account.styl @@ -1,4 +1,8 @@ .account + &-header-list + min-width: 281px !important + right: 0 + &-nav li position: relative diff --git a/resources/styles/components/signin.styl b/resources/styles/components/signin.styl index 117a698..65dc033 100644 --- a/resources/styles/components/signin.styl +++ b/resources/styles/components/signin.styl @@ -50,3 +50,12 @@ color: theme('colors.red') &:not(:last-child) padding-bottom: 3px + +.signin, +.account + .btn:not(#checkemail) + max-width: 258px + width: 100% + padding-left: 28px + padding-right: 28px + justify-content: center diff --git a/resources/views/pages/sign_in.blade.php b/resources/views/pages/sign_in.blade.php index 17d8bdf..359a0dd 100644 --- a/resources/views/pages/sign_in.blade.php +++ b/resources/views/pages/sign_in.blade.php @@ -7,6 +7,13 @@

Se connecter

+
+ +
@csrf
@@ -148,7 +155,7 @@

{{ __('Mon adresse') }}

@@ -173,7 +180,7 @@