Skip to content

Commit

Permalink
Número do cliente trucado para Atendente com verificação individual
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed May 6, 2023
1 parent f1cf52d commit f36e6c6
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 27 deletions.
2 changes: 2 additions & 0 deletions backend/src/controllers/UserController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
password,
name,
profile,
isTricked,
queueIds,
whatsappId,
startWork,
Expand All @@ -58,6 +59,7 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
password,
name,
profile,
isTricked,
queueIds,
whatsappId,
startWork,
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
};
4 changes: 4 additions & 0 deletions backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ class User extends Model<User> {
@Column
profile: string;

@Default(true)
@Column
isTricked: boolean;

@ForeignKey(() => Whatsapp)
@Column
whatsappId: number;
Expand Down
3 changes: 3 additions & 0 deletions backend/src/services/UserServices/CreateUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Request {
name: string;
queueIds?: number[];
profile?: string;
isTricked?: boolean;
whatsappId?: number;
startWork?: string;
endWork?: string;
Expand All @@ -28,6 +29,7 @@ const CreateUserService = async ({
name,
queueIds = [],
profile = "admin",
isTricked,
whatsappId,
startWork,
endWork
Expand Down Expand Up @@ -63,6 +65,7 @@ const CreateUserService = async ({
password,
name,
profile,
isTricked,
whatsappId: whatsappId || null,
startWork,
endWork
Expand Down
1 change: 1 addition & 0 deletions backend/src/services/UserServices/ListUsersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const ListUsersService = async ({
"id",
"email",
"profile",
"isTricked",
"createdAt",
"startWork",
"endWork"
Expand Down
1 change: 1 addition & 0 deletions backend/src/services/UserServices/ShowUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const ShowUserService = async (id: string | number): Promise<User> => {
"id",
"email",
"profile",
"isTricked",
"tokenVersion",
"whatsappId",
"startWork",
Expand Down
3 changes: 3 additions & 0 deletions backend/src/services/UserServices/UpdateUserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface UserData {
password?: string;
name?: string;
profile?: string;
isTricked?: boolean;
queueIds?: number[];
whatsappId?: number;
startWork?: string;
Expand Down Expand Up @@ -44,6 +45,7 @@ const UpdateUserService = async ({
email,
password,
profile,
isTricked,
name,
queueIds = [],
whatsappId,
Expand All @@ -61,6 +63,7 @@ const UpdateUserService = async ({
email,
password,
profile,
isTricked,
name,
whatsappId: whatsappId || null,
startWork,
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ContactDrawer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ const ContactDrawer = ({ open, handleDrawerClose, contact, loading }) => {
<CopyToClipboard content={contact.name} color="secondary" />
</Typography>
<Typography>
<Link href={`tel:${user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"}`}>{user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"}</Link>
<CopyToClipboard content={user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"} color="secondary" />
<Link href={`tel:${user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"}`}>{user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"}</Link>
<CopyToClipboard content={user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"} color="secondary" />
</Typography>
{contact.email && (
<Typography>
Expand Down
32 changes: 13 additions & 19 deletions frontend/src/components/ContactModal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => ({
Expand Down Expand Up @@ -172,24 +171,19 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => {
margin="dense"
className={classes.textField}
/>
<Can
role={user.profile}
perform="drawer-admin-items:view"
yes={() => (
<>
<Field
as={TextField}
label={i18n.t("contactModal.form.number")}
name="number"
error={touched.number && Boolean(errors.number)}
helperText={touched.number && errors.number}
placeholder="5522999999999"
variant="outlined"
margin="dense"
/>
</>
)}
/>
{user.isTricked ?
<Field
as={TextField}
label={i18n.t("contactModal.form.number")}
name="number"
error={touched.number && Boolean(errors.number)}
helperText={touched.number && errors.number}
placeholder="5522999999999"
variant="outlined"
margin="dense"
/>
: ""
}
<div>
<Field
as={TextField}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Contacts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ const Contacts = () => {
{<Avatar src={contact.profilePicUrl} className={classes.avatar} />}
</TableCell>
<TableCell>{contact.name}</TableCell>
<TableCell align="center">{user.profile === "admin" ? contact.number : contact.number.slice(0,-4) + "****"}</TableCell>
<TableCell align="center">{user.isTricked ? contact.number : contact.number.slice(0,-4) + "****"}</TableCell>
<TableCell align="center">{contact.email}</TableCell>
<TableCell align="center">
<IconButton
Expand Down
49 changes: 45 additions & 4 deletions frontend/src/pages/Users/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useState, useEffect, useReducer } from "react";
import React, { useState, useEffect, useReducer, useContext } from "react";
import { toast } from "react-toastify";
import openSocket from "../../services/socket-io";

import { useHistory } from "react-router-dom";
import { makeStyles } from "@material-ui/core/styles";

import {
Button,
IconButton,
InputAdornment,
Paper,
Switch,
Table,
TableBody,
TableCell,
Expand All @@ -32,10 +33,11 @@ import Title from "../../components/Title";
import TableRowSkeleton from "../../components/TableRowSkeleton";
import UserModal from "../../components/UserModal";
import ConfirmationModal from "../../components/ConfirmationModal";

import { AuthContext } from "../../context/Auth/AuthContext";
import api from "../../services/api";
import { i18n } from "../../translate/i18n";
import toastError from "../../errors/toastError";
import { Can } from "../../components/Can";

const reducer = (state, action) => {
if (action.type === "LOAD_USERS") {
Expand Down Expand Up @@ -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" });
Expand Down Expand Up @@ -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 (
<MainContainer>
<ConfirmationModal
Expand Down Expand Up @@ -257,6 +276,15 @@ const Users = () => {
<TableCell align="center">
{i18n.t("users.table.profile")}
</TableCell>
<Can
role={loggedInUser.profile}
perform="user-table:editTricked"
yes={() => (
<TableCell align="center">
{i18n.t("users.table.tricked")}
</TableCell>
)}
/>
<TableCell align="center">
{i18n.t("users.table.whatsapp")}
</TableCell>
Expand All @@ -279,6 +307,19 @@ const Users = () => {
<TableCell align="center">{user.name}</TableCell>
<TableCell align="center">{user.email}</TableCell>
<TableCell align="center">{user.profile}</TableCell>
<Can
role={loggedInUser.profile}
perform="user-table:editTricked"
yes={() => (
<TableCell align="center">
<Switch
checked={user.isTricked}
disabled={updatingUserId === user.id}
onChange={(e) => handleSwitchChange(user, e.target.checked)}
/>
</TableCell>
)}
/>
<TableCell align="center">{user.whatsapp?.name}</TableCell>
<TableCell align="center">{user.startWork}</TableCell>
<TableCell align="center">{user.endWork}</TableCell>
Expand All @@ -302,7 +343,7 @@ const Users = () => {
</TableCell>
</TableRow>
))}
{loading && <TableRowSkeleton columns={7} />}
{loading && <TableRowSkeleton columns={9} />}
</>
</TableBody>
</Table>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ const messages = {
name: "Name",
email: "Email",
profile: "Profile",
tricked: "View Contacts",
whatsapp: "Standard Connection",
startWork: "Start time",
endWork: "End Time",
Expand All @@ -478,6 +479,7 @@ const messages = {
},
toasts: {
deleted: "Attendant deleted successfully.",
updated: "Attendant updated successfully."
},
confirmationModal: {
deleteTitle: "Delete",
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -479,6 +480,7 @@ const messages = {
},
toasts: {
deleted: "Atendente excluído com sucesso.",
updated: "Atendente atualizado com sucesso."
},
confirmationModal: {
deleteTitle: "Excluir",
Expand Down

0 comments on commit f36e6c6

Please sign in to comment.