Browse Source

FIX | Contact email press

merge-requests/184/merge
Vitalik 2 years ago
parent
commit
fbafbaf20a
  1. 26
      src/containers/App/ScrollToTop.jsx
  2. 249
      src/containers/App/Socket.jsx
  3. 340
      src/containers/App/sockets.js
  4. 16
      src/containers/Chats/plugins/chat-item-message.component.tsx
  5. 2
      src/containers/Contact/components/contact-external.component.tsx
  6. 17
      src/containers/Tasks/components/create-update-task-modal.component.tsx
  7. 4
      src/shared/components/fields/contact-field.component.tsx

26
src/containers/App/ScrollToTop.jsx

@ -1,26 +0,0 @@ @@ -1,26 +0,0 @@
import { PureComponent } from 'react';
import { withRouter } from 'react-router-dom';
import PropTypes from 'prop-types';
class ScrollToTop extends PureComponent<any> {
static propTypes = {
location: PropTypes.shape({
pathname: PropTypes.string,
}).isRequired,
children: PropTypes.element.isRequired,
};
componentDidUpdate(prevProps) {
const { location } = this.props;
if (location.pathname !== prevProps.location.pathname) {
window.scrollTo(0, 0);
}
}
render() {
const { children } = this.props;
return children;
}
}
export default withRouter(ScrollToTop);

249
src/containers/App/Socket.jsx

