mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
Email app create email form
This commit is contained in:
1 parent
6569f94cd5
commit
c2510266f8
3 files changed
+94
-56
No files matched your search
@@ -0,0 +1,54 @@
|
|||||||
|
import {
|
||||||
|
Avatar,
|
||||||
|
IconButton,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
|
ListItemAvatar,
|
||||||
|
ListItemSecondaryAction,
|
||||||
|
ListItemText,
|
||||||
|
} from '@material-ui/core';
|
||||||
|
import React from 'react';
|
||||||
|
import { IEmail } from '../../../common/typings/email';
|
||||||
|
import MarkRead from '@material-ui/icons/Markunread';
|
||||||
|
import MarkUnread from '@material-ui/icons/MarkunreadMailbox';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
interface IProps {
|
||||||
|
emails: IEmail[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EmailList = ({ emails }: IProps) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const getSendDate = (email) => dayjs.unix(email.sendDate).format(t('DATE_FORMAT'));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<List>
|
||||||
|
{emails &&
|
||||||
|
emails.map((email) => (
|
||||||
|
<ListItem button divider key={email.id}>
|
||||||
|
<ListItemAvatar>
|
||||||
|
<Avatar>{email.sender.charAt(0).toUpperCase()}</Avatar>
|
||||||
|
</ListItemAvatar>
|
||||||
|
<ListItemText
|
||||||
|
secondary={
|
||||||
|
email.isRead ? (
|
||||||
|
<span>{getSendDate(email)}</span>
|
||||||
|
) : (
|
||||||
|
<strong>{getSendDate(email)}</strong>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{email.isRead ? <span>{email.subject}</span> : <strong>{email.subject}</strong>}
|
||||||
|
</ListItemText>
|
||||||
|
<ListItemSecondaryAction>
|
||||||
|
<IconButton>
|
||||||
|
{email.isRead ? <MarkUnread color="primary" /> : <MarkRead color="primary" />}
|
||||||
|
</IconButton>
|
||||||
|
</ListItemSecondaryAction>
|
||||||
|
</ListItem>
|
||||||
|
))}
|
||||||
|
</List>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,22 +1,8 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import {
|
import { Box, makeStyles, TextField } from '@material-ui/core';
|
||||||
Avatar,
|
|
||||||
Box,
|
|
||||||
IconButton,
|
|
||||||
List,
|
|
||||||
ListItem,
|
|
||||||
ListItemAvatar,
|
|
||||||
ListItemSecondaryAction,
|
|
||||||
ListItemText,
|
|
||||||
makeStyles,
|
|
||||||
TextField,
|
|
||||||
} from '@material-ui/core';
|
|
||||||
import MarkRead from '@material-ui/icons/Markunread';
|
|
||||||
import MarkUnread from '@material-ui/icons/MarkunreadMailbox';
|
|
||||||
import { useQueryParams } from '../../../common/hooks/useQueryParams';
|
import { useQueryParams } from '../../../common/hooks/useQueryParams';
|
||||||
import { useEmail } from '../hooks/useEmail';
|
import { useEmail } from '../hooks/useEmail';
|
||||||
import dayjs from 'dayjs';
|
import { EmailList } from './EmailList';
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
search: {
|
search: {
|
||||||
@@ -29,20 +15,15 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
|
|
||||||
export const InboxPage = () => {
|
export const InboxPage = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const { emails } = useEmail();
|
const { emails } = useEmail();
|
||||||
|
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
||||||
|
|
||||||
const [search, setSearch] = useState<string>('');
|
const [search, setSearch] = useState<string>('');
|
||||||
|
|
||||||
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
|
||||||
|
|
||||||
const handleSearch = (e) => {
|
const handleSearch = (e) => {
|
||||||
setSearch(e.target.value);
|
setSearch(e.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSendDate = (email) => dayjs.unix(email.sendDate).format(t('DATE_FORMAT'));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box height="100%" pt="80px" position="relative">
|
<Box height="100%" pt="80px" position="relative">
|
||||||
<Box width="100%" p={2} className={classes.search}>
|
<Box width="100%" p={2} className={classes.search}>
|
||||||
@@ -56,32 +37,7 @@ export const InboxPage = () => {
|
|||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box overflow="auto" maxHeight="100%">
|
<Box overflow="auto" maxHeight="100%">
|
||||||
<List>
|
<EmailList emails={emails} />
|
||||||
{emails &&
|
|
||||||
emails.map((email) => (
|
|
||||||
<ListItem button divider key={email.id}>
|
|
||||||
<ListItemAvatar>
|
|
||||||
<Avatar>{email.sender.charAt(0).toUpperCase()}</Avatar>
|
|
||||||
</ListItemAvatar>
|
|
||||||
<ListItemText
|
|
||||||
secondary={
|
|
||||||
email.isRead ? (
|
|
||||||
<span>{getSendDate(email)}</span>
|
|
||||||
) : (
|
|
||||||
<strong>{getSendDate(email)}</strong>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{email.isRead ? <span>{email.subject}</span> : <strong>{email.subject}</strong>}
|
|
||||||
</ListItemText>
|
|
||||||
<ListItemSecondaryAction>
|
|
||||||
<IconButton>
|
|
||||||
{email.isRead ? <MarkUnread color="primary" /> : <MarkRead color="primary" />}
|
|
||||||
</IconButton>
|
|
||||||
</ListItemSecondaryAction>
|
|
||||||
</ListItem>
|
|
||||||
))}
|
|
||||||
</List>
|
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Box, makeStyles, TextField } from '@material-ui/core';
|
import SendIcon from '@material-ui/icons/Send';
|
||||||
|
import { Box, Fab, makeStyles, TextField } from '@material-ui/core';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
search: {
|
search: {
|
||||||
@@ -9,23 +11,34 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
top: 0,
|
top: 0,
|
||||||
},
|
},
|
||||||
|
sendBtn: {
|
||||||
|
position: 'absolute',
|
||||||
|
right: theme.spacing(2),
|
||||||
|
bottom: theme.spacing(2),
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const NewEmailPage = () => {
|
export const NewEmailPage = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
// const [subject, setSubject] = useState<string>('');
|
const { t } = useTranslation();
|
||||||
// const [receivers, setReceivers] = useState<string>('');
|
const [subject, setSubject] = useState<string>('');
|
||||||
|
const [receivers, setReceivers] = useState<string>('');
|
||||||
|
const [body, setBody] = useState<string>('');
|
||||||
|
|
||||||
const handleSubject = (e) => {
|
const handleSubject = (e) => {
|
||||||
// setSubject(e.target.value || '');
|
setSubject(e.target.value || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReceiver = (e) => {
|
const handleReceiver = (e) => {
|
||||||
// setReceivers(e.target.value || '');
|
setReceivers(e.target.value || '');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBody = (e) => {
|
||||||
|
setBody(e.target.value || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box height="100%" pt="120px">
|
<Box height="100%" pt="180px">
|
||||||
<Box p={2} className={classes.search}>
|
<Box p={2} className={classes.search}>
|
||||||
<TextField
|
<TextField
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@@ -33,6 +46,7 @@ export const NewEmailPage = () => {
|
|||||||
color="primary"
|
color="primary"
|
||||||
helperText="Add receivers separated by a comma"
|
helperText="Add receivers separated by a comma"
|
||||||
fullWidth
|
fullWidth
|
||||||
|
value={receivers}
|
||||||
onChange={handleReceiver}
|
onChange={handleReceiver}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -40,10 +54,24 @@ export const NewEmailPage = () => {
|
|||||||
placeholder="Subject"
|
placeholder="Subject"
|
||||||
color="primary"
|
color="primary"
|
||||||
fullWidth
|
fullWidth
|
||||||
|
value={subject}
|
||||||
onChange={handleSubject}
|
onChange={handleSubject}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box>New Email</Box>
|
<Box px={1}>
|
||||||
|
<TextField
|
||||||
|
label={t('GENERIC_CONTENT')}
|
||||||
|
multiline
|
||||||
|
fullWidth
|
||||||
|
rows={16}
|
||||||
|
variant="outlined"
|
||||||
|
value={body}
|
||||||
|
onChange={handleBody}
|
||||||
|
/>
|
||||||
|
<Fab disabled={!body || !receivers} className={classes.sendBtn} color="primary">
|
||||||
|
<SendIcon />
|
||||||
|
</Fab>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user