mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
improvement: better error handling
This commit is contained in:
@@ -43,23 +43,22 @@ exports.store = async (req, res) => {
|
|||||||
const io = getIO();
|
const io = getIO();
|
||||||
const newContact = req.body;
|
const newContact = req.body;
|
||||||
|
|
||||||
let isValidNumber;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
isValidNumber = await wbot.isRegisteredUser(`${newContact.number}@c.us`);
|
const isValidNumber = await wbot.isRegisteredUser(
|
||||||
|
`${newContact.number}@c.us`
|
||||||
|
);
|
||||||
|
if (!isValidNumber) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ error: "The suplied number is not a valid Whatsapp number" });
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Could not check whatsapp contact. Is session details valid?");
|
console.log(err);
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
error: "Could not check whatsapp contact. Check connection page.",
|
error: "Could not check whatsapp contact. Check connection page.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidNumber) {
|
|
||||||
return res
|
|
||||||
.status(400)
|
|
||||||
.json({ error: "The suplied number is not a valid Whatsapp number" });
|
|
||||||
}
|
|
||||||
|
|
||||||
const profilePicUrl = await wbot.getProfilePicUrl(
|
const profilePicUrl = await wbot.getProfilePicUrl(
|
||||||
`${newContact.number}@c.us`
|
`${newContact.number}@c.us`
|
||||||
);
|
);
|
||||||
@@ -76,26 +75,22 @@ exports.store = async (req, res) => {
|
|||||||
contact: contact,
|
contact: contact,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json(contact);
|
return res.status(200).json(contact);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.show = async (req, res) => {
|
exports.show = async (req, res) => {
|
||||||
const { contactId } = req.params;
|
const { contactId } = req.params;
|
||||||
|
|
||||||
const { id, name, number, email, extraInfo } = await Contact.findByPk(
|
const contact = await Contact.findByPk(contactId, {
|
||||||
contactId,
|
include: "extraInfo",
|
||||||
{
|
attributes: ["id", "name", "number", "email"],
|
||||||
include: "extraInfo",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
res.status(200).json({
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
number,
|
|
||||||
email,
|
|
||||||
extraInfo,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!contact) {
|
||||||
|
return res.status(404).json({ error: "No contact found with this id." });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json(contact);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = async (req, res) => {
|
exports.update = async (req, res) => {
|
||||||
@@ -110,7 +105,7 @@ exports.update = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
return res.status(400).json({ error: "No contact found with this ID" });
|
return res.status(404).json({ error: "No contact found with this ID" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updatedContact.extraInfo) {
|
if (updatedContact.extraInfo) {
|
||||||
@@ -140,7 +135,7 @@ exports.update = async (req, res) => {
|
|||||||
contact: contact,
|
contact: contact,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json(contact);
|
return res.status(200).json(contact);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.delete = async (req, res) => {
|
exports.delete = async (req, res) => {
|
||||||
@@ -150,7 +145,7 @@ exports.delete = async (req, res) => {
|
|||||||
const contact = await Contact.findByPk(contactId);
|
const contact = await Contact.findByPk(contactId);
|
||||||
|
|
||||||
if (!contact) {
|
if (!contact) {
|
||||||
return res.status(400).json({ error: "No contact found with this ID" });
|
return res.status(404).json({ error: "No contact found with this ID" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await contact.destroy();
|
await contact.destroy();
|
||||||
@@ -160,5 +155,5 @@ exports.delete = async (req, res) => {
|
|||||||
contactId: contactId,
|
contactId: contactId,
|
||||||
});
|
});
|
||||||
|
|
||||||
res.status(200).json({ message: "Contact deleted" });
|
return res.status(200).json({ message: "Contact deleted" });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,16 @@ exports.store = async (req, res, next) => {
|
|||||||
const io = getIO();
|
const io = getIO();
|
||||||
const wbot = getWbot();
|
const wbot = getWbot();
|
||||||
|
|
||||||
const phoneContacts = await wbot.getContacts();
|
let phoneContacts;
|
||||||
|
|
||||||
|
try {
|
||||||
|
phoneContacts = await wbot.getContacts();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
return res.status(500).json({
|
||||||
|
error: "Could not check whatsapp contact. Check connection page.",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
phoneContacts.map(async ({ number, name }) => {
|
phoneContacts.map(async ({ number, name }) => {
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ const setMessagesAsRead = async ticket => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.index = async (req, res, next) => {
|
exports.index = async (req, res, next) => {
|
||||||
// const wbot = getWbot();
|
|
||||||
// const io = getIO();
|
|
||||||
|
|
||||||
const { ticketId } = req.params;
|
const { ticketId } = req.params;
|
||||||
const { searchParam = "", pageNumber = 1 } = req.query;
|
const { searchParam = "", pageNumber = 1 } = req.query;
|
||||||
|
|
||||||
@@ -125,6 +122,10 @@ exports.store = async (req, res, next) => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!ticket) {
|
||||||
|
return res.status(404).json({ error: "No ticket found with this ID" });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (media) {
|
if (media) {
|
||||||
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
const newMedia = MessageMedia.fromFilePath(req.file.path);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ exports.store = async (req, res, next) => {
|
|||||||
|
|
||||||
const user = await User.findOne({ where: { email: email } });
|
const user = await User.findOne({ where: { email: email } });
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return res.status(401).json({ error: "No user found with this email" });
|
return res.status(404).json({ error: "No user found with this email" });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(await user.checkPassword(password))) {
|
if (!(await user.checkPassword(password))) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ exports.update = async (req, res) => {
|
|||||||
const setting = await Setting.findByPk(settingKey);
|
const setting = await Setting.findByPk(settingKey);
|
||||||
|
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
return res.status(400).json({ error: "No setting found with this ID" });
|
return res.status(404).json({ error: "No setting found with this ID" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await setting.update(req.body);
|
await setting.update(req.body);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ exports.index = async (req, res) => {
|
|||||||
|
|
||||||
const hasMore = count > offset + tickets.length;
|
const hasMore = count > offset + tickets.length;
|
||||||
|
|
||||||
return res.json({ count, tickets, hasMore });
|
return res.status(200).json({ count, tickets, hasMore });
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.store = async (req, res) => {
|
exports.store = async (req, res) => {
|
||||||
@@ -139,7 +139,7 @@ exports.update = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!ticket) {
|
if (!ticket) {
|
||||||
return res.status(400).json({ error: "No ticket found with this ID" });
|
return res.status(404).json({ error: "No ticket found with this ID" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await ticket.update(req.body);
|
await ticket.update(req.body);
|
||||||
|
|||||||
@@ -71,7 +71,11 @@ exports.store = async (req, res, next) => {
|
|||||||
.json({ error: "Only administrators can create users." });
|
.json({ error: "Only administrators can create users." });
|
||||||
}
|
}
|
||||||
|
|
||||||
await schema.validate(req.body);
|
try {
|
||||||
|
await schema.validate(req.body);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(400).json({ error: err.message });
|
||||||
|
}
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|
||||||
@@ -88,14 +92,15 @@ exports.store = async (req, res, next) => {
|
|||||||
exports.show = async (req, res) => {
|
exports.show = async (req, res) => {
|
||||||
const { userId } = req.params;
|
const { userId } = req.params;
|
||||||
|
|
||||||
const { id, name, email, profile } = await User.findByPk(userId);
|
const user = await User.findByPk(userId, {
|
||||||
|
attributes: ["id", "name", "email", "profile"],
|
||||||
return res.status(200).json({
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
profile,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
res.status(400).json({ error: "No user found with this id." });
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.status(200).json(user);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.update = async (req, res) => {
|
exports.update = async (req, res) => {
|
||||||
@@ -121,7 +126,7 @@ exports.update = async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
res.status(400).json({ error: "No user found with this id." });
|
res.status(404).json({ error: "No user found with this id." });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.profile === "admin" && req.body.profile === "user") {
|
if (user.profile === "admin" && req.body.profile === "user") {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ exports.delete = async (req, res) => {
|
|||||||
const dbSession = await Whatsapp.findByPk(sessionId);
|
const dbSession = await Whatsapp.findByPk(sessionId);
|
||||||
|
|
||||||
if (!dbSession) {
|
if (!dbSession) {
|
||||||
return res.status(200).json({ message: "Session not found" });
|
return res.status(404).json({ message: "Session not found" });
|
||||||
}
|
}
|
||||||
|
|
||||||
await dbSession.update({ session: "", status: "pending" });
|
await dbSession.update({ session: "", status: "pending" });
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkInsert(
|
|
||||||
"Contacts",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
name: "Joana Doe",
|
|
||||||
profilePicUrl:
|
|
||||||
"https://images.unsplash.com/photo-1494790108377-be9c29b29330?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1834&q=80",
|
|
||||||
number: 5512345678,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "John Rulles",
|
|
||||||
profilePicUrl:
|
|
||||||
"https://images.unsplash.com/photo-1500648767791-00dcc994a43e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80",
|
|
||||||
number: 5512345679,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Jonas Jhones",
|
|
||||||
profilePicUrl:
|
|
||||||
"https://images.unsplash.com/photo-1531427186611-ecfd6d936c79?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=634&q=80",
|
|
||||||
number: 5512345680,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Julie June",
|
|
||||||
profilePicUrl:
|
|
||||||
"https://images.unsplash.com/photo-1493666438817-866a91353ca9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1049&q=80",
|
|
||||||
number: 5512345681,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkDelete("Contacts", null, {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,261 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkInsert(
|
|
||||||
"Tickets",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 3,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 4,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 2,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
status: "pending",
|
|
||||||
lastMessage: "hello!",
|
|
||||||
contactId: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkDelete("Tickets", null, {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -1,148 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
up: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkInsert(
|
|
||||||
"Messages",
|
|
||||||
[
|
|
||||||
{
|
|
||||||
id: "12312321342",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 1,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321313",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 1,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321314",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 1,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321315",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 1,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321316",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 5,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321355",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 5,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321318",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 5,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321319",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 5,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321399",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 11,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321391",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 11,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321392",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 3,
|
|
||||||
ticketId: 11,
|
|
||||||
fromMe: true,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "12312321393",
|
|
||||||
body:
|
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.",
|
|
||||||
ack: 0,
|
|
||||||
ticketId: 11,
|
|
||||||
fromMe: false,
|
|
||||||
read: 1,
|
|
||||||
createdAt: new Date(),
|
|
||||||
updatedAt: new Date(),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
},
|
|
||||||
|
|
||||||
down: (queryInterface, Sequelize) => {
|
|
||||||
return queryInterface.bulkDelete("Messages", null, {});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
|
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import { Formik, FieldArray, Form, Field } from "formik";
|
import { Formik, FieldArray, Form, Field } from "formik";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { green } from "@material-ui/core/colors";
|
import { green } from "@material-ui/core/colors";
|
||||||
@@ -76,8 +77,15 @@ const ContactModal = ({ open, onClose, contactId }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchContact = async () => {
|
const fetchContact = async () => {
|
||||||
if (!contactId) return;
|
if (!contactId) return;
|
||||||
const res = await api.get(`/contacts/${contactId}`);
|
try {
|
||||||
setContact(res.data);
|
const { data } = await api.get(`/contacts/${contactId}`);
|
||||||
|
setContact(data);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchContact();
|
fetchContact();
|
||||||
@@ -95,9 +103,12 @@ const ContactModal = ({ open, onClose, contactId }) => {
|
|||||||
} else {
|
} else {
|
||||||
await api.post("/contacts", values);
|
await api.post("/contacts", values);
|
||||||
}
|
}
|
||||||
|
toast.success("Contact saved sucessfully!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(JSON.stringify(err.response.data, null, 2));
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
@@ -131,6 +142,7 @@ const ContactModal = ({ open, onClose, contactId }) => {
|
|||||||
as={TextField}
|
as={TextField}
|
||||||
label={i18n.t("contactModal.form.name")}
|
label={i18n.t("contactModal.form.name")}
|
||||||
name="name"
|
name="name"
|
||||||
|
autoFocus
|
||||||
error={touched.name && Boolean(errors.name)}
|
error={touched.name && Boolean(errors.name)}
|
||||||
helperText={touched.name && errors.name}
|
helperText={touched.name && errors.name}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
import "emoji-mart/css/emoji-mart.css";
|
import "emoji-mart/css/emoji-mart.css";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Picker } from "emoji-mart";
|
import { Picker } from "emoji-mart";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
import MicRecorder from "mic-recorder-to-mp3";
|
import MicRecorder from "mic-recorder-to-mp3";
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
@@ -163,8 +164,10 @@ const MessageInput = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err.response.data.error);
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setMedia(mediaInitialState);
|
setMedia(mediaInitialState);
|
||||||
@@ -182,8 +185,10 @@ const MessageInput = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, message);
|
await api.post(`/messages/${ticketId}`, message);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err.response.data.error);
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setInputMessage("");
|
setInputMessage("");
|
||||||
setShowEmoji(false);
|
setShowEmoji(false);
|
||||||
@@ -224,8 +229,10 @@ const MessageInput = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err.response.data.error);
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setRecording(false);
|
setRecording(false);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -303,8 +303,12 @@ const MessagesList = () => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
toast.error("Ticket não encontrado");
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
history.push("/tickets");
|
toast.error(err.response.data.error);
|
||||||
|
if (err.response.status === 404) {
|
||||||
|
history.push("/tickets");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMessages();
|
fetchMessages();
|
||||||
@@ -417,6 +421,9 @@ const MessagesList = () => {
|
|||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
history.push("/tickets");
|
history.push("/tickets");
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@@ -38,7 +39,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
|
const NewTicketModal = ({ modalOpen, onClose }) => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const userId = +localStorage.getItem("userId");
|
const userId = +localStorage.getItem("userId");
|
||||||
@@ -54,18 +55,21 @@ const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
|
|||||||
const delayDebounceFn = setTimeout(() => {
|
const delayDebounceFn = setTimeout(() => {
|
||||||
const fetchContacts = async () => {
|
const fetchContacts = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await api.get("contacts", {
|
const { data } = await api.get("contacts", {
|
||||||
params: { searchParam, rowsPerPage: 20 },
|
params: { searchParam },
|
||||||
});
|
});
|
||||||
setOptions(res.data.contacts);
|
setOptions(data.contacts);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchContacts();
|
fetchContacts();
|
||||||
}, 1000);
|
}, 500);
|
||||||
return () => clearTimeout(delayDebounceFn);
|
return () => clearTimeout(delayDebounceFn);
|
||||||
}, [searchParam, modalOpen]);
|
}, [searchParam, modalOpen]);
|
||||||
|
|
||||||
@@ -87,7 +91,10 @@ const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
|
|||||||
});
|
});
|
||||||
history.push(`/tickets/${ticket.id}`);
|
history.push(`/tickets/${ticket.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
handleClose();
|
handleClose();
|
||||||
@@ -107,13 +114,14 @@ const NewTicketModal = ({ modalOpen, onClose, contactId }) => {
|
|||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
id="asynchronous-demo"
|
id="contacts-finder"
|
||||||
style={{ width: 300 }}
|
style={{ width: 300 }}
|
||||||
getOptionLabel={option => `${option.name} - ${option.number}`}
|
getOptionLabel={option => `${option.name} - ${option.number}`}
|
||||||
onChange={(e, newValue) => {
|
onChange={(e, newValue) => {
|
||||||
setSelectedContact(newValue);
|
setSelectedContact(newValue);
|
||||||
}}
|
}}
|
||||||
options={options}
|
options={options}
|
||||||
|
noOptionsText="No contacts found. Try another term."
|
||||||
loading={loading}
|
loading={loading}
|
||||||
renderInput={params => (
|
renderInput={params => (
|
||||||
<TextField
|
<TextField
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React from "react";
|
|||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import { format, parseISO } from "date-fns";
|
import { format, parseISO } from "date-fns";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
@@ -12,6 +13,9 @@ const SessionInfo = ({ session }) => {
|
|||||||
await api.delete("/whatsapp/session/1");
|
await api.delete("/whatsapp/session/1");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
|
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import { Formik, Form, Field } from "formik";
|
import { Formik, Form, Field } from "formik";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { green } from "@material-ui/core/colors";
|
import { green } from "@material-ui/core/colors";
|
||||||
@@ -76,10 +77,17 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUser = async () => {
|
const fetchUser = async () => {
|
||||||
if (!userId) return;
|
if (!userId) return;
|
||||||
const { data } = await api.get(`/users/${userId}`);
|
try {
|
||||||
setUser(prevState => {
|
const { data } = await api.get(`/users/${userId}`);
|
||||||
return { ...prevState, ...data };
|
setUser(prevState => {
|
||||||
});
|
return { ...prevState, ...data };
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchUser();
|
fetchUser();
|
||||||
@@ -97,9 +105,12 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
} else {
|
} else {
|
||||||
await api.post("/users", values);
|
await api.post("/users", values);
|
||||||
}
|
}
|
||||||
|
toast.success("Success!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(JSON.stringify(err.response.data, null, 2));
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
@@ -127,6 +138,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
<Field
|
<Field
|
||||||
as={TextField}
|
as={TextField}
|
||||||
label="Name"
|
label="Name"
|
||||||
|
autoFocus
|
||||||
name="name"
|
name="name"
|
||||||
error={touched.name && Boolean(errors.name)}
|
error={touched.name && Boolean(errors.name)}
|
||||||
helperText={touched.name && errors.name}
|
helperText={touched.name && errors.name}
|
||||||
|
|||||||
@@ -35,7 +35,10 @@ const useAuth = () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setIsAuth(false);
|
setIsAuth(false);
|
||||||
toast.error(i18n.t("auth.toasts.fail"));
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
checkAuth();
|
checkAuth();
|
||||||
@@ -53,7 +56,10 @@ const useAuth = () => {
|
|||||||
toast.success(i18n.t("auth.toasts.success"));
|
toast.success(i18n.t("auth.toasts.success"));
|
||||||
history.push("/tickets");
|
history.push("/tickets");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error(i18n.t("auth.toasts.fail"));
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect, useReducer } from "react";
|
import { useState, useEffect, useReducer } from "react";
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
|
||||||
@@ -97,6 +98,9 @@ const useTickets = ({ searchParam, pageNumber, status, date, showAll }) => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchTickets();
|
fetchTickets();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
|
||||||
@@ -46,6 +47,9 @@ const WhatsAuth = () => {
|
|||||||
setSession(data);
|
setSession(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import React, { useState, useEffect, useReducer } from "react";
|
import React, { useState, useEffect, useReducer } from "react";
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import Table from "@material-ui/core/Table";
|
import Table from "@material-ui/core/Table";
|
||||||
@@ -114,7 +115,9 @@ const Contacts = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
alert(err);
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchContacts();
|
fetchContacts();
|
||||||
@@ -161,8 +164,12 @@ const Contacts = () => {
|
|||||||
const handleDeleteContact = async contactId => {
|
const handleDeleteContact = async contactId => {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/contacts/${contactId}`);
|
await api.delete(`/contacts/${contactId}`);
|
||||||
|
toast.success("Contact deleted sucessfully!");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
setDeletingContact(null);
|
setDeletingContact(null);
|
||||||
setSearchParam("");
|
setSearchParam("");
|
||||||
@@ -172,8 +179,10 @@ const Contacts = () => {
|
|||||||
const handleimportContact = async () => {
|
const handleimportContact = async () => {
|
||||||
try {
|
try {
|
||||||
await api.post("/contacts/import");
|
await api.post("/contacts/import");
|
||||||
|
window.location.reload(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
window.location.reload(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ const Settings = () => {
|
|||||||
setSettings(data);
|
setSettings(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
@@ -77,14 +80,16 @@ const Settings = () => {
|
|||||||
});
|
});
|
||||||
toast.success("Setting updated");
|
toast.success("Setting updated");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSettingValue = key => {
|
const getSettingValue = key => {
|
||||||
const setting = settings.find(s => s.key === key);
|
const { value } = settings.find(s => s.key === key);
|
||||||
return setting.value;
|
return value;
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -78,7 +78,10 @@ const SignUp = () => {
|
|||||||
toast.success(i18n.t("signup.toasts.success"));
|
toast.success(i18n.t("signup.toasts.success"));
|
||||||
history.push("/login");
|
history.push("/login");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error(i18n.t("signup.toasts.fail"));
|
console.log(err);
|
||||||
|
if (err.response && err.response.data && err.response.data.error) {
|
||||||
|
toast.error(err.response.data.error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user