]> _ Git - pmi.git/commitdiff
wip #5788 @7:30 Gestion des erreurs, correctifs js/css, refactorisation
authorsoufiane <soufiane@cubedesigners.com>
Mon, 27 Mar 2023 10:11:19 +0000 (12:11 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 27 Mar 2023 10:11:19 +0000 (12:11 +0200)
app/Http/Controllers/AjaxController.php
resources/js/app.js
resources/styles/components/my-account.styl
resources/styles/components/signin.styl
resources/views/pages/sign_in.blade.php
resources/views/partials/header.blade.php

index 637ade44c1290b3a942fb2fc32167fa2e28ca852..bb226e759d19500fc7c6a01a335c3c48eca5558f 100644 (file)
@@ -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');
+        }
     }
 }
index 2fd2d3a3dca4e22cf4a9dff2e72eb29c010f89f3..597d8168a1644775f4239a2c4b6e801ccc8caac2 100644 (file)
@@ -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. <div v-close-outside></div>
+     */
     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});
index f2d424ce68b2b268c52a1413029a555413db0c46..8b381407915b9e8b3cf0fe1aef4e7a58d34579ae 100644 (file)
@@ -1,4 +1,8 @@
 .account
+  &-header-list
+    min-width: 281px !important
+    right: 0
+
   &-nav
     li
       position: relative
index 117a6987f1fc0eb3699bb8dad8ae014c838066f6..65dc0336f3ed690a89000ae305cad4aba027535f 100644 (file)
     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
index 17d8bdfd0eaa909281220c838aaec519c6e0afa8..359a0dd2b64bb8ccb3b20bad31d73e8ab95b60d9 100644 (file)
@@ -7,6 +7,13 @@
                 <div class="form-info text-navy mb-10">
                     <h1 class="text-4xl m-0">Se connecter</h1>
                 </div>
+                <div class="signup-form-errors mb-10" v-if="Object.keys(errorsForm).length > 0">
+                    <ul class="list-disc list-inside text-red">
+                        <li class="leading-5" v-for="(errorName,errorKey) in errorsForm" :key="errorKey">
+                            @{{ errorName[0] }}
+                        </li>
+                    </ul>
+                </div>
                 <form class="form-portal">
                     @csrf
                     <div class="form-group mb-6">
                         <h2 class="text-2xl">{{ __('Mon adresse') }}</h2>
                         <label class="form-input mb-6 text-navy">
                             {{ __('Adresse de facturation') }}<span>*</span>
-                            <textarea class="py-3 mt-3" required="required" name="address[billing][address]">
+                            <textarea class="py-3 mt-3" required="required" rows="5" name="address[billing][address]">
                             </textarea>
                         </label>
                         <div class="fields grid">
                         <div class="form-group line-up mt-12 pt-12" v-if="!address_choice">
                             <label class="form-input mb-6 text-navy">
                                 {{ __('Adresse de livraison') }}<span>*</span>
-                                <textarea class="py-3 mt-3" required="required" name="address[delivery][address]"></textarea>
+                                <textarea class="py-3 mt-3" required="required" rows="5" name="address[delivery][address]"></textarea>
                             </label>
                             <div class="fields grid">
                                 <label class="form-input half mb-6 text-navy">
index f986bb83cb138a67da9fb9f741c4b4cb66d6a59b..c5d0018764017773b7c6c39b5464d959f978941a 100644 (file)
@@ -31,7 +31,7 @@
 
         </nav>
 
-        <ul class="account-header">
+        <ul class="account-header relative">
             <li class="{{ Route::currentRouteName() === "client" ? "active" : '' }}">
                 <a href="{{ Auth::guard('web-clients')->check() ? $nav->getHrefByName('Mon compte') : $nav->getHrefByName('signin') }}"
                    class="text-right flex items-center cursor-pointer text-white hover:text-primary"