Skip to content

Commit

Permalink
Correção da visualização de contatos (isTricked)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed May 27, 2023
1 parent 38cc5d0 commit 2951585
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { QueryInterface, DataTypes } from "sequelize";

module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Users", "isTricked");
},
down: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Users", "isTricked", {
type: DataTypes.BOOLEAN,
defaultValue: true
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { QueryInterface, DataTypes } from "sequelize";

module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.addColumn("Users", "isTricked", {
type: DataTypes.STRING,
allowNull: false,
defaultValue: "enabled"
});
},

down: (queryInterface: QueryInterface) => {
return queryInterface.removeColumn("Users", "isTricked");
}
};
4 changes: 2 additions & 2 deletions backend/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ class User extends Model<User> {
@Column
profile: string;

@Default(true)
@Default("enabled")
@Column
isTricked: boolean;
isTricked: string;

@ForeignKey(() => Whatsapp)
@Column
Expand Down
39 changes: 35 additions & 4 deletions frontend/src/components/UserModal/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useContext, useRef } from "react";

import { useHistory } from "react-router-dom";
import * as Yup from "yup";
import {
Formik,
Expand All @@ -25,9 +25,9 @@ import {
IconButton
} from '@material-ui/core';

import {
Visibility,
VisibilityOff
import {
Visibility,
VisibilityOff
} from '@material-ui/icons';

import { green } from "@material-ui/core/colors";
Expand Down Expand Up @@ -97,6 +97,7 @@ const UserModal = ({ open, onClose, userId }) => {
profile: "user",
startWork: "",
endWork: "",
isTricked: "enabled"
};

const { user: loggedInUser } = useContext(AuthContext);
Expand All @@ -108,6 +109,7 @@ const UserModal = ({ open, onClose, userId }) => {
const { loading, whatsApps } = useWhatsApps();
const startWorkRef = useRef();
const endWorkRef = useRef();
const history = useHistory();

useEffect(() => {
const fetchUser = async () => {
Expand Down Expand Up @@ -142,6 +144,7 @@ const UserModal = ({ open, onClose, userId }) => {
await api.post("/users", userData);
}
toast.success(i18n.t("userModal.success"));
history.go(0);
} catch (err) {
toastError(err);
}
Expand Down Expand Up @@ -341,6 +344,34 @@ const UserModal = ({ open, onClose, userId }) => {
</form>
)}
/>
<FormControl
variant="outlined"
className={classes.formControl}
margin="dense"
>
<Can
role={loggedInUser.profile}
perform="user-modal:editProfile"
yes={() => (
<>
<InputLabel id="isTricked-selection-input-label">
{i18n.t("userModal.form.isTricked")}
</InputLabel>

<Field
as={Select}
label={i18n.t("userModal.form.isTricked")}
name="isTricked"
labelId="isTricked-selection-label"
id="isTricked-selection"
>
<MenuItem value="enabled">{i18n.t("userModal.form.enabled")}</MenuItem>
<MenuItem value="disabled">{i18n.t("userModal.form.disabled")}</MenuItem>
</Field>
</>
)}
/>
</FormControl>
</DialogContent>
<DialogActions>
<Button
Expand Down
47 changes: 2 additions & 45 deletions frontend/src/pages/Users/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React, { useState, useEffect, useReducer, useContext } from "react";
import React, { useState, useEffect, useReducer } 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 @@ -33,11 +31,9 @@ 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 @@ -105,9 +101,6 @@ 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 @@ -195,20 +188,6 @@ 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 @@ -276,15 +255,6 @@ 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 @@ -307,19 +277,6 @@ 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 @@ -343,7 +300,7 @@ const Users = () => {
</TableCell>
</TableRow>
))}
{loading && <TableRowSkeleton columns={9} />}
{loading && <TableRowSkeleton columns={8} />}
</>
</TableBody>
</Table>
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ const messages = {
whatsapp: "Standard Connection",
user: "Attendant",
startWork: "Start",
endWork: "Finish"
endWork: "Finish",
isTricked: "View Contacts",
enabled: "Enabled",
disabled: "Disabled"
},
buttons: {
okAdd: "Add",
Expand Down Expand Up @@ -486,6 +489,13 @@ const messages = {
deleteMessage: "All agent data will be lost. Open tickets for this agent will be moved to hold.",
},
},
company:{
success: "Company data successfully saved.",
title: "Company Data",
info: "Information",
name: "Name",
url: "Website"
},
integrations: {
success: "Integration saved successfully.",
title: "Integrations",
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ const messages = {
whatsapp: "Conexión estándar",
asistente: "Asistente",
startWork: "Inicio",
endWork: "Finalizar"
endWork: "Finalizar",
isTricked: "Ver contactos",
enabled: "Habilitado",
disabled: "Deshabilitado"
},
buttons: {
okAdd: "Agregar",
Expand Down Expand Up @@ -486,6 +489,13 @@ const messages = {
deleteMessage: "Se perderán todos los datos del asistente. Los tickets abiertos para este asistente se moverán a espera.",
},
},
company:{
success: "Los datos de la empresa se guardaron con éxito.",
title: "Datos de la empresa",
info: "Información",
name: "Nombre",
url: "Sitio web"
},
integrations: {
success: "Integracion guardada con exito.",
title: "Integraciones",
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ const messages = {
whatsapp: "Conexão Padrão",
user: "Atendente",
startWork: "Inicio",
endWork: "Termino"
endWork: "Termino",
isTricked: "Ver Contatos",
enabled: "Habilitado",
disabled: "Desabilitado"
},
buttons: {
okAdd: "Adicionar",
Expand Down Expand Up @@ -390,6 +393,7 @@ const messages = {
queues: "Setores",
administration: "Administração",
users: "Atendentes",
company: "Empresa",
integrations: "Integrações",
settings: "Configurações",
sendMsg: "Envio de Mensagens",
Expand Down Expand Up @@ -469,7 +473,6 @@ 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 @@ -487,6 +490,13 @@ const messages = {
deleteMessage: "Todos os dados do atendente serão perdidos. Os tickets abertos deste atendente serão movidos para a espera.",
},
},
company:{
success: "Dados da Empresa salvo com sucesso.",
title: "Dados da Empresa",
info: "Informações",
name: "Nome",
url: "Site"
},
integrations: {
success: "Integração salva com sucesso.",
title: "Integrações",
Expand Down

0 comments on commit 2951585

Please sign in to comment.