mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 12:49:32 +00:00
✨ In user registration add standard whatsapp field
This commit is contained in:
@@ -27,7 +27,7 @@ export const index = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const store = async (req: Request, res: Response): Promise<Response> => {
|
export const store = async (req: Request, res: Response): Promise<Response> => {
|
||||||
const { email, password, name, profile, queueIds } = req.body;
|
const { email, password, name, profile, queueIds, whatsappId } = req.body;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
req.url === "/signup" &&
|
req.url === "/signup" &&
|
||||||
@@ -43,7 +43,8 @@ export const store = async (req: Request, res: Response): Promise<Response> => {
|
|||||||
password,
|
password,
|
||||||
name,
|
name,
|
||||||
profile,
|
profile,
|
||||||
queueIds
|
queueIds,
|
||||||
|
whatsappId
|
||||||
});
|
});
|
||||||
|
|
||||||
const io = getIO();
|
const io = getIO();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import Queue from "../models/Queue";
|
import Queue from "../models/Queue";
|
||||||
import User from "../models/User";
|
import User from "../models/User";
|
||||||
|
import Whatsapp from "../models/Whatsapp";
|
||||||
|
|
||||||
interface SerializedUser {
|
interface SerializedUser {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -7,6 +8,7 @@ interface SerializedUser {
|
|||||||
email: string;
|
email: string;
|
||||||
profile: string;
|
profile: string;
|
||||||
queues: Queue[];
|
queues: Queue[];
|
||||||
|
whatsapp: Whatsapp;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const SerializeUser = (user: User): SerializedUser => {
|
export const SerializeUser = (user: User): SerializedUser => {
|
||||||
@@ -15,6 +17,7 @@ export const SerializeUser = (user: User): SerializedUser => {
|
|||||||
name: user.name,
|
name: user.name,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
profile: user.profile,
|
profile: user.profile,
|
||||||
queues: user.queues
|
queues: user.queues,
|
||||||
|
whatsapp: user.whatsapp
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ interface Request {
|
|||||||
name: string;
|
name: string;
|
||||||
queueIds?: number[];
|
queueIds?: number[];
|
||||||
profile?: string;
|
profile?: string;
|
||||||
|
whatsappId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Response {
|
interface Response {
|
||||||
@@ -24,7 +25,8 @@ const CreateUserService = async ({
|
|||||||
password,
|
password,
|
||||||
name,
|
name,
|
||||||
queueIds = [],
|
queueIds = [],
|
||||||
profile = "admin"
|
profile = "admin",
|
||||||
|
whatsappId
|
||||||
}: Request): Promise<Response> => {
|
}: Request): Promise<Response> => {
|
||||||
const schema = Yup.object().shape({
|
const schema = Yup.object().shape({
|
||||||
name: Yup.string().required().min(2),
|
name: Yup.string().required().min(2),
|
||||||
@@ -56,9 +58,10 @@ const CreateUserService = async ({
|
|||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
name,
|
name,
|
||||||
profile
|
profile,
|
||||||
|
whatsappId: whatsappId ? whatsappId : null
|
||||||
},
|
},
|
||||||
{ include: ["queues"] }
|
{ include: ["queues", "whatsapp"] }
|
||||||
);
|
);
|
||||||
|
|
||||||
await user.$set("queues", queueIds);
|
await user.$set("queues", queueIds);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Sequelize, Op } from "sequelize";
|
import { Sequelize, Op } from "sequelize";
|
||||||
import Queue from "../../models/Queue";
|
import Queue from "../../models/Queue";
|
||||||
import User from "../../models/User";
|
import User from "../../models/User";
|
||||||
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
searchParam?: string;
|
searchParam?: string;
|
||||||
@@ -39,7 +40,8 @@ const ListUsersService = async ({
|
|||||||
offset,
|
offset,
|
||||||
order: [["createdAt", "DESC"]],
|
order: [["createdAt", "DESC"]],
|
||||||
include: [
|
include: [
|
||||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] },
|
||||||
|
{ model: Whatsapp, as: "whatsapp", attributes: ["id", "name"] },
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import User from "../../models/User";
|
import User from "../../models/User";
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
import Queue from "../../models/Queue";
|
import Queue from "../../models/Queue";
|
||||||
|
import Whatsapp from "../../models/Whatsapp";
|
||||||
|
|
||||||
const ShowUserService = async (id: string | number): Promise<User> => {
|
const ShowUserService = async (id: string | number): Promise<User> => {
|
||||||
const user = await User.findByPk(id, {
|
const user = await User.findByPk(id, {
|
||||||
attributes: ["name", "id", "email", "profile", "tokenVersion"],
|
attributes: ["name", "id", "email", "profile", "tokenVersion", "whatsappId"],
|
||||||
include: [
|
include: [
|
||||||
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] }
|
{ model: Queue, as: "queues", attributes: ["id", "name", "color"] },
|
||||||
|
{ model: Whatsapp, as: "whatsapp", attributes: ["id", "name"] },
|
||||||
],
|
],
|
||||||
order: [ [ { model: Queue, as: "queues"}, 'name', 'asc' ] ]
|
order: [ [ { model: Queue, as: "queues"}, 'name', 'asc' ] ]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
|
|
||||||
import AppError from "../../errors/AppError";
|
import AppError from "../../errors/AppError";
|
||||||
|
import { SerializeUser } from "../../helpers/SerializeUser";
|
||||||
import ShowUserService from "./ShowUserService";
|
import ShowUserService from "./ShowUserService";
|
||||||
|
|
||||||
interface UserData {
|
interface UserData {
|
||||||
@@ -9,6 +10,7 @@ interface UserData {
|
|||||||
name?: string;
|
name?: string;
|
||||||
profile?: string;
|
profile?: string;
|
||||||
queueIds?: number[];
|
queueIds?: number[];
|
||||||
|
whatsappId?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Request {
|
interface Request {
|
||||||
@@ -36,7 +38,7 @@ const UpdateUserService = async ({
|
|||||||
password: Yup.string()
|
password: Yup.string()
|
||||||
});
|
});
|
||||||
|
|
||||||
const { email, password, profile, name, queueIds = [] } = userData;
|
const { email, password, profile, name, queueIds = [], whatsappId } = userData;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await schema.validate({ email, password, profile, name });
|
await schema.validate({ email, password, profile, name });
|
||||||
@@ -48,20 +50,15 @@ const UpdateUserService = async ({
|
|||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
profile,
|
profile,
|
||||||
name
|
name,
|
||||||
|
whatsappId: whatsappId ? whatsappId : null
|
||||||
});
|
});
|
||||||
|
|
||||||
await user.$set("queues", queueIds);
|
await user.$set("queues", queueIds);
|
||||||
|
|
||||||
await user.reload();
|
await user.reload();
|
||||||
|
|
||||||
const serializedUser = {
|
const serializedUser = SerializeUser(user);
|
||||||
id: user.id,
|
|
||||||
name: user.name,
|
|
||||||
email: user.email,
|
|
||||||
profile: user.profile,
|
|
||||||
queues: user.queues
|
|
||||||
};
|
|
||||||
|
|
||||||
return serializedUser;
|
return serializedUser;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import toastError from "../../errors/toastError";
|
|||||||
import QueueSelect from "../QueueSelect";
|
import QueueSelect from "../QueueSelect";
|
||||||
import { AuthContext } from "../../context/Auth/AuthContext";
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
||||||
import { Can } from "../Can";
|
import { Can } from "../Can";
|
||||||
|
import useWhatsApps from "../../hooks/useWhatsApps";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -79,7 +80,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
name: "",
|
name: "",
|
||||||
email: "",
|
email: "",
|
||||||
password: "",
|
password: "",
|
||||||
profile: "user",
|
profile: "user"
|
||||||
};
|
};
|
||||||
|
|
||||||
const { user: loggedInUser } = useContext(AuthContext);
|
const { user: loggedInUser } = useContext(AuthContext);
|
||||||
@@ -87,7 +88,8 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
const [user, setUser] = useState(initialState);
|
const [user, setUser] = useState(initialState);
|
||||||
const [selectedQueueIds, setSelectedQueueIds] = useState([]);
|
const [selectedQueueIds, setSelectedQueueIds] = useState([]);
|
||||||
const [showPassword, setShowPassword] = useState(false);
|
const [showPassword, setShowPassword] = useState(false);
|
||||||
|
const [whatsappId, setWhatsappId] = useState(false);
|
||||||
|
const {loading, whatsApps} = useWhatsApps();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUser = async () => {
|
const fetchUser = async () => {
|
||||||
@@ -99,6 +101,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
});
|
});
|
||||||
const userQueueIds = data.queues?.map(queue => queue.id);
|
const userQueueIds = data.queues?.map(queue => queue.id);
|
||||||
setSelectedQueueIds(userQueueIds);
|
setSelectedQueueIds(userQueueIds);
|
||||||
|
setWhatsappId(data.whatsappId ? data.whatsappId : '');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toastError(err);
|
toastError(err);
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSaveUser = async values => {
|
const handleSaveUser = async values => {
|
||||||
const userData = { ...values, queueIds: selectedQueueIds };
|
const userData = { ...values, whatsappId, queueIds: selectedQueueIds };
|
||||||
try {
|
try {
|
||||||
if (userId) {
|
if (userId) {
|
||||||
await api.put(`/users/${userId}`, userData);
|
await api.put(`/users/${userId}`, userData);
|
||||||
@@ -242,6 +245,26 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Can
|
||||||
|
role={loggedInUser.profile}
|
||||||
|
perform="user-modal:editQueues"
|
||||||
|
yes={() => (
|
||||||
|
<FormControl variant="outlined" margin="dense" className={classes.maxWidth} fullWidth>
|
||||||
|
<InputLabel>{i18n.t("userModal.form.whatsapp")}</InputLabel>
|
||||||
|
<Field
|
||||||
|
as={Select}
|
||||||
|
value={whatsappId}
|
||||||
|
onChange={(e) => setWhatsappId(e.target.value)}
|
||||||
|
label={i18n.t("userModal.form.whatsapp")}
|
||||||
|
>
|
||||||
|
<MenuItem value={''}> </MenuItem>
|
||||||
|
{whatsApps.map((whatsapp) => (
|
||||||
|
<MenuItem key={whatsapp.id} value={whatsapp.id}>{whatsapp.name}</MenuItem>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -243,6 +243,9 @@ const Users = () => {
|
|||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
{i18n.t("users.table.profile")}
|
{i18n.t("users.table.profile")}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
|
<TableCell align="center">
|
||||||
|
{i18n.t("users.table.whatsapp")}
|
||||||
|
</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
{i18n.t("users.table.actions")}
|
{i18n.t("users.table.actions")}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
@@ -255,6 +258,7 @@ const Users = () => {
|
|||||||
<TableCell align="center">{user.name}</TableCell>
|
<TableCell align="center">{user.name}</TableCell>
|
||||||
<TableCell align="center">{user.email}</TableCell>
|
<TableCell align="center">{user.email}</TableCell>
|
||||||
<TableCell align="center">{user.profile}</TableCell>
|
<TableCell align="center">{user.profile}</TableCell>
|
||||||
|
<TableCell align="center">{user.whatsapp?.name}</TableCell>
|
||||||
<TableCell align="center">
|
<TableCell align="center">
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ const messages = {
|
|||||||
email: "Email",
|
email: "Email",
|
||||||
password: "Password",
|
password: "Password",
|
||||||
profile: "Profile",
|
profile: "Profile",
|
||||||
|
whatsapp: "Default Connection",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
okAdd: "Add",
|
okAdd: "Add",
|
||||||
@@ -340,6 +341,7 @@ const messages = {
|
|||||||
name: "Name",
|
name: "Name",
|
||||||
email: "Email",
|
email: "Email",
|
||||||
profile: "Profile",
|
profile: "Profile",
|
||||||
|
whatsapp: "Default Connection",
|
||||||
actions: "Actions",
|
actions: "Actions",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ const messages = {
|
|||||||
email: "Correo Electrónico",
|
email: "Correo Electrónico",
|
||||||
password: "Contraseña",
|
password: "Contraseña",
|
||||||
profile: "Perfil",
|
profile: "Perfil",
|
||||||
|
whatsapp: "Conexión estándar",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
okAdd: "Agregar",
|
okAdd: "Agregar",
|
||||||
@@ -345,6 +346,7 @@ const messages = {
|
|||||||
name: "Nombre",
|
name: "Nombre",
|
||||||
email: "Correo Electrónico",
|
email: "Correo Electrónico",
|
||||||
profile: "Perfil",
|
profile: "Perfil",
|
||||||
|
whatsapp: "Conexión estándar",
|
||||||
actions: "Acciones",
|
actions: "Acciones",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
|
|||||||
@@ -208,6 +208,7 @@ const messages = {
|
|||||||
email: "Email",
|
email: "Email",
|
||||||
password: "Senha",
|
password: "Senha",
|
||||||
profile: "Perfil",
|
profile: "Perfil",
|
||||||
|
whatsapp: "Conexão Padrão",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
okAdd: "Adicionar",
|
okAdd: "Adicionar",
|
||||||
@@ -344,6 +345,7 @@ const messages = {
|
|||||||
name: "Nome",
|
name: "Nome",
|
||||||
email: "Email",
|
email: "Email",
|
||||||
profile: "Perfil",
|
profile: "Perfil",
|
||||||
|
whatsapp: "Conexão Padrão",
|
||||||
actions: "Ações",
|
actions: "Ações",
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
|
|||||||
Reference in New Issue
Block a user