mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
Merge pull request #101 from project-error/feature/autocomplete-contacts
Feature / Autocomplete contacts in messages + improve messages ui a bit
This commit is contained in:
11 files changed
+355
-241
No files matched your search
@@ -36,9 +36,6 @@ export const MessagesApp = () => {
|
||||
render={() => (
|
||||
<>
|
||||
<MessagesList />
|
||||
<NewMessageGroupButton
|
||||
onClick={() => history.push('/messages/new')}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
/>
|
||||
@@ -51,6 +48,9 @@ export const MessagesApp = () => {
|
||||
/>
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<NewMessageGroupButton
|
||||
onClick={() => history.push('/messages/new')}
|
||||
/>
|
||||
<AlertBar />
|
||||
</AppWrapper>
|
||||
);
|
||||
@@ -72,6 +72,94 @@ InjectDebugData([
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: true,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: false,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
message: 'sup!',
|
||||
user_identifier: '1234',
|
||||
phone_number: '444-4444',
|
||||
display: 'kidz',
|
||||
avatar: null,
|
||||
isRead: true,
|
||||
isMine: true,
|
||||
updatedAt: Date.now(),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -3,11 +3,11 @@ import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Fab } from '@material-ui/core';
|
||||
import AddIcon from '@material-ui/icons/Add';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
bottom: '25px',
|
||||
right: '15px',
|
||||
bottom: theme.spacing(2),
|
||||
right: theme.spacing(3),
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -21,11 +21,13 @@ export function NewMessageGroupButton({
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Fab color='primary' onClick={onClick}>
|
||||
<Fab
|
||||
className={classes.root}
|
||||
color='primary'
|
||||
onClick={onClick}
|
||||
>
|
||||
<AddIcon />
|
||||
</Fab>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import React, { FormEvent, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Paper, TextField, Button } from '@material-ui/core';
|
||||
import useStyles from './form.styles';
|
||||
import { Paper, TextField, Button, Box, makeStyles } from '@material-ui/core';
|
||||
import SendIcon from '@material-ui/icons/Send';
|
||||
import ImageIcon from '@material-ui/icons/Image';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
@@ -11,9 +10,13 @@ interface IProps {
|
||||
messageGroupId: string | undefined;
|
||||
}
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: { position: 'absolute', bottom: 0, width: '100%' },
|
||||
});
|
||||
|
||||
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const classes = useStyles();
|
||||
const [message, setMessage] = useState('');
|
||||
|
||||
const handleSubmit = (event: FormEvent) => {
|
||||
@@ -31,24 +34,28 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
if (!messageGroupId) return null;
|
||||
|
||||
return (
|
||||
<Paper className={classes.paper} variant='outlined'>
|
||||
<form className={classes.form} onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder={t('APPS_MESSAGES_NEW_MESSAGE')}
|
||||
className={classes.input}
|
||||
inputRef={(input) => input && input.focus()}
|
||||
inputProps={{
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
/>
|
||||
<Button className={classes.sendButton} onClick={onAddImageClick}>
|
||||
<ImageIcon />
|
||||
</Button>
|
||||
<Button className={classes.sendButton} type='submit'>
|
||||
<SendIcon />
|
||||
</Button>
|
||||
<Paper variant='outlined' className={classes.root}>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Box display='flex'>
|
||||
<Box pl={1} flexGrow={1}>
|
||||
<TextField
|
||||
fullWidth
|
||||
inputProps={{ style: { fontSize: '1.3em' } }}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
placeholder={t('APPS_MESSAGES_NEW_MESSAGE')}
|
||||
inputRef={(input) => input && input.focus()}
|
||||
/>
|
||||
</Box>
|
||||
<Box>
|
||||
<Button onClick={onAddImageClick}>
|
||||
<ImageIcon />
|
||||
</Button>
|
||||
<Button type='submit'>
|
||||
<SendIcon />
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
</form>
|
||||
</Paper>
|
||||
);
|
||||
|
||||
@@ -1,86 +1,110 @@
|
||||
import React, { FormEvent, useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import React, { FormEvent, useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TextField, Button } from '@material-ui/core';
|
||||
import { TextField, Button, Box } from '@material-ui/core';
|
||||
|
||||
import useStyles from './form.styles';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
const sendNuiCreateMessageGroup = ({ parts, isGroupChat, labelValue }) =>
|
||||
Nui.send('phone:createMessageGroup', {
|
||||
phoneNumbers: parts,
|
||||
label: isGroupChat && labelValue ? labelValue : null,
|
||||
});
|
||||
import { Autocomplete } from '@material-ui/lab';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { Contact } from '../../../../common/typings/contact';
|
||||
|
||||
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
const [participants, setParticipants] = useState('');
|
||||
const [participants, setParticipants] = useState([]);
|
||||
const [label, setLabel] = useState('');
|
||||
|
||||
// handles phone numbers in a csv format and strips all spaces and
|
||||
// external characters out of them:
|
||||
// 123-4567, 987-6543, 333-4444
|
||||
const getGroupParts = useCallback(
|
||||
(numbers) => numbers.split(',').map((part) => part.replace(/[^0-9]/g, '')),
|
||||
[]
|
||||
);
|
||||
|
||||
const parts = useMemo(() => getGroupParts(participants), [participants, getGroupParts]);
|
||||
|
||||
const isGroupChat = parts.length > 1;
|
||||
|
||||
const labelValue = label.trim();
|
||||
const { contacts } = useContacts();
|
||||
|
||||
useEffect(() => {
|
||||
if (phoneNumber) {
|
||||
sendNuiCreateMessageGroup({ parts: getGroupParts(phoneNumber), isGroupChat: false, labelValue: null });
|
||||
history.push('/messages');
|
||||
const find = contacts.find((c) => c.number === phoneNumber);
|
||||
const newPart = find || { number: phoneNumber };
|
||||
setParticipants((all) => [...all, newPart]);
|
||||
}
|
||||
}, [phoneNumber, labelValue, history, getGroupParts]);
|
||||
}, [phoneNumber, contacts]);
|
||||
|
||||
const handleSubmit = (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
if (parts.length > 0) {
|
||||
sendNuiCreateMessageGroup({ parts, isGroupChat, labelValue });
|
||||
setParticipants('');
|
||||
history.push('/messages');
|
||||
const isGroupChat = participants.length > 1;
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
// handles phone numbers in a csv format and strips all spaces and
|
||||
// external characters out of them:
|
||||
// 123-4567, 987-6543, 333-4444
|
||||
const phoneNumbers = participants.map(({ number }) =>
|
||||
number.replace(/[^0-9]/g, '')
|
||||
);
|
||||
const labelValue = isGroupChat ? label.trim() : null;
|
||||
|
||||
if (phoneNumbers.length) {
|
||||
Nui.send('phone:createMessageGroup', {
|
||||
phoneNumbers,
|
||||
label: labelValue,
|
||||
});
|
||||
setParticipants([]);
|
||||
history.push('/messages');
|
||||
}
|
||||
},
|
||||
[history, label, participants, isGroupChat]
|
||||
);
|
||||
|
||||
const onAutocompleteChange = useCallback((_e, value: any) => {
|
||||
const lastIdx = value.length - 1;
|
||||
if (typeof value[lastIdx] === 'string') {
|
||||
value.splice(lastIdx, 1, { number: value[lastIdx] });
|
||||
setParticipants(value);
|
||||
return;
|
||||
}
|
||||
};
|
||||
setParticipants(value as any[]);
|
||||
}, []);
|
||||
|
||||
const renderAutocompleteInput = useCallback(
|
||||
(params) => (
|
||||
<TextField
|
||||
{...params}
|
||||
fullWidth
|
||||
label={t('APPS_MESSAGES_INPUT_NAME_OR_NUMBER')}
|
||||
inputProps={{
|
||||
...params.inputProps,
|
||||
autoFocus: true,
|
||||
}}
|
||||
/>
|
||||
),
|
||||
[t]
|
||||
);
|
||||
|
||||
const submitDisabled = !participants.length || (isGroupChat && !label);
|
||||
|
||||
return (
|
||||
<form className={classes.newGroupForm} onSubmit={handleSubmit}>
|
||||
<TextField
|
||||
value={participants}
|
||||
onChange={(e) => setParticipants(e.target.value || '')}
|
||||
placeholder={t('APPS_MESSAGES_NEW_MESSAGE_GROUP')}
|
||||
className={classes.newGroupinput}
|
||||
autoFocus
|
||||
inputProps={{
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
multiline
|
||||
/>
|
||||
{isGroupChat && (
|
||||
<TextField
|
||||
value={label}
|
||||
onChange={(e) => setLabel(e.target.value)}
|
||||
placeholder={t('APPS_MESSAGES_GROUP_CHAT_LABEL')}
|
||||
className={classes.newGroupinput}
|
||||
inputProps={{
|
||||
className: classes.messagesInput,
|
||||
}}
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Box px={2} py={3}>
|
||||
<Autocomplete<Contact, boolean, boolean, boolean>
|
||||
value={participants}
|
||||
multiple
|
||||
freeSolo
|
||||
autoHighlight
|
||||
options={contacts || []}
|
||||
getOptionLabel={(c) => c.display || c.number}
|
||||
onChange={onAutocompleteChange}
|
||||
renderInput={renderAutocompleteInput}
|
||||
/>
|
||||
</Box>
|
||||
{isGroupChat && (
|
||||
<Box px={2} py={3}>
|
||||
<TextField
|
||||
fullWidth
|
||||
value={label}
|
||||
onChange={(e) => setLabel(e.target.value)}
|
||||
placeholder={t('APPS_MESSAGES_GROUP_CHAT_LABEL')}
|
||||
/>
|
||||
</Box>
|
||||
)}
|
||||
<Button
|
||||
variant='contained'
|
||||
className={classes.newGroupSubmitButton}
|
||||
color='primary'
|
||||
type='submit'
|
||||
>
|
||||
{t('APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT')}
|
||||
</Button>
|
||||
<Box px={2} py={3}>
|
||||
<Button disabled={submitDisabled} variant='contained' fullWidth color='primary' type='submit'>
|
||||
{t('APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT')}
|
||||
</Button>
|
||||
</Box>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
sendButton: {
|
||||
float: 'right',
|
||||
},
|
||||
paper: {
|
||||
position: 'absolute',
|
||||
bottom: 0,
|
||||
width: '100%',
|
||||
},
|
||||
form: {
|
||||
display: 'flex',
|
||||
},
|
||||
input: {
|
||||
width: '100%',
|
||||
margin: 10,
|
||||
},
|
||||
newGroupForm: {
|
||||
position: 'absolute',
|
||||
top: 65,
|
||||
display: 'flex',
|
||||
flexFlow: 'column nowrap',
|
||||
justifyContent: 'flex-start',
|
||||
width: '100%',
|
||||
},
|
||||
newGroupSubmitButton: {
|
||||
margin: '15px 8px 0px 8px',
|
||||
},
|
||||
newGroupinput: {
|
||||
margin: '0px 8px 15px 8px',
|
||||
},
|
||||
messagesInput: {
|
||||
fontSize: 20,
|
||||
},
|
||||
}));
|
||||
|
||||
export default useStyles;
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Paper, Typography } from '@material-ui/core';
|
||||
import { Box, Paper, Typography } from '@material-ui/core';
|
||||
|
||||
import { Message, MessageGroup } from '../../../../common/typings/messages';
|
||||
import MessageInput from '../form/MessageInput';
|
||||
@@ -32,9 +32,16 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
|
||||
isOpen={imageModalOpen}
|
||||
messageGroupId={activeMessageGroup.groupId}
|
||||
/>
|
||||
<div id={CONVERSATION_ELEMENT_ID} className={classes.messageList}>
|
||||
<Box
|
||||
id={CONVERSATION_ELEMENT_ID}
|
||||
height='90%'
|
||||
display='flex'
|
||||
flexDirection='column'
|
||||
pb={4}
|
||||
className={classes.overflowAutoY}
|
||||
>
|
||||
{messages.map((message) => (
|
||||
<div key={message.id} className={classes.messageContainer}>
|
||||
<div key={message.id}>
|
||||
<Paper
|
||||
className={message.isMine ? classes.sourceSms : classes.sms}
|
||||
variant='outlined'
|
||||
@@ -56,7 +63,7 @@ const Conversation = ({ activeMessageGroup, messages }: IProps) => {
|
||||
</Paper>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Box>
|
||||
<MessageInput
|
||||
messageGroupId={activeMessageGroup.groupId}
|
||||
onAddImageClick={() => setImageModalOpen(true)}
|
||||
|
||||
@@ -15,6 +15,9 @@ const useStyles = makeStyles((theme) => ({
|
||||
flexFlow: 'row nowrap',
|
||||
padding: '3px 0px',
|
||||
},
|
||||
overflowAutoY: {
|
||||
overflowY: 'auto',
|
||||
},
|
||||
groupdisplay: {
|
||||
width: '300px',
|
||||
paddingTop: '8px',
|
||||
@@ -28,15 +31,6 @@ const useStyles = makeStyles((theme) => ({
|
||||
paddingTop: '8px',
|
||||
fontSize: '20px',
|
||||
},
|
||||
messageList: {
|
||||
height: '90%',
|
||||
overflowY: 'auto',
|
||||
paddingBottom: '40px',
|
||||
},
|
||||
messageContainer: {
|
||||
marginTop: 25,
|
||||
width: '100%',
|
||||
},
|
||||
sourceSms: {
|
||||
float: 'right',
|
||||
margin: 10,
|
||||
|
||||
@@ -66,11 +66,12 @@
|
||||
"APPS_MESSAGES_NEW_MESSAGE": "Message...",
|
||||
"APPS_MESSAGES_NEW_MESSAGE_GROUP": "Phone numbers...",
|
||||
"APPS_MESSAGES_GROUP_CHAT_LABEL": "Group chat label...",
|
||||
"APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Submit",
|
||||
"APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Send",
|
||||
"APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number: ",
|
||||
"APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE": "This message group already exists",
|
||||
"APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group",
|
||||
"APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE": "You cannot add yourself!",
|
||||
"APPS_MESSAGES_INPUT_NAME_OR_NUMBER": "Search contacts or type number and press enter",
|
||||
|
||||
"APPS_CONTACT_ADD_SUCCESS": "Successfully created contact!",
|
||||
"APPS_CONTACT_ADD_FAILED": "Failed to created contact!",
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
"translation": {
|
||||
"DATE_FORMAT": "DD/MM/AAAA",
|
||||
"DATE_TIME_FORMAT": "DD/MM/AAAA hh:mm A",
|
||||
|
||||
|
||||
"COMING_SOON": "En cours...",
|
||||
|
||||
|
||||
"APPS_DIALER": "Téléphone",
|
||||
"APPS_CONTACTS": "Contacts",
|
||||
"APPS_MESSAGES": "Messages",
|
||||
@@ -16,11 +16,10 @@
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_SELLOUT": "Marché",
|
||||
"APPS_CAMERA": "Caméra",
|
||||
|
||||
|
||||
"APPS_BANK_TRANSFER": "Transfert",
|
||||
"APPS_SETTINGS_OPTIONS_WALLPAPER": "Fond d'écran",
|
||||
"APPS_SETTINGS_OPTIONS_FRAME": "Cadre/Coque",
|
||||
"APPS_TWITTER": "Twitter",
|
||||
"APPS_TWITTER_TWEET": "Tweet",
|
||||
"APPS_TWITTER_TWEET_MESSAGE_PLACEHOLDER": "Quoi de neuf ?",
|
||||
"APPS_TWITTER_IMAGE_PLACEHOLDER": "Lien vers votre image/GIF",
|
||||
@@ -83,7 +82,7 @@
|
||||
"APPS_CONTACT_MODAL_PLACEHOLDER_NUMBER": "Numéro",
|
||||
"APPS_CONTACT_MODAL_PLACEHOLDER_AVATAR": "Photo",
|
||||
"APPS_CONTACT_MODAL_BUTTON_ADD": "Ajouter un contact",
|
||||
|
||||
|
||||
"APPS_NOTES_ADD_SUCCESS": "Note sauvegardée avec succès.",
|
||||
"APPS_NOTES_ADD_FAILED": "Erreur lors de la suppression d'une note.",
|
||||
"APPS_NOTES_UPDATE_SUCCESS": "Mise à jour d'une note réalisée avec succès.",
|
||||
|
||||
Reference in new issue
Block a user