digital-store/src/main/components/orders.component.js
2020-01-20 20:47:30 +03:00

43 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Component } from "../core/component";
import axios from "axios";
export class OrdersComponent extends Component {
constructor(id, {notification}, {loader}) {
super(id);
this.notification = notification;
this.loader = loader;
}
init() {
if (this.$el) {
let valid = true;
this.$el.querySelector('form').onsubmit = async (e) => {
e.preventDefault();
if (valid) {
valid = false;
this.loader.show();
const email = e.target.elements.email.value,
request = await axios.post('/my-orders', {email});
switch (request.data.status) {
case 'OK':
this.notification.notificate(`Данные были успешно высланы на почту "${email}".`, '#26A69A', 3500);
break;
case 'NF':
this.notification.notificate(`Покупатель с почтой "${email}" не был найден.`, '#f44336', 3500);
break;
case 'ERR':
this.notification.notificate(`Произошла ошибка, попробуйте повторить запрос позже.`, '#f44336', 3500);
break;
default:
break;
}
this.loader.hide();
setTimeout(() => valid = true, 10000);
} else {
this.notification.notificate(`Подождите еще нескольно секунд прежде чем сделать запрос...`, '#f44336', 3500);
}
};
}
}
}