@ -1,249 +0,0 @@ @@ -1,249 +0,0 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { getUsersNotification } from '../Layout/topbar/TopbarNotification/actions';
import {
getTasks, getUsers as getUserTask, getUsersPermissions, getFactories, getTypes,
} from '../Task/actions';
import { getUsers } from '../User/actions';
import { logout, me } from './actions';
import {
gotMessage, gotMessageDelete, gotMessageEdit, gotMessagePin, gotMessageUnPin, loadChatMessages,
} from '../Messenger/redux/chat/chat.actions';
import { gotChatCreated, gotChatDeleted, updateChat } from '../Messenger/redux/chatList/chatlist.actions';
import taskSockets from './sockets';
class SocketComponent extends Component<any> {
constructor(props) {
super(props);
this.state = {
is_init_socket: false,
};
this.header = {};
this.clientSocket = null;
}
componentWillMount() {
}
componentDidMount() {
this.header = {
Authorization: `Bearer ${localStorage.getItem('tmp_token')}`,
};
taskSockets.headers = this.header;
taskSockets.initSockets();
}
componentWillReceiveProps(nextProps) {
// if (!this.state.is_init_socket && nextProps.is_logined && nextProps.is_load) {
// this.header = {
// Authorization: `Bearer ${localStorage.getItem('tmp_token')}`,
// };
// taskSockets.headers = this.header;
// taskSockets.initSockets();
// this.state.is_init_socket = true;
// this.clientSocket = sailsIOClient(socketIOClient);
// this.clientSocket.sails.url = config.apiUrl;
// this.clientSocket.sails.initialConnectionHeaders = this.header;
// this.clientSocket.sails.autoConnect = true;
// this.clientSocket.sails.reconnection = true;
// this.clientSocket.socket.on('connect', () => {
// this.state.is_connect = true;
// console.log('on connect');
// // io.socket.get('/api/admin/socket_init', {headers: headers}, function (body, response) {
// this.clientSocket.socket.request({
// method: 'get',
// url: '/api/auth/socket_init',
// headers: this.header
// }, (body, response) => {
// console.log('socket init req')
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> response", response)
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> body", body)
// });
// });
// this.clientSocket.socket.on('message',message => {
// console.log('message',message)
// // if(message.userId !== me.id){
// // store.dispatch(gotMessage(message))
// // }
// this.props.gotMessage(message)
// })
// this.clientSocket.socket.on('messageUnPinned',()=>{
// console.log('gotMessageUnPIn')
// this.props.gotMessageUnPin()
// })
// this.clientSocket.socket.on('messagePin',(msg)=>{
// console.log('gotMessagePin',msg)
// this.props.gotMessagePin(msg)
// })
// this.clientSocket.socket.on('messageDelete',(messageId)=>{
// console.log('gotMessageToDelete',messageId)
// this.props.gotMessageDelete(messageId)
// })
// this.clientSocket.socket.on('messageEdit',(message)=>{
// console.log('gotMessageToEdit',message)
// this.props.gotMessageEdit(message)
// })
// this.clientSocket.socket.on('notificationMessage', async message => {
// console.log('messageFromNotifications',message)
// // await Notifications.scheduleLocalNotificationAsync({title:message.chatName,
// // body:message.message
// // })
// })
// this.clientSocket.socket.on('chatCreated',(chat)=>{
// console.log('chatCreateeeed',chat)
// this.props.gotChatCreated(chat)
// })
// this.clientSocket.socket.on('chatUpdated',(chat)=>{
// console.log('chatUpdateddd',chat)
// this.props.updateChat(chat)
// })
// this.clientSocket.socket.on('chatDeleted',(chatId)=>{
// console.log('chatDeleted',chatId)
// this.props.gotChatDeleted(chatId)
// })
// this.clientSocket.socket.on('getLatest',()=>{
// this.props.loadChatMessages()
// })
// this.clientSocket.socket.on('update_me', () => {
// this.props.me()
// });
// this.clientSocket.socket.on('update_notification', () => {
// this.props.getUsersNotification();
// });
// this.clientSocket.socket.on('user_logout', (data) => {
// if(data.token_type){
// if(data.token_type == 'desktop'){
// this.props.logout();
// }
// } else {
// this.props.logout();
// }
// });
// this.clientSocket.socket.on('update_users', () => {
// this.props.getUsers(this.props.filter_user);
// this.props.getUserTask();
// this.props.getUsersPermissions();
// });
// this.clientSocket.socket.on('update_tasks', () => {
// this.props.getUserTask();
// this.props.getFactories();
// this.props.getTypes();
// this.props.getUsersPermissions();
// this.props.getTasks(this.props.filter_task, false);
// });
// this.clientSocket.socket.on('reconnect', () => {
// });
// this.clientSocket.socket.on('disconnect', () => {
// });
// this.clientSocket.socket.on('notification', (notification) => {
// this.props.getUsersNotification();
// if(notification.type == 'task')
// this.props.getTasks(this.props.filter_task);
// });
// }
// if(this.state.is_init_socket && !this.props.is_logined && nextProps.is_logined && nextProps.is_load){
// if(this.clientSocket && this.clientSocket.socket.isConnected()){
// this.header = {
// 'Authorization': 'Bearer ' + localStorage.getItem('tmp_token'),
// };
// this.clientSocket.sails.initialConnectionHeaders = this.header;
// console.log('reconnect')
// this.clientSocket.socket.request({
// method: 'get',
// url: '/api/auth/socket_init',
// headers: this.header
// }, (body, response) => {
// console.log("TCL: SocketComponent -> componentWillReceiveProps -> body", body)
// });
// }
// }
// if(this.props.token != nextProps.token && nextProps.token){
// if(this.clientSocket && this.clientSocket.socket.isConnected()){
// this.header = {
// 'Authorization': 'Bearer ' + nextProps.token,
// };
// this.clientSocket.sails.initialConnectionHeaders = this.header;
// console.log('reconnect')
// this.clientSocket.socket.request({
// method: 'get',
// url: '/api/auth/socket_init',
// headers: this.header
// }, (body, response) => {
// console.log("TCL: SocketComponent -> componentWillReceiveProps22 -> body", body)
// });
// }
// }
}
componentWillUnmount() {
}
render() {
return null;
}
}
SocketComponent.propTypes = {
};
const mapStateToProps = (state, ownProps) => ({
is_logined: state.auth.is_logined,
is_load: state.auth.is_load,
token: state.auth.token,
filter_task: state.task.filter,
filter_user: state.user.filter,
});
const mapDispatchToProps = {
getUsersNotification,
getTasks,
getUsers,
getUserTask,
getUsersPermissions,
logout,
getFactories,
getTypes,
me,
gotMessage,
gotMessageDelete,
gotMessageEdit,
gotMessagePin,
gotMessageUnPin,
gotChatCreated,
gotChatDeleted,
updateChat,
loadChatMessages,
};
export default connect(mapStateToProps, mapDispatchToProps)(SocketComponent);

