feat(phone/dialer): add contacts from dialer history

This commit is contained in:
Christopher committed 2021-02-23 23:19:29 +01:00
1 parent 51fb261e8a
commit d4fbdc8e0c
5 files changed
+70 -12

No files matched your search

@@ -45,7 +45,7 @@ InjectDebugData([
{
id: 3,
display: 'Chip',
number: '417-8792',
number: '777-7777',
},
],
},
@@ -39,7 +39,7 @@ export const DialerApp = () => {
InjectDebugData([
{
app: 'DIALER',
app: 'DAILER',
method: 'setHistory',
data: [
{
@@ -1,7 +1,8 @@
import React from 'react';
import ListItemText from '@material-ui/core/ListItemText';
import PhoneCallbackIcon from '@material-ui/icons/PhoneCallback';
import PhoneForwardedIcon from '@material-ui/icons/PhoneForwarded';
import PhoneIcon from '@material-ui/icons/Phone';
import PersonAddIcon from '@material-ui/icons/PersonAdd';
import { List } from '../../../../ui/components/List';
import { ListItem } from '../../../../ui/components/ListItem';
import Nui from '../../../../os/nui-events/utils/Nui';
@@ -10,11 +11,27 @@ import { useContacts } from '../../../contacts/hooks/useContacts';
import { ICall } from '../../../../common/typings/call';
import dayjs from 'dayjs';
import { useTranslation } from 'react-i18next';
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
import { useHistory } from 'react-router-dom';
import { makeStyles, Theme } from '@material-ui/core/styles';
const useStyles = makeStyles((theme: Theme) => ({
callForward: {
color: theme.palette.success.main,
},
callBack: {
color: theme.palette.error.main,
},
}));
export const DialerHistory = ({ calls }) => {
const { number } = useSimcard();
const { getDisplayByNumber } = useContacts();
const classes = useStyles();
const history = useHistory();
const { t } = useTranslation();
const handleCall = (phoneNumber) => {
@@ -23,8 +40,17 @@ export const DialerHistory = ({ calls }) => {
});
};
if (!calls) {
return <p>Things are loading or arent here at all</p>;
if (!calls?.length) {
return (
<Box
display='flex'
justifyContent='center'
alignItems='center'
paddingTop={35}
>
<p>You got no friends!😎</p>
</Box>
);
}
return (
@@ -34,27 +60,59 @@ export const DialerHistory = ({ calls }) => {
<ListItem
key={call.id}
divider
button
onClick={() => handleCall(call.receiver)}
>
<ListItemIcon>
{<PhoneForwardedIcon className={classes.callForward} />}
</ListItemIcon>
<ListItemText
primary={getDisplayByNumber(call.receiver)}
secondary={new Date(call.start).getUTCDate()}
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))}
/>
{<PhoneForwardedIcon />}
<IconButton onClick={() => handleCall(call.receiver)}>
{<PhoneIcon />}
</IconButton>
<IconButton
onClick={() =>
history.push(
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
)
}
>
{<PersonAddIcon />}
</IconButton>
</ListItem>
) : (
<ListItem
key={call.id}
divider
button
onClick={() => handleCall(call.transmitter)}
>
<ListItemIcon>
{<PhoneCallbackIcon className={classes.callBack} />}
</ListItemIcon>
<ListItemText
primary={getDisplayByNumber(call.transmitter)}
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))}
/>
{<PhoneCallbackIcon />}
<IconButton onClick={() => handleCall(call.receiver)}>
{<PhoneIcon />}
</IconButton>
{getDisplayByNumber(call.transmitter) === call.transmitter ? (
<IconButton
onClick={() =>
history.push(
`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`
)
}
>
{<PersonAddIcon />}
</IconButton>
) : null}
</ListItem>
)
)}
+1 -1
View File
@@ -3,6 +3,6 @@ import { atom } from 'recoil';
export const dialState = {
history: atom({
key: 'dialHistory',
default: null,
default: [],
}),
};
@@ -5,7 +5,7 @@ interface ICallUI {
history: ICall[];
}
export const useDialHistory = (): ICallUI => {
export const useDialHistory = (): ICallUI[] => {
const history = useRecoilValue(dialState.history);
return history;
};