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(); 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 (
setName(e.target.value)} label={t('APPS_CONTACT_FORM_NAME')} fullWidth inputProps={{ className: classes.inputProps, }} /> setNumber(e.target.value)} label={t('APPS_CONTACT_FORM_NUMBER')} fullWidth inputProps={{ className: classes.inputProps, }} /> setAvatar(e.target.value)} inputProps={{ className: classes.inputProps, }} /> {/* Display if fetched contact */} {contact && ( <> )} {/* Display if no fetched contact */} {!contact && ( )}
); }; export default ContactsInfoPage;