340
src/containers/App/sockets.js

@ -1,99 +1,113 @@ @@ -1,99 +1,113 @@
import socketIOClient from 'socket.io-client';
import sailsIOClient from 'sails.io.js';
import React from 'react';
import Notification from 'rc-notification';
import store from './store';
import config from '../../config';
import React from "react";
import socketIOClient from "socket.io-client";
import sailsIOClient from "sails.io.js";
import store from "./store";
import config from "../../config";
import {
gotMessage, gotMessageDelete, gotMessageEdit, gotMessagePin, gotMessageUnPin, loadChatMessages, setInitialState,
} from '../Messenger/redux/chat/chat.actions';
gotMessage,
gotMessageDelete,
gotMessageEdit,
gotMessagePin,
gotMessageUnPin,
loadChatMessages,
setInitialState,
} from "../Messenger/redux/chat/chat.actions";
import {
gotChatCreated, gotChatDeleted, setChats, updateChat,
} from '../Messenger/redux/chatList/chatlist.actions';
import { logout, me } from './actions';
import { getUsersNotification } from '../Layout/topbar/TopbarNotification/actions';
import { getUsers } from '../User/actions';
gotChatCreated,
gotChatDeleted,
setChats,
updateChat,
} from "../Messenger/redux/chatList/chatlist.actions";
import { logout, me } from "./actions";
import { getUsersNotification } from "../Layout/topbar/TopbarNotification/actions";
import { getUsers } from "../User/actions";
import {
getFactories, getTasks, getTypes, getUsers as getUserTask, getUsersPermissions,
} from '../Task/actions';
import { BasicNotification } from '../../components/Notification/components/NotificationItem';
getFactories,
getTasks,
getTypes,
getUsers as getUserTask,
getUsersPermissions,
} from "../Task/actions";
console.log('storree', store.getState());
console.log("storree", store.getState());
class AppSockets {
client = null;
client = null;
inited = false
inited = false;
headers = null
headers = null;
initSockets = () => {
console.log('init sockets called', this.headers);
if (!this.headers) {
console.log('no headers returning');
return;
}
if (this.inited) {
console.log('already inited returning');
return;
}
if (!this.client) {
this.client = sailsIOClient(socketIOClient);
}
initSockets = () => {
console.log("init sockets called", this.headers);
if (!this.headers) {
console.log("no headers returning");
return;
}
if (this.inited) {
console.log("already inited returning");
return;
}
if (!this.client) {
this.client = sailsIOClient(socketIOClient);
}
this.client.sails.url = config.apiUrl;
this.client.sails.useCORSRouteToGetCookie = false;
this.client.sails.initialConnectionHeaders = this.headers;
this.client.sails.autoConnect = true;
this.client.sails.reconnection = true;
console.log('headersSet', this.client.sails.initialConnectionHeaders);
this.inited = true;
console.log('sockets inited', this.client.sails.initialConnectionHeaders);
this.client.socket.on('connect', () => {
console.log('connected!');
this.client.socket.request({
method: 'get',
url: '/api/auth/socket_init',
this.client.sails.url = config.apiUrl;
this.client.sails.useCORSRouteToGetCookie = false;
this.client.sails.initialConnectionHeaders = this.headers;
this.client.sails.autoConnect = true;
this.client.sails.reconnection = true;
console.log("headersSet", this.client.sails.initialConnectionHeaders);
this.inited = true;
console.log("sockets inited", this.client.sails.initialConnectionHeaders);
this.client.socket.on("connect", () => {
console.log("connected!");
this.client.socket.request(
{
method: "get",
url: "/api/auth/socket_init",
headers: this.headers,
}, (body, response) => {
console.log('socketResponse', response, body);
});
});
this.client.socket.on('message', (message) => {
console.log('message', message);
// if(message.userId !== me.id){
// store.dispatch(gotMessage(message))
// }
store.dispatch(gotMessage(message));
store.dispatch({
type: 'TO_NEW_MESSAGE',
payload: message,
});
});
this.client.socket.on('messageUnPinned', () => {
console.log('gotMessageUnPIn');
store.dispatch(gotMessageUnPin());
});
this.client.socket.on('messagePin', (msg) => {
console.log('gotMessagePin', msg);
store.dispatch(gotMessagePin(msg));
});
this.client.socket.on('messageDelete', (messageId) => {
console.log('gotMessageToDelete', messageId);
store.dispatch(gotMessageDelete(messageId));
});
this.client.socket.on('messageEdit', (message) => {
console.log('gotMessageToEdit', message);
store.dispatch(gotMessageEdit(message));
});
// this.client.socket.on('onlineUpdated',(chatId) => {
// console.log('onlineUpdateeeed',chatId)
// store.dispatch(chatOnlineUpdated(chatId))
// })
this.client.socket.on('notificationMessage', async (message) => {
console.log('messageFromNotifications', message);
/* Notification.newInstance({}, (notification) => {
},
(body, response) => {
console.log("socketResponse", response, body);
}
);
});
this.client.socket.on("message", (message) => {
console.log("message", message);
// if(message.userId !== me.id){
// store.dispatch(gotMessage(message))
// }
store.dispatch(gotMessage(message));
store.dispatch({
type: "TO_NEW_MESSAGE",
payload: message,
});
});
this.client.socket.on("messageUnPinned", () => {
console.log("gotMessageUnPIn");
store.dispatch(gotMessageUnPin());
});
this.client.socket.on("messagePin", (msg) => {
console.log("gotMessagePin", msg);
store.dispatch(gotMessagePin(msg));
});
this.client.socket.on("messageDelete", (messageId) => {
console.log("gotMessageToDelete", messageId);
store.dispatch(gotMessageDelete(messageId));
});
this.client.socket.on("messageEdit", (message) => {
console.log("gotMessageToEdit", message);
store.dispatch(gotMessageEdit(message));
});
// this.client.socket.on('onlineUpdated',(chatId) => {
// console.log('onlineUpdateeeed',chatId)
// store.dispatch(chatOnlineUpdated(chatId))
// })
this.client.socket.on("notificationMessage", async (message) => {
console.log("messageFromNotifications", message);
/* Notification.newInstance({}, (notification) => {
notification.notice({
content: <BasicNotification
color="info"
@ -103,90 +117,88 @@ class AppSockets { @@ -103,90 +117,88 @@ class AppSockets {
position: 'right-up',
});
}); */
});
this.client.socket.on('user_online', (chat) => {
console.log('user_online', chat);
});
this.client.socket.on('user_offline', (chat) => {
console.log('user_offline', chat);
});
this.client.socket.on('chatCreated', (chat) => {
console.log('chatCreated', chat);
store.dispatch(gotChatCreated(chat));
store.dispatch(setChats());
});
this.client.socket.on('chatUpdated', (chat) => {
console.log('chatUpdated', chat);
if(!chat) return
store.dispatch(updateChat(chat));
});
this.client.socket.on('chatDeleted', (chatId) => {
console.log('chatDeleted', chatId);
store.dispatch(gotChatDeleted(chatId));
if (store.getState().chat.chat.id == chatId) {
store.dispatch(setInitialState());
}
});
this.client.socket.on('getLatest', () => {
store.dispatch(loadChatMessages());
});
this.client.socket.on('update_me', () => {
store.dispatch(me());
});
this.client.socket.on('update_notification', () => {
store.dispatch(getUsersNotification());
});
this.client.socket.on('totalUnread', (total) => {
store.dispatch({
type: 'SET_TOTAL_UNREAD',
payload: total,
});
});
this.client.socket.on('user_logout', (data) => {
if (data.token_type) {
if (data.token_type == 'desktop') {
store.dispatch(logout());
}
} else {
});
this.client.socket.on("user_online", (chat) => {
console.log("user_online", chat);
});
this.client.socket.on("user_offline", (chat) => {
console.log("user_offline", chat);
});
this.client.socket.on("chatCreated", (chat) => {
console.log("chatCreated", chat);
store.dispatch(gotChatCreated(chat));
store.dispatch(setChats());
});
this.client.socket.on("chatUpdated", (chat) => {
console.log("chatUpdated", chat);
if (!chat) return;
store.dispatch(updateChat(chat));
});
this.client.socket.on("chatDeleted", (chatId) => {
console.log("chatDeleted", chatId);
store.dispatch(gotChatDeleted(chatId));
if (store.getState().chat.chat.id == chatId) {
store.dispatch(setInitialState());
}
});
this.client.socket.on("getLatest", () => {
store.dispatch(loadChatMessages());
});
this.client.socket.on("update_me", () => {
store.dispatch(me());
});
this.client.socket.on("update_notification", () => {
store.dispatch(getUsersNotification());
});
this.client.socket.on("totalUnread", (total) => {
store.dispatch({
type: "SET_TOTAL_UNREAD",
payload: total,
});
});
this.client.socket.on("user_logout", (data) => {
if (data.token_type) {
if (data.token_type == "desktop") {
store.dispatch(logout());
}
});
this.client.socket.on('update_users', () => {
store.dispatch(getUsers(store.getState().user.filter));
store.dispatch(getUserTask());
store.dispatch(getUsersPermissions());
});
this.client.socket.on('update_tasks', () => {
store.dispatch(getUserTask());
store.dispatch(getFactories());
store.dispatch(getTypes());
store.dispatch(getUsersPermissions());
store.dispatch(getTasks(store.getState().task.filter, false));
});
this.client.socket.on('reconnect', () => {
});
this.client.socket.on('leaveChat', (id) => {
console.log('You was kicked from chat', id);
if (store.getState().chat.chat.id == id) {
store.dispatch(setInitialState());
}
});
this.client.socket.on('disconnect', () => {
});
} else {
store.dispatch(logout());
}
});
this.client.socket.on("update_users", () => {
store.dispatch(getUsers(store.getState().user.filter));
store.dispatch(getUserTask());
store.dispatch(getUsersPermissions());
});
this.client.socket.on("update_tasks", () => {
store.dispatch(getUserTask());
store.dispatch(getFactories());
store.dispatch(getTypes());
store.dispatch(getUsersPermissions());
store.dispatch(getTasks(store.getState().task.filter, false));
});
this.client.socket.on("reconnect", () => {});
this.client.socket.on("leaveChat", (id) => {
console.log("You was kicked from chat", id);
if (store.getState().chat.chat.id == id) {
store.dispatch(setInitialState());
}
});
this.client.socket.on("disconnect", () => {});
this.client.socket.on('notification', (notification) => {
store.dispatch(getUsersNotification());
this.client.socket.on("notification", (notification) => {
store.dispatch(getUsersNotification());
if (notification.type == 'task') store.dispatch(getTasks(store.getState().task.filter));
});
}
if (notification.type == "task")
store.dispatch(getTasks(store.getState().task.filter));
});
};
}
const taskSockets = new AppSockets();
export default taskSockets;

16
src/containers/Chats/plugins/chat-item-message.component.tsx

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
import React, { FC } from "react";
import React, { FC, useMemo } from "react";
import { IMessage } from "@/shared";
import { ChatItem } from "./chat-item.component";
@ -54,7 +54,7 @@ const parseMessage = (message: string, regex: RegExp): string => { @@ -54,7 +54,7 @@ const parseMessage = (message: string, regex: RegExp): string => {
const subst = ` @$1($2) `;
const result = message.replace(regex, subst);
return result;
return result.replace(/\n{3,}\s*/g, "\n\n");
};
const findMentionId = (user: string): number => {
@ -66,9 +66,7 @@ const findMentionId = (user: string): number => { @@ -66,9 +66,7 @@ const findMentionId = (user: string): number => {
return Number(preparedId);
};
export const ChatItemMessage: FC<ChatItemMessageProps> = (props) => {
const mentions = parseMentions(props.content?.message);
const _ChatItemMessage: FC<ChatItemMessageProps> = (props) => {
const resultMessage = parseMessage(props.content?.message, regexToMatch);
return (
@ -98,7 +96,11 @@ export const ChatItemMessage: FC<ChatItemMessageProps> = (props) => { @@ -98,7 +96,11 @@ export const ChatItemMessage: FC<ChatItemMessageProps> = (props) => {
}}
>{` ${item.substring(0, item.lastIndexOf("("))} `}</a>
) : (
<span>{item}</span>
<span
dangerouslySetInnerHTML={{
__html: item.replaceAll("\n", "<br />"),
}}
/>
)
)}
</Linkify>
@ -108,3 +110,5 @@ export const ChatItemMessage: FC<ChatItemMessageProps> = (props) => { @@ -108,3 +110,5 @@ export const ChatItemMessage: FC<ChatItemMessageProps> = (props) => {
</ChatItem>
);
};
export const ChatItemMessage = React.memo(_ChatItemMessage);

2
src/containers/Contact/components/contact-external.component.tsx

@ -69,7 +69,6 @@ export const ContactExternal: FC<IProps> = ({ contact }) => { @@ -69,7 +69,6 @@ export const ContactExternal: FC<IProps> = ({ contact }) => {
<div
className="col-md-6 email-container"
style={{ paddingLeft: 0, marginBottom: 35 }}
onDoubleClick={() => window.open(`mailto:${contact.email}`)}
>
<ContactField
label={"Email"}
@ -77,6 +76,7 @@ export const ContactExternal: FC<IProps> = ({ contact }) => { @@ -77,6 +76,7 @@ export const ContactExternal: FC<IProps> = ({ contact }) => {
placeholder={"Email"}
onChange={() => {}}
svgIcon={MailIcon}
onClick={() => window.open(`mailto:${contact.email}`)}
/>
</div>
</div>

17
src/containers/Tasks/components/create-update-task-modal.component.tsx

@ -97,14 +97,15 @@ export const CreateUpdateTaskModal: FC<IProps> = ({ @@ -97,14 +97,15 @@ export const CreateUpdateTaskModal: FC<IProps> = ({
onDelete={deleteAttachment}
taskId={selectedTask?.id}
disabled={
selectedTask?.status !== ETaskStatus.Active ||
!checkPermission(
"user",
selectedTask?.executorId,
profile,
permissions,
Permissions.UPDATE
)
selectedTask &&
(selectedTask?.status !== ETaskStatus.Active ||
!checkPermission(
"user",
selectedTask?.executorId,
profile,
permissions,
Permissions.UPDATE
))
}
mode={state.mode}
onTaskFilesChange={setCopyDocumentsIds}

4
src/shared/components/fields/contact-field.component.tsx

@ -16,6 +16,7 @@ interface IProps { @@ -16,6 +16,7 @@ interface IProps {
svgIcon: string;
phone?: boolean;
onChange?: (val: string) => void;
onClick?: () => void;
// required?: any;
}
@ -27,11 +28,12 @@ export const ContactField: FC<IProps> = ({ @@ -27,11 +28,12 @@ export const ContactField: FC<IProps> = ({
svgIcon,
phone,
error,
onClick,
required,
}) => {
const formattedPhone = value ? new AsYouType().input(value?.toString()) : "";
return (
<div className="contact-field" style={style}>
<div className="contact-field" style={style} onClick={onClick}>
<p className="contact-label">{label}</p>
<div className="value-container">
{!phone ? (

Loading…
Cancel
Save