working group texts

This commit is contained in:
erik-sn committed 2020-11-20 19:35:42 -05:00
1 parent 5a78b67946
commit 61eecd5b59
8 files changed
+98 -31

No files matched your search

@@ -1,4 +1,4 @@
import React, { useState } from 'react'
import React, { FormEvent, useState } from 'react'
import { useTranslation } from 'react-i18next';
import { TextField, Button } from '@material-ui/core'
import AddIcon from '@material-ui/icons/Add';
@@ -12,32 +12,55 @@ const NewMessageGroupForm = () => {
const { t } = useTranslation();
const { setShowNewMessageGroup } = useModals();
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 parts = participants.split(',').map(part => part.replace(/[^0-9]/g, ''));
const isGroupChat = parts.length > 1;
const handleSubmit = () => {
// handles phone numbers in a csv format and strips all spaces and
// external characters out of them:
// 123-4567, 987-6543, 333-4444
const parts = participants.split(',').map(part => part.replace(/[^0-9]/g, ''));
Nui.send('phone:createMessageGroup', { phoneNumbers: parts });
setParticipants('');
setShowNewMessageGroup(false); // close modal after submission
const handleSubmit = (event: FormEvent) => {
event.preventDefault();
if (parts.length > 0) {
const labelValue = label.trim();
Nui.send('phone:createMessageGroup', {
phoneNumbers: parts,
label: isGroupChat && labelValue ? labelValue : null,
});
setParticipants('');
setShowNewMessageGroup(false); // close modal after submission
}
}
return (
<div className={classes.formTop}>
<form className={classes.newGroupForm} onSubmit={handleSubmit}>
<TextField
value={participants}
onChange={e => setParticipants(e.target.value)}
placeholder={t("APPS_MESSAGES_NEW_MESSAGE_GROUP")}
className={classes.input}
className={classes.newGroupinput}
inputProps={{
className: classes.messagesInput
}}
multiline
/>
<Button className={classes.sendButton} onClick={handleSubmit} >
<AddIcon fontSize="large" />
{isGroupChat && (
<TextField
value={label}
onChange={e => setLabel(e.target.value)}
placeholder={t("APPS_MESSAGES_GROUP_CHAT_LABEL")}
className={classes.newGroupinput}
inputProps={{
className: classes.messagesInput
}}
/>
)}
<Button variant="contained" className={classes.newGroupSubmitButton} color="primary" type="submit" >
{t("APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT")}
</Button>
</div>
</form>
)
}
@@ -12,16 +12,24 @@ const useStyles = makeStyles((theme) => ({
form: {
display: 'flex',
},
formTop: {
position: 'absolute',
top: 65,
display: 'flex',
width: '100%',
},
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
}
@@ -33,10 +33,10 @@ const MessagesList = (): any => {
button
>
<ListItemAvatar>
<MuiAvatar />
<MuiAvatar src={messageGroup?.avatar} />
</ListItemAvatar>
<ListItemText>
{messageGroup.groupDisplay}
{messageGroup.label || messageGroup.groupDisplay}
</ListItemText>
</ListItem>
))}
@@ -7,3 +7,8 @@
#messages-app .Mui-focused:after {
border-bottom-color: #ffa000 !important;
}
/* override form submit button */
#messages-app .MuiButton-containedPrimary {
background-color: #ffa000 !important;
}
+2
View File
@@ -13,5 +13,7 @@ export interface Message {
export interface MessageGroup {
groupId: string;
groupDisplay: string;
avatar?: string;
label?: string;
updatedAt: string;
}
+3 -1
View File
@@ -54,6 +54,8 @@
"APPS_CONTACT_FORM_AVATAR": "Avatar URL",
"APPS_MESSAGES_NEW_MESSAGE": "Message...",
"APPS_MESSAGES_NEW_MESSAGE_GROUP": "Phone numbers..."
"APPS_MESSAGES_NEW_MESSAGE_GROUP": "Phone numbers...",
"APPS_MESSAGES_GROUP_CHAT_LABEL": "Group chat label...",
"APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT": "Submit"
}
}