Skip to content

Commit

Permalink
fix: create new message setup
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterMotko committed Feb 10, 2022
1 parent e536c0d commit 4f2620d
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 107 deletions.
6 changes: 3 additions & 3 deletions src/components/Messaging/AnnounceMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const AnnounceMessageForm = () => {
MenuProps={MenuProps}
>
{orgList.map((org, i) => (
<MenuItem key={i} value={org.id}>
<MenuItem key={org.id ? org.id : i} value={org.id}>
{org.name}
</MenuItem>
))}
Expand All @@ -150,8 +150,8 @@ const AnnounceMessageForm = () => {
input={<OutlinedInput />}
id="select-reg"
>
{regions.map((region) => (
<MenuItem key={region.id} value={region.id}>
{regions.map((region, i) => (
<MenuItem key={region.id ? region.id : i} value={region.id}>
{region.name}
</MenuItem>
))}
Expand Down
176 changes: 87 additions & 89 deletions src/components/Messaging/MessageBody.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,95 @@
import React, { useState, useContext } from 'react';
import { createStyles, makeStyles } from '@material-ui/core/styles';
import { makeStyles } from '@material-ui/core/styles';
import { Avatar, Grid, Typography, Paper } from '@material-ui/core';
import { TextInput } from './TextInput.js';

import { MessagingContext } from 'context/MessagingContext.js';

const useStyles = makeStyles((theme) =>
createStyles({
messageRow: {
display: 'flex',
const useStyles = makeStyles((theme) => ({
messageRow: {
display: 'flex',
},
messageRowRight: {
display: 'flex',
justifyContent: 'flex-end',
},
recievedMessage: {
position: 'relative',
marginLeft: '20px',
marginBottom: '10px',
padding: '10px',
backgroundColor: 'lightGrey',
textAlign: 'left',
borderRadius: '10px',
},
sentMessage: {
position: 'relative',
marginRight: '20px',
marginBottom: '10px',
padding: '10px',
backgroundColor: theme.palette.primary.main,
textAlign: 'left',
borderRadius: '10px',
},
messageContent: {
padding: 0,
margin: 0,
wordWrap: 'break-word',
},
messageTimeStampLeft: {
display: 'flex',
marginRight: 'auto',
alignItems: 'center',
color: 'grey',
},
messageTimeStampRight: {
display: 'flex',
marginLeft: 'auto',
alignItems: 'center',
color: 'grey',
},
displayName: {
marginLeft: '20px',
},
paper: {
height: '100%',
display: 'flex',
alignItems: 'center',
flexDirection: 'column',
},
senderInfo: {
padding: '10px',
borderBottom: '2px solid black',
},
messagesBody: {
height: '80%',
width: '95%',
padding: '7.5px',
overflowY: 'auto',
},
senderItem: {
padding: theme.spacing(1),
margin: theme.spacing(1),
},
avatar: {
width: '5em',
height: '5em',
[theme.breakpoints.down('md')]: {
width: '4em',
height: '4em',
},
messageRowRight: {
display: 'flex',
justifyContent: 'flex-end',
[theme.breakpoints.down('sm')]: {
width: '2em',
height: '2em',
},
recievedMessage: {
position: 'relative',
marginLeft: '20px',
marginBottom: '10px',
padding: '10px',
backgroundColor: 'lightGrey',
textAlign: 'left',
borderRadius: '10px',
},
sentMessage: {
position: 'relative',
marginRight: '20px',
marginBottom: '10px',
padding: '10px',
backgroundColor: theme.palette.primary.main,
textAlign: 'left',
borderRadius: '10px',
},
messageContent: {
padding: 0,
margin: 0,
wordWrap: 'break-word',
},
messageTimeStampLeft: {
display: 'flex',
marginRight: 'auto',
alignItems: 'center',
color: 'grey',
},
messageTimeStampRight: {
display: 'flex',
marginLeft: 'auto',
alignItems: 'center',
color: 'grey',
},
displayName: {
marginLeft: '20px',
},
paper: {
height: '100%',
display: 'flex',
alignItems: 'center',
flexDirection: 'column',
},
senderInfo: {
padding: '10px',
borderBottom: '2px solid black',
},
messagesBody: {
height: '80%',
width: '95%',
padding: '7.5px',
overflowY: 'auto',
},
senderItem: {
padding: theme.spacing(1),
margin: theme.spacing(1),
},
avatar: {
width: '5em',
height: '5em',
[theme.breakpoints.down('md')]: {
width: '4em',
height: '4em',
},
[theme.breakpoints.down('sm')]: {
width: '2em',
height: '2em',
},
},
textInput: {
borderTop: '2px solid black',
},
surveyContent: {
color: '#fff',
},
})
);
},
textInput: {
borderTop: '2px solid black',
},
surveyContent: {
color: '#fff',
},
}));

export const AnnounceMessage = ({ message }) => {
const {
Expand Down Expand Up @@ -134,8 +132,8 @@ export const SurveyMessage = ({ message }) => {
<Typography variant={'h6'}>
Choices:
<ol type="A">
{question.choices.map((choice) => (
<li key={choice}>{choice}</li>
{question.choices.map((choice, i) => (
<li key={choice ? choice : i}>{choice}</li>
))}
</ol>
</Typography>
Expand Down Expand Up @@ -244,7 +242,7 @@ const MessageBody = ({ messages, messageRecipient }) => {
{messageRecipient && messages ? (
<SenderInformation messageRecipient={messageRecipient} id={''} />
) : (
<SenderInformation></SenderInformation>
<SenderInformation />
)}
<div id="style-1" className={messagesBody}>
{messages ? (
Expand Down
10 changes: 8 additions & 2 deletions src/components/Messaging/Messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Inbox from './Inbox';
import MessageBody from './MessageBody';
import Survey from './Survey';
import AnnounceMessage from './AnnounceMessage';

import NewMessage from './NewMessage';
import Grid from '@material-ui/core/Grid';
import Button from '@material-ui/core/Button';
import { makeStyles } from '@material-ui/styles';
Expand Down Expand Up @@ -78,7 +78,9 @@ const Messaging = () => {
const [toggleSurvey, setToggleSurvey] = useState(false);
const [messageRecipient, setMessageRecipient] = useState('');
const [selectedIndex, setSelectedIndex] = useState(0);

const [openModal, setOpenModal] = useState(false);
const handleOpen = () => setOpenModal(true);
const handleClose = () => setOpenModal(false);
useEffect(() => {
if (messages.length && messageRecipient === '') {
setMessageRecipient(messages[0].userName);
Expand All @@ -98,6 +100,10 @@ const Messaging = () => {
<h1>Inbox</h1>
</Grid>
<Grid item className={buttonContainer}>
<Button className={button} onClick={handleOpen}>
New Message
</Button>
<NewMessage openModal={openModal} handleClose={handleClose} />
<Button
className={button}
onClick={() => setToggleAnnounceMessage(!toggleAnnounceMessage)}
Expand Down
123 changes: 123 additions & 0 deletions src/components/Messaging/NewMessage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import React, { useState, useContext } from 'react';
import { MessagingContext } from 'context/MessagingContext';
import {
FormControl,
Box,
Modal,
TextField,
Select,
MenuItem,
Typography,
Button,
} from '@material-ui/core';
import { makeStyles } from '@material-ui/styles';

import GSInputLabel from 'components/common/InputLabel';

const useStyles = makeStyles((theme) => ({
box: {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: 300,
height: 400,
backgroundColor: '#FFF',
border: `2px solid ${theme.palette.primary.main}`,
borderRadius: 20,
boxShadow: 24,
padding: 20,
textAlign: 'center',
},
header: {
color: theme.palette.primary.main,
borderBottom: `2px solid black`,
padding: 10,
},
button: {
margin: '10px 0',
background: theme.palette.primary.main,
color: 'white',
},
}));

const NewMessage = ({ openModal, handleClose }) => {
const { box, header, button } = useStyles();
const { user, postMessageSend } = useContext(MessagingContext);
const [messageContent, setMessageContent] = useState({ to: '', body: '' });

const handleChange = (e) => {
const { name, value } = e.target;
setMessageContent({
...messageContent,
[name]: value,
});
};

const handleSubmit = async (e) => {
e.preventDefault();

const messagePayload = {
author_handle: user.userName,
recipient_handle: messageContent.to,
subject: 'Message',
body: messageContent.body,
};
``;

if (
messagePayload.body !== '' &&
user.userName &&
messagePayload.to !== ''
) {
await postMessageSend(messagePayload);
}
setMessageContent({ to: '', body: '' });
};
return (
<Modal
open={openModal}
onClose={handleClose}
aria-labelledby="modal-modal-title"
aria-describedby="modal-modal-description"
>
<Box className={box}>
<form onSubmit={handleSubmit}>
<FormControl fullWidth spacing={2}>
<Box className={header} my={1}>
<Typography variant="h3">Send New Message</Typography>
</Box>
<GSInputLabel
id="select-label"
text="Choose the message recipient"
/>
<Select
labelId="select-label"
id="select"
variant="filled"
label="Recipient"
name="to"
value={messageContent.to}
onChange={handleChange}
>
<MenuItem>Something</MenuItem>
</Select>
<GSInputLabel text="Message" />
<TextField
multiline
placeholder="Write you message here ..."
name="body"
value={messageContent.body}
onChange={handleChange}
/>
<Button type="submit" size="large" className={button}>
Send Message
</Button>
</FormControl>
</form>
</Box>
</Modal>
);
};

export default NewMessage;
Loading

0 comments on commit 4f2620d

Please sign in to comment.