mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 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 {
|
||||
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 { Box, makeStyles, TextField } from '@material-ui/core';
|
||||
import { useQueryParams } from '../../../common/hooks/useQueryParams';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
import dayjs from 'dayjs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { EmailList } from './EmailList';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
search: {
|
||||
@@ -29,20 +15,15 @@ const useStyles = makeStyles((theme) => ({
|
||||
|
||||
export const InboxPage = () => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { emails } = useEmail();
|
||||
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
||||
|
||||
const [search, setSearch] = useState<string>('');
|
||||
|
||||
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
||||
|
||||
const handleSearch = (e) => {
|
||||
setSearch(e.target.value);
|
||||
};
|
||||
|
||||
const getSendDate = (email) => dayjs.unix(email.sendDate).format(t('DATE_FORMAT'));
|
||||
|
||||
return (
|
||||
<Box height="100%" pt="80px" position="relative">
|
||||
<Box width="100%" p={2} className={classes.search}>
|
||||
@@ -56,32 +37,7 @@ export const InboxPage = () => {
|
||||
/>
|
||||
</Box>
|
||||
<Box overflow="auto" maxHeight="100%">
|
||||
<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>
|
||||
<EmailList emails={emails} />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Box, makeStyles, TextField } from '@material-ui/core';
|
||||
import React, { useState } from 'react';
|
||||
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) => ({
|
||||
search: {
|
||||
@@ -9,23 +11,34 @@ const useStyles = makeStyles((theme) => ({
|
||||
width: '100%',
|
||||
top: 0,
|
||||
},
|
||||
sendBtn: {
|
||||
position: 'absolute',
|
||||
right: theme.spacing(2),
|
||||
bottom: theme.spacing(2),
|
||||
},
|
||||
}));
|
||||
|
||||
export const NewEmailPage = () => {
|
||||
const classes = useStyles();
|
||||
// const [subject, setSubject] = useState<string>('');
|
||||
// const [receivers, setReceivers] = useState<string>('');
|
||||
const { t } = useTranslation();
|
||||
const [subject, setSubject] = useState<string>('');
|
||||
const [receivers, setReceivers] = useState<string>('');
|
||||
const [body, setBody] = useState<string>('');
|
||||
|
||||
const handleSubject = (e) => {
|
||||
// setSubject(e.target.value || '');
|
||||
setSubject(e.target.value || '');
|
||||
};
|
||||
|
||||
const handleReceiver = (e) => {
|
||||
// setReceivers(e.target.value || '');
|
||||
setReceivers(e.target.value || '');
|
||||
};
|
||||
|
||||
const handleBody = (e) => {
|
||||
setBody(e.target.value || '');
|
||||
};
|
||||
|
||||
return (
|
||||
<Box height="100%" pt="120px">
|
||||
<Box height="100%" pt="180px">
|
||||
<Box p={2} className={classes.search}>
|
||||
<TextField
|
||||
variant="outlined"
|
||||
@@ -33,6 +46,7 @@ export const NewEmailPage = () => {
|
||||
color="primary"
|
||||
helperText="Add receivers separated by a comma"
|
||||
fullWidth
|
||||
value={receivers}
|
||||
onChange={handleReceiver}
|
||||
/>
|
||||
<TextField
|
||||
@@ -40,10 +54,24 @@ export const NewEmailPage = () => {
|
||||
placeholder="Subject"
|
||||
color="primary"
|
||||
fullWidth
|
||||
value={subject}
|
||||
onChange={handleSubject}
|
||||
/>
|
||||
</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>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user