|
@@ -211,7 +211,7 @@ const gql = (url, query, variables) => fetch(url, {
|
|
|
}).then(res => res.json())
|
|
|
|
|
|
const backendURL = 'http://shop-roles.node.ed.asmer.org.ua'
|
|
|
-const graphQLBackendUrl = `${backendURL}/graphql`
|
|
|
+const graphQLBackendUrl = `${backendURL}/graphql`
|
|
|
|
|
|
|
|
|
const actionRootCats = () =>
|
|
@@ -249,18 +249,21 @@ const actionLogin = (login, password) =>
|
|
|
, { login, password }))
|
|
|
|
|
|
|
|
|
- /* actionPromise(
|
|
|
- "register",
|
|
|
- gql(
|
|
|
- `mutation register($login: String, $password: String) {
|
|
|
+const actionRegister = (login, password) =>
|
|
|
+ actionPromise(
|
|
|
+ "register",
|
|
|
+ gql(graphQLBackendUrl,
|
|
|
+ `mutation register($login: String, $password: String) {
|
|
|
UserUpsert(user: {login: $login, password: $password}) {
|
|
|
_id
|
|
|
login
|
|
|
}
|
|
|
}`,
|
|
|
- { login: login, password: password }
|
|
|
- )
|
|
|
- ) */
|
|
|
+ { login: login, password: password }
|
|
|
+ )
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
store.dispatch(actionRootCats())
|
|
@@ -295,14 +298,14 @@ const updateCartInfo = () => {
|
|
|
cartProductsContainer.append(ul)
|
|
|
|
|
|
const clearFromCartButton = document.createElement('button')
|
|
|
- clearFromCartButton.innerHTML = "Очистить"
|
|
|
- clearFromCartButton.onclick = () => { store.dispatch(cartClear())}
|
|
|
- cartProductsContainer.append(clearFromCartButton)
|
|
|
+ clearFromCartButton.innerHTML = "Очистить"
|
|
|
+ clearFromCartButton.onclick = () => { store.dispatch(cartClear()) }
|
|
|
+ cartProductsContainer.append(clearFromCartButton)
|
|
|
|
|
|
const buyGoods = document.createElement('button')
|
|
|
- buyGoods.innerHTML = "Купить"
|
|
|
- buyGoods.onclick = () => {store.dispatch(cartClear()), alert('Спасибо за покупку!')}
|
|
|
- cartProductsContainer.append(buyGoods)
|
|
|
+ buyGoods.innerHTML = "Купить"
|
|
|
+ buyGoods.onclick = () => { store.dispatch(cartClear()), alert('Спасибо за покупку!') }
|
|
|
+ cartProductsContainer.append(buyGoods)
|
|
|
|
|
|
for (const [key, value] of Object.entries(cart)) {
|
|
|
const li = document.createElement('li')
|
|
@@ -310,7 +313,7 @@ const updateCartInfo = () => {
|
|
|
const removeFromCartButton = document.createElement('button')
|
|
|
removeFromCartButton.innerText = "-"
|
|
|
removeFromCartButton.onclick = () => { store.dispatch(cartRemove(value.good)) }
|
|
|
-
|
|
|
+
|
|
|
a.innerHTML = value.good.name;
|
|
|
ul.append(li)
|
|
|
li.append(a)
|
|
@@ -329,14 +332,14 @@ const updateCartInfo = () => {
|
|
|
|
|
|
const deleteFromCartButton = document.createElement('button')
|
|
|
deleteFromCartButton.innerHTML = "-1"
|
|
|
- deleteFromCartButton.onclick = () => { store.dispatch(cartDelete(value.good))}
|
|
|
+ deleteFromCartButton.onclick = () => { store.dispatch(cartDelete(value.good)) }
|
|
|
ul.append(deleteFromCartButton)
|
|
|
- }
|
|
|
+ }
|
|
|
const allCountElement = document.createElement('p');
|
|
|
allCountElement.innerHTML = `Total: ${value.count}`;
|
|
|
ul.append(allCountElement)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
};
|
|
|
|
|
|
enterCart.onclick = () => {
|
|
@@ -359,6 +362,19 @@ function handleLogin() {
|
|
|
outLogin.click();
|
|
|
}
|
|
|
|
|
|
+const registerBtn = document.getElementById('registerBtn');
|
|
|
+
|
|
|
+registerBtn.onclick = handleRegister
|
|
|
+
|
|
|
+function handleRegister() {
|
|
|
+ let userName = document.getElementById('inputUserNameRegister')
|
|
|
+ let userPassword = document.getElementById('inputPasswordRegister')
|
|
|
+ store.dispatch(actionRegister(userName.value, userPassword.value));
|
|
|
+ return hideLogin.style.display = 'block', registerContainer.style.display = 'none'
|
|
|
+ outLogin.click();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
/* store.dispatch(actionLogin('levshin95', '123123')) */
|
|
|
|
|
@@ -455,7 +471,7 @@ store.subscribe(() => {
|
|
|
const goodById = store.getState().promise.goodById?.payload?.data.GoodFindOne
|
|
|
const [, route] = location.hash.split('/')
|
|
|
if (goodById && route === 'good') {
|
|
|
- const { name, description, _id, price, images} = goodById
|
|
|
+ const { name, description, _id, price, images } = goodById
|
|
|
categories.innerHTML = `<h1>${name}</h1>`
|
|
|
|
|
|
const strongPrice = document.createElement('b')
|
|
@@ -494,6 +510,12 @@ window.onhashchange = () => {
|
|
|
},
|
|
|
good() {
|
|
|
store.dispatch(actionGoodById(_id))
|
|
|
+ },
|
|
|
+ login() {
|
|
|
+ console.log('Тут надо нарисовать форму логина. по нажатию кнопки в ней - задиспатчить actionFullLogin')
|
|
|
+ },
|
|
|
+ register() {
|
|
|
+ console.log('Тут надо нарисовать форму логина/регистрации. по нажатию кнопки в ней - задиспатчить actionFullRegister')
|
|
|
}
|
|
|
}
|
|
|
if (route in routes) {
|