2020-07-15 01:26:08 +03:00
|
|
|
export const dispatchCustomEvent = ({ name, detail }) => {
|
|
|
|
let event = new CustomEvent(name, { detail });
|
|
|
|
window.dispatchEvent(event);
|
|
|
|
};
|
2020-11-22 00:25:40 +03:00
|
|
|
|
2020-11-28 04:54:42 +03:00
|
|
|
export const hasError = (response) => {
|
2020-11-22 00:25:40 +03:00
|
|
|
if (!response) {
|
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
message: "We're having trouble connecting right now. Please try again later",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-01-14 09:30:26 +03:00
|
|
|
console.log(response);
|
2020-11-22 00:25:40 +03:00
|
|
|
return true;
|
2020-11-28 07:39:01 +03:00
|
|
|
} else if (response.error) {
|
2020-11-22 00:25:40 +03:00
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
decorator: response.decorator,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2021-01-14 09:30:26 +03:00
|
|
|
console.log(response);
|
2020-11-22 00:25:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
2020-11-28 07:39:01 +03:00
|
|
|
export const dispatchMessage = ({ message, decorator, status }) => {
|
2020-11-22 00:25:40 +03:00
|
|
|
if (decorator) {
|
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
decorator,
|
2020-11-28 07:39:01 +03:00
|
|
|
status,
|
2020-11-22 00:25:40 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else if (message) {
|
|
|
|
dispatchCustomEvent({
|
|
|
|
name: "create-alert",
|
|
|
|
detail: {
|
|
|
|
alert: {
|
|
|
|
message,
|
2020-11-28 07:39:01 +03:00
|
|
|
status,
|
2020-11-22 00:25:40 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|