Browse Source

shopGQL done

Vadym Hlushko 3 năm trước cách đây
mục cha
commit
e3bac3e8f3
1 tập tin đã thay đổi với 25 bổ sung17 xóa
  1. 25 17
      shopGQL/main.js

+ 25 - 17
shopGQL/main.js

@@ -364,8 +364,20 @@ const actionPromise = (name, promise) =>
     header.append(aLogBtn)
     aRegBtn.append(regBtn)
     header.append(aRegBtn)
-    let aCabinet = document.createElement('a')
-    aCabinet.href = '#/cabinet'
+    // let aCabinet = document.createElement('a')
+    // aCabinet.href = '#/cabinet'
+    let unlogBtn = document.createElement('button')
+    unlogBtn.style.marginTop = '20px'
+    unlogBtn.style.float = 'right'
+    unlogBtn.innerHTML = "Выйти"
+    unlogBtn.style.marginLeft = '10px'
+    unlogBtn.onclick = () => {
+        let question = confirm ('Вы уверены что хотите выйти?')
+        if (question) {
+             store.dispatch(actionAuthLogout())
+             location.reload()
+        }
+    }
 
     function drawReg() {
         main.innerHTML = ""
@@ -567,13 +579,7 @@ const actionFullLogin = (login , password) => async dispatch => {
     let result = await dispatch(actionPromise("login",log(login,password)))
     if (result.data.login !== null){
     dispatch(actionAuthLogin(result.data.login))
-    logBtn.hidden = true
-    regBtn.hidden = true
-    main.innerHTML = ''
-    let hLog = document.createElement('h1')
-    hLog.innerHTML = "Вы успешно войшли в свой кабинет"
-    hLog.style.textAlign = 'center'
-    main.append(hLog)
+    location.reload()
     }
     else {
         alert ('Такого пользователя не существует или вы не правильно указали логин/пароль')
@@ -586,14 +592,7 @@ actionFullRegister = (login,password) => async dispatch => {
     console.log(result)
     if (result.errors === undefined) {
         await dispatch (actionFullLogin(login,password))
-        logBtn.hidden = true
-        regBtn.hidden = true
-        main.innerHTML = ""
-        let hReg = document.createElement('h1')
-        hReg.innerHTML = "Вы успешно зарегестрированы"
-        hReg.style.textAlign = 'center'
-        main.append(hReg)
-
+        location.reload()
     }
     else { 
         alert("Такой пользователь уже есть")
@@ -601,9 +600,18 @@ actionFullRegister = (login,password) => async dispatch => {
     }
 }
 
+        let pLog = document.createElement('p')
+        pLog.innerHTML = "Ваш логин:" + " " + store.getState().auth.payload.sub.login
+        pLog.style.float = 'right'
+        pLog.style.fontWeight = 'bold'
+        pLog.style.marginTop = '20px'
+        pLog.style.color = '#000080'
+
 if (localStorage.authToken) {
     regBtn.hidden = true
     logBtn.hidden = true
+    header.append(unlogBtn)
+    header.append(pLog)
 }
 
 let newOrder = async(obj) => {