From f36e6c6f8ae2a3cd29a0defdc14a8a79a726cbcb Mon Sep 17 00:00:00 2001 From: Robson Tenorio Date: Sat, 6 May 2023 00:34:38 -0300 Subject: [PATCH] =?UTF-8?q?N=C3=BAmero=20do=20cliente=20trucado=20para=20A?= =?UTF-8?q?tendente=20com=20verifica=C3=A7=C3=A3o=20individual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/controllers/UserController.ts | 2 + .../20230505232700-add-istricked-to-users.ts | 14 ++++++ backend/src/models/User.ts | 4 ++ .../UserServices/CreateUserService.ts | 3 ++ .../services/UserServices/ListUsersService.ts | 1 + .../services/UserServices/ShowUserService.ts | 1 + .../UserServices/UpdateUserService.ts | 3 ++ .../src/components/ContactDrawer/index.js | 4 +- frontend/src/components/ContactModal/index.js | 32 +++++------- frontend/src/pages/Contacts/index.js | 2 +- frontend/src/pages/Users/index.js | 49 +++++++++++++++++-- frontend/src/rules.js | 1 + frontend/src/translate/languages/en.js | 2 + frontend/src/translate/languages/es.js | 4 +- frontend/src/translate/languages/pt.js | 2 + 15 files changed, 97 insertions(+), 27 deletions(-) create mode 100644 backend/src/database/migrations/20230505232700-add-istricked-to-users.ts diff --git a/backend/src/controllers/UserController.ts b/backend/src/controllers/UserController.ts index 342f604c..9de1bd9f 100644 --- a/backend/src/controllers/UserController.ts +++ b/backend/src/controllers/UserController.ts @@ -38,6 +38,7 @@ export const store = async (req: Request, res: Response): Promise => { password, name, profile, + isTricked, queueIds, whatsappId, startWork, @@ -58,6 +59,7 @@ export const store = async (req: Request, res: Response): Promise => { password, name, profile, + isTricked, queueIds, whatsappId, startWork, diff --git a/backend/src/database/migrations/20230505232700-add-istricked-to-users.ts b/backend/src/database/migrations/20230505232700-add-istricked-to-users.ts new file mode 100644 index 00000000..21a0536b --- /dev/null +++ b/backend/src/database/migrations/20230505232700-add-istricked-to-users.ts @@ -0,0 +1,14 @@ +import { QueryInterface, DataTypes } from "sequelize"; + +module.exports = { + up: (queryInterface: QueryInterface) => { + return queryInterface.addColumn("Users", "isTricked", { + type: DataTypes.BOOLEAN, + defaultValue: true + }); + }, + + down: (queryInterface: QueryInterface) => { + return queryInterface.removeColumn("Users", "isTricked"); + } +}; diff --git a/backend/src/models/User.ts b/backend/src/models/User.ts index e3517eba..b0e3e864 100644 --- a/backend/src/models/User.ts +++ b/backend/src/models/User.ts @@ -48,6 +48,10 @@ class User extends Model { @Column profile: string; + @Default(true) + @Column + isTricked: boolean; + @ForeignKey(() => Whatsapp) @Column whatsappId: number; diff --git a/backend/src/services/UserServices/CreateUserService.ts b/backend/src/services/UserServices/CreateUserService.ts index 337d7be7..1c799d98 100644 --- a/backend/src/services/UserServices/CreateUserService.ts +++ b/backend/src/services/UserServices/CreateUserService.ts @@ -10,6 +10,7 @@ interface Request { name: string; queueIds?: number[]; profile?: string; + isTricked?: boolean; whatsappId?: number; startWork?: string; endWork?: string; @@ -28,6 +29,7 @@ const CreateUserService = async ({ name, queueIds = [], profile = "admin", + isTricked, whatsappId, startWork, endWork @@ -63,6 +65,7 @@ const CreateUserService = async ({ password, name, profile, + isTricked, whatsappId: whatsappId || null, startWork, endWork diff --git a/backend/src/services/UserServices/ListUsersService.ts b/backend/src/services/UserServices/ListUsersService.ts index e67d7b56..9cde0b07 100644 --- a/backend/src/services/UserServices/ListUsersService.ts +++ b/backend/src/services/UserServices/ListUsersService.ts @@ -40,6 +40,7 @@ const ListUsersService = async ({ "id", "email", "profile", + "isTricked", "createdAt", "startWork", "endWork" diff --git a/backend/src/services/UserServices/ShowUserService.ts b/backend/src/services/UserServices/ShowUserService.ts index 417386c6..ef059269 100644 --- a/backend/src/services/UserServices/ShowUserService.ts +++ b/backend/src/services/UserServices/ShowUserService.ts @@ -10,6 +10,7 @@ const ShowUserService = async (id: string | number): Promise => { "id", "email", "profile", + "isTricked", "tokenVersion", "whatsappId", "startWork", diff --git a/backend/src/services/UserServices/UpdateUserService.ts b/backend/src/services/UserServices/UpdateUserService.ts index 96875641..75f38f42 100644 --- a/backend/src/services/UserServices/UpdateUserService.ts +++ b/backend/src/services/UserServices/UpdateUserService.ts @@ -9,6 +9,7 @@ interface UserData { password?: string; name?: string; profile?: string; + isTricked?: boolean; queueIds?: number[]; whatsappId?: number; startWork?: string; @@ -44,6 +45,7 @@ const UpdateUserService = async ({ email, password, profile, + isTricked, name, queueIds = [], whatsappId, @@ -61,6 +63,7 @@ const UpdateUserService = async ({ email, password, profile, + isTricked, name, whatsappId: whatsappId || null, startWork, diff --git a/frontend/src/components/ContactDrawer/index.js b/frontend/src/components/ContactDrawer/index.js index b697c602..2e3b5db6 100644 --- a/frontend/src/components/ContactDrawer/index.js +++ b/frontend/src/components/ContactDrawer/index.js @@ -128,8 +128,8 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => { - {user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"} - + {user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"} + {contact.email && ( diff --git a/frontend/src/components/ContactModal/index.js b/frontend/src/components/ContactModal/index.js index ba0f3a48..b3129cfd 100644 --- a/frontend/src/components/ContactModal/index.js +++ b/frontend/src/components/ContactModal/index.js @@ -32,7 +32,6 @@ import api from "../../services/api"; import toastError from "../../errors/toastError"; import * as Yup from "yup"; import { toast } from "react-toastify"; -import { Can } from "../Can"; import { AuthContext } from "../../context/Auth/AuthContext"; const useStyles = makeStyles(theme => ({ @@ -172,24 +171,19 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => { margin="dense" className={classes.textField} /> - ( - <> - - - )} - /> + {user.isTricked ? + + : "" + }
{ {} {contact.name} - {user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"} + {user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"} {contact.email} { if (action.type === "LOAD_USERS") { @@ -103,6 +105,9 @@ const Users = () => { const [confirmModalOpen, setConfirmModalOpen] = useState(false); const [searchParam, setSearchParam] = useState(""); const [users, dispatch] = useReducer(reducer, []); + const [updatingUserId, setUpdatingUserId] = useState(null); + const { user: loggedInUser } = useContext(AuthContext); + const history = useHistory(); useEffect(() => { dispatch({ type: "RESET" }); @@ -190,6 +195,20 @@ const Users = () => { } }; + const handleSwitchChange = async (user, newValue) => { + try { + setUpdatingUserId(user.id); + await api.put(`/users/${user.id}`, { isTricked: newValue }); + dispatch({ type: "UPDATE_USERS", payload: { ...user, isTricked: newValue } }); + toast.success(i18n.t("users.toasts.updated")); + history.go(0); + } catch (err) { + toastError(err); + } + setUpdatingUserId(null); + }; + + return ( { {i18n.t("users.table.profile")} + ( + + {i18n.t("users.table.tricked")} + + )} + /> {i18n.t("users.table.whatsapp")} @@ -279,6 +307,19 @@ const Users = () => { {user.name} {user.email} {user.profile} + ( + + handleSwitchChange(user, e.target.checked)} + /> + + )} + /> {user.whatsapp?.name} {user.startWork} {user.endWork} @@ -302,7 +343,7 @@ const Users = () => { ))} - {loading && } + {loading && } diff --git a/frontend/src/rules.js b/frontend/src/rules.js index 6fde3d42..4ef9b4ea 100644 --- a/frontend/src/rules.js +++ b/frontend/src/rules.js @@ -8,6 +8,7 @@ const rules = { "tickets-manager:showall", "user-modal:editProfile", "user-modal:editQueues", + "user-table:editTricked", "ticket-options:deleteTicket", "ticket-options:transferWhatsapp", "contacts-page:deleteContact", diff --git a/frontend/src/translate/languages/en.js b/frontend/src/translate/languages/en.js index 4a68deb6..4b38a14a 100644 --- a/frontend/src/translate/languages/en.js +++ b/frontend/src/translate/languages/en.js @@ -468,6 +468,7 @@ const messages = { name: "Name", email: "Email", profile: "Profile", + tricked: "View Contacts", whatsapp: "Standard Connection", startWork: "Start time", endWork: "End Time", @@ -478,6 +479,7 @@ const messages = { }, toasts: { deleted: "Attendant deleted successfully.", + updated: "Attendant updated successfully." }, confirmationModal: { deleteTitle: "Delete", diff --git a/frontend/src/translate/languages/es.js b/frontend/src/translate/languages/es.js index 3df20b9c..96250b48 100644 --- a/frontend/src/translate/languages/es.js +++ b/frontend/src/translate/languages/es.js @@ -468,6 +468,7 @@ const messages = { name: "Nombre", email: "Correo electrónico", profile: "Perfil", + tricked: "Ver contactos", whatsapp: "Conexión estándar", startWork: "Hora de inicio", endWork: "Tiempo de finalización", @@ -477,7 +478,8 @@ const messages = { add: "Agregar asistente", }, toasts: { - deleted: "asistente eliminado con éxito.", + deleted: "Asistente eliminado con éxito.", + updated: "Asistente actualizado con éxito." }, confirmationModal: { deleteTitle: "Eliminar", diff --git a/frontend/src/translate/languages/pt.js b/frontend/src/translate/languages/pt.js index a47dd7f2..7173d4e6 100644 --- a/frontend/src/translate/languages/pt.js +++ b/frontend/src/translate/languages/pt.js @@ -469,6 +469,7 @@ const messages = { name: "Nome", email: "E-mail", profile: "Perfil", + tricked: "Visualizar Contatos", whatsapp: "Conexão Padrão", startWork: "Horário inicial", endWork: "Horário final", @@ -479,6 +480,7 @@ const messages = { }, toasts: { deleted: "Atendente excluído com sucesso.", + updated: "Atendente atualizado com sucesso." }, confirmationModal: { deleteTitle: "Excluir",