Files
new-phone-who-dis/phone/src/apps/contacts/components/views/ContactInfo.tsx
T
J Francisco Rader 4acb214ec9 Task/improve hardcoded styles and types (#107)
* Add working notifications with only twitter for now

* feat(notification-bar): I didnt copy from NP

* feat(notifications): Collapse when no more notifications after closing one

* Improve overall messages styling code

* Improve Routing performance

* improve use keyboard hook

* Remove unused returns

* Button hover color :)

* Button hover color :) x2

* Added hover style to containedPrimary msg btn

* Replace custom components for custom theme providers for Messages and Contacts apps

* Improve createAppThemeProvider

* Improve createAppThemeProvider

* Final housekeeping for messages styles

* Change placeholder to label in Contacts app text fields

* Fix alerts style with navigation and fix calc copy alerrt

* Split Phone code for snackbar

* Add more options and style Context Menu

* Enable Sellout theme provider and make it work with light themes
2021-02-21 12:41:25 -05:00

186 lines
4.5 KiB
TypeScript

import React, { useState } from 'react';
import {
Avatar as MuiAvatar,
Box,
Button,
Paper,
TextField,
} from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import { useTranslation } from 'react-i18next';
import { useHistory, useParams } from 'react-router-dom';
import { useContacts } from '../../hooks/useContacts';
import Nui from '../../../../os/nui-events/utils/Nui';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
interface ContactInfoRouteParams {
mode: string;
id: string;
}
const useStyles = makeStyles((theme: Theme) => ({
root: {
height: '100%',
width: '100%',
},
listContainer: {
marginTop: 30,
width: '75%',
margin: '0 auto',
textAlign: 'center',
},
avatar: {
margin: 'auto',
height: '125px',
width: '124px',
marginBottom: 29,
},
input: {
marginBottom: 20,
margin: 'auto',
textAlign: 'center',
},
inputProps: {
fontSize: 22,
},
}));
const ContactsInfoPage = () => {
const classes = useStyles();
const history = useHistory();
const { getContact } = useContacts();
const { id } = useParams<ContactInfoRouteParams>();
const contact = getContact(parseInt(id));
// Set state after checking if null
const [name, setName] = useState(contact ? contact.display : '');
const [number, setNumber] = useState(contact ? contact.number : '');
const [avatar, setAvatar] = useState(contact ? contact.avatar : '');
const { t } = useTranslation();
const handleContactAdd = () => {
LogDebugEvent({
action: 'Handling Contact Add',
data: contact,
level: 2,
});
Nui.send('phone:addContacts', {
display: name,
number,
avatar,
});
history.goBack();
};
const handleContactSave = () => {
LogDebugEvent({
action: 'Handling Contact Update',
data: contact,
level: 2,
});
Nui.send('phone:updateContact', {
id: contact.id,
display: name,
number,
avatar,
});
history.goBack();
};
const handleContactDelete = () => {
LogDebugEvent({
action: 'Handling Contact Delete',
data: contact,
level: 2,
});
Nui.send('phone:deleteContact', {
id: contact.id,
});
history.goBack();
};
return (
<Paper className={classes.root} square>
<Button style={{ margin: 10 }} onClick={() => history.goBack()}>
<ArrowBackIcon fontSize='large' />
</Button>
<div className={classes.listContainer}>
<MuiAvatar className={classes.avatar} src={avatar} />
<TextField
className={classes.input}
value={name}
onChange={(e) => setName(e.target.value)}
label={t('APPS_CONTACT_FORM_NAME')}
fullWidth
inputProps={{
className: classes.inputProps,
}}
/>
<TextField
className={classes.input}
value={number}
onChange={(e) => setNumber(e.target.value)}
label={t('APPS_CONTACT_FORM_NUMBER')}
fullWidth
inputProps={{
className: classes.inputProps,
}}
/>
<TextField
className={classes.input}
label={t('APPS_CONTACT_FORM_AVATAR')}
fullWidth
value={avatar}
onChange={(e) => setAvatar(e.target.value)}
inputProps={{
className: classes.inputProps,
}}
/>
{/* Display if fetched contact */}
{contact && (
<>
<Box py={1} display='block'>
<Button
color='primary'
variant='contained'
onClick={handleContactSave}
>
{t('GENERIC_UPDATE')}
</Button>
</Box>
<Box py={1} display='block'>
<Button
variant='contained'
color='secondary'
onClick={handleContactDelete}
>
{t('GENERIC_DELETE')}
</Button>
</Box>
</>
)}
{/* Display if no fetched contact */}
{!contact && (
<Box display='block'>
<Button
color='primary'
variant='contained'
onClick={handleContactAdd}
>
{t('APPS_CONTACT_MODAL_BUTTON_ADD')}
</Button>
</Box>
)}
</div>
</Paper>
);
};
export default ContactsInfoPage;