From 74f43efddbc1f0dd17f894930068ecb9000d2790 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 11 Dec 2020 22:13:31 +0100 Subject: [PATCH] feats(contacts/nui): cleanup | esx.js | translation for contacts --- .../apps/contacts/components/ContactModal.tsx | 95 ++++++------------- .../apps/contacts/components/ContactTitle.tsx | 28 +----- .../apps/contacts/components/ContactsApp.tsx | 22 +---- .../contacts/components/List/ContactList.tsx | 48 +++++----- .../components/List/SearchContacts.tsx | 63 ++++++------ .../components/alert/ContactAlert.tsx | 59 ++++++++++++ .../contacts/components/modal/InfoModal.tsx | 38 ++++---- .../components/styles.contactmodal.ts | 45 +++++++++ .../contacts/components/styles.contacts.ts | 35 +++++++ phone/src/apps/contacts/hooks/state.ts | 18 ++-- phone/src/locale/en.json | 9 +- resources/package.json | 1 + 12 files changed, 265 insertions(+), 196 deletions(-) create mode 100644 phone/src/apps/contacts/components/alert/ContactAlert.tsx create mode 100644 phone/src/apps/contacts/components/styles.contactmodal.ts create mode 100644 phone/src/apps/contacts/components/styles.contacts.ts diff --git a/phone/src/apps/contacts/components/ContactModal.tsx b/phone/src/apps/contacts/components/ContactModal.tsx index eaa6993..e5b15ad 100644 --- a/phone/src/apps/contacts/components/ContactModal.tsx +++ b/phone/src/apps/contacts/components/ContactModal.tsx @@ -1,71 +1,30 @@ -import React, { useState } from "react"; -import { makeStyles, Theme } from "@material-ui/core/styles"; -import { Button, TextField } from "@material-ui/core"; -import Nui from "../../../os/nui-events/utils/Nui"; -import List from "@material-ui/core/List"; -import ListItem from "@material-ui/core/ListItem"; -import Modal from "../../../ui/components/Modal"; -import { useModal } from "../hooks/useModal"; -import ClearIcon from "@material-ui/icons/Clear"; -import PersonIcon from "@material-ui/icons/Person"; -import PhoneIcon from "@material-ui/icons/Phone"; -import AccountCircleIcon from "@material-ui/icons/AccountCircle"; - -const useStyles = makeStyles((theme: Theme) => ({ - button: { - margin: 5, - marginTop: 20, - }, - root: { - position: "fixed", - bottom: 380, - zIndex: 2, - background: "#232323", - marginLeft: "-4em", - height: "20%", - }, - clearButton: { - width: "10%", - position: "absolute", - right: 0, - }, - textInputField: { - fontSize: 20, - borderBottomColor: "red", - }, - addBtn: { - margin: "auto", - fontSize: 16, - width: 150, - background: "#2196f3", - marginBottom: 10, - padding: 8, - }, - cancelBtn: { - margin: "auto", - width: 150, - background: "#232323", - marginBottom: 20, - padding: 8, - }, - icons: { - marginRight: 5, - }, -})); +import React, { useState } from 'react'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import { Button, TextField } from '@material-ui/core'; +import Nui from '../../../os/nui-events/utils/Nui'; +import List from '@material-ui/core/List'; +import ListItem from '@material-ui/core/ListItem'; +import Modal from '../../../ui/components/Modal'; +import { useModal } from '../hooks/useModal'; +import ClearIcon from '@material-ui/icons/Clear'; +import PersonIcon from '@material-ui/icons/Person'; +import PhoneIcon from '@material-ui/icons/Phone'; +import AccountCircleIcon from '@material-ui/icons/AccountCircle'; +import useStyles from './styles.contactmodal'; export const AddContactModal = () => { - const [name, setName] = useState(""); - const [number, setNumber] = useState(""); - const [avatar, setAvatar] = useState(""); + const [name, setName] = useState(''); + const [number, setNumber] = useState(''); + const [avatar, setAvatar] = useState(''); const classes = useStyles(); const { showModal, setShowModal } = useModal(); const addContact = () => { - if (name === "" || number === "") { - console.log("You need to pass in values"); + if (name === '' || number === '') { + console.log('You need to pass in values'); } else { - Nui.send("contacts:add", { + Nui.send('contacts:add', { name, number, avatar, @@ -91,8 +50,8 @@ export const AddContactModal = () => { inputProps={{ className: classes.textInputField }} onChange={(e) => setName(e.target.value)} fullWidth - variant="standard" - placeholder="Name" + variant='standard' + placeholder='Name' /> @@ -102,9 +61,9 @@ export const AddContactModal = () => { inputProps={{ className: classes.textInputField }} onChange={(e) => setNumber(e.target.value)} fullWidth - placeholder="Number" - variant="standard" - type="text" + placeholder='Number' + variant='standard' + type='text' /> @@ -114,9 +73,9 @@ export const AddContactModal = () => { inputProps={{ className: classes.textInputField }} onChange={(e) => setAvatar(e.target.value)} fullWidth - placeholder="Avatar URL" - variant="standard" - type="text" + placeholder='Avatar URL' + variant='standard' + type='text' /> diff --git a/phone/src/apps/contacts/components/ContactTitle.tsx b/phone/src/apps/contacts/components/ContactTitle.tsx index 75f0944..adcda87 100644 --- a/phone/src/apps/contacts/components/ContactTitle.tsx +++ b/phone/src/apps/contacts/components/ContactTitle.tsx @@ -1,30 +1,12 @@ -import React from "react"; -import { makeStyles, createStyles, Theme } from "@material-ui/core/styles"; -import Paper from "@material-ui/core/Paper"; -import ContactsIcon from "@material-ui/icons/Contacts"; - -const useStyles = makeStyles((theme: Theme) => - createStyles({ - root: { - height: "60px", - width: "100%", - display: "flex", - flexFlow: "row nowrap", - justifyContent: "center", - alignItems: "center", - background: "#424242", - }, - icon: { - color: "#fff", - fontSize: 30, - }, - }) -); +import React from 'react'; +import Paper from '@material-ui/core/Paper'; +import ContactsIcon from '@material-ui/icons/Contacts'; +import useStyles from './styles.contacts'; export const ContactTitle = () => { const classes = useStyles(); return ( - + ); diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx index 2357026..622da53 100644 --- a/phone/src/apps/contacts/components/ContactsApp.tsx +++ b/phone/src/apps/contacts/components/ContactsApp.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { AppWrapper } from '../../../ui/components'; -import { makeStyles, createStyles, Theme } from '@material-ui/core/styles'; import { AppTitle } from '../../../ui/components/AppTitle'; import { AppContent } from '../../../ui/components/AppContent'; import { ContactList } from './List/ContactList'; @@ -10,30 +9,11 @@ import { useModal } from '../hooks/useModal'; import { SearchContacts } from './List/SearchContacts'; import PersonAddIcon from '@material-ui/icons/PersonAdd'; import Fab from '@material-ui/core/Fab'; -import { useContactModal } from '../hooks/useContactModal'; import { InfoModal } from './modal/InfoModal'; import { useContactDetail } from '../hooks/useContactDetail'; import { ContactAlert } from './alert/ContactAlert'; -const useStyles = makeStyles((theme: Theme) => - createStyles({ - backgroundModal: { - background: 'black', - opacity: '0.6', - position: 'absolute', - top: 0, - left: 0, - right: 0, - bottom: 0, - zIndex: 5, - }, - absolute: { - position: 'sticky', - bottom: theme.spacing(2), - left: theme.spacing(3), - }, - }) -); +import useStyles from './styles.contacts'; export const ContactsApp = () => { const classes = useStyles(); diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx index 2edfdcf..30983a3 100644 --- a/phone/src/apps/contacts/components/List/ContactList.tsx +++ b/phone/src/apps/contacts/components/List/ContactList.tsx @@ -1,5 +1,5 @@ -import React from "react"; -import ListItemText from "@material-ui/core/ListItemText"; +import React from 'react'; +import ListItemText from '@material-ui/core/ListItemText'; import { Button, ListItemAvatar, @@ -9,41 +9,41 @@ import { TextField, Collapse, makeStyles, -} from "@material-ui/core"; +} from '@material-ui/core'; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faPen } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faPen } from '@fortawesome/free-solid-svg-icons'; -import { useFilteredContacts } from "../../hooks/useFilteredContacts"; +import { useFilteredContacts } from '../../hooks/useFilteredContacts'; -import PhoneIcon from "@material-ui/icons/Phone"; -import ChatIcon from "@material-ui/icons/Chat"; -import MoreVertIcon from "@material-ui/icons/MoreVert"; -import { useContacts } from "../../hooks/useContacts"; -import { useContactModal } from "../../hooks/useContactModal"; -import { useContactDetail } from "../../hooks/useContactDetail"; +import PhoneIcon from '@material-ui/icons/Phone'; +import ChatIcon from '@material-ui/icons/Chat'; +import MoreVertIcon from '@material-ui/icons/MoreVert'; +import { useContacts } from '../../hooks/useContacts'; +import { useContactModal } from '../../hooks/useContactModal'; +import { useContactDetail } from '../../hooks/useContactDetail'; -import Nui from "../../../../os/nui-events/utils/Nui"; +import Nui from '../../../../os/nui-events/utils/Nui'; -import "../Contact.css"; +import '../Contact.css'; +import { ContactAlert } from '../alert/ContactAlert'; const useStyles = makeStyles((theme) => ({ updateButton: { - margin: "auto", + margin: 'auto', fontSize: 14, width: 150, - background: "#2196f3", + background: '#2196f3', marginBottom: 10, padding: 8, }, collapseItem: { - margin: "auto", - width: "50%", + margin: 'auto', + width: '50%', }, })); export const ContactList = () => { - const classes = useStyles(); const { filteredContacts } = useFilteredContacts(); const { setShowContactModal } = useContactModal(); const { contactDetail, setContactDetail } = useContactDetail(); @@ -53,11 +53,11 @@ export const ContactList = () => { const openContactInfo = (contact) => { setShowContactModal(true); setContactDetail(contact); - console.log("CONTACT", contactDetail); + console.log('CONTACT', contactDetail); }; const startCall = (number) => { console.log(number); - Nui.send("phone:startCall", { + Nui.send('phone:startCall', { number, }); }; @@ -67,8 +67,8 @@ export const ContactList = () => { {contacts.contacts .filter( (contact) => - contact.display.includes(filteredContacts) || - contact.number.includes(filteredContacts) + contact.display.includes(filteredContacts.toLowerCase()) || + contact.number.includes(filteredContacts.toLowerCase()) ) .map((contact) => ( <> @@ -91,7 +91,7 @@ export const ContactList = () => {
@@ -69,7 +69,7 @@ export const InfoModal = () => { className={classes.input} value={display} onChange={(e) => setDisplay(e.target.value)} - placeholder={t("APPS_CONTACT_FORM_NAME")} + placeholder={t('APPS_CONTACT_FORM_NAME')} fullWidth inputProps={{ className: classes.inputProps, @@ -79,7 +79,7 @@ export const InfoModal = () => { className={classes.input} value={number} onChange={(e) => setNumber(e.target.value)} - placeholder={t("APPS_CONTACT_FORM_NUMBER")} + placeholder={t('APPS_CONTACT_FORM_NUMBER')} fullWidth inputProps={{ className: classes.inputProps, @@ -87,7 +87,7 @@ export const InfoModal = () => { /> setAvatar(e.target.value)} @@ -96,7 +96,7 @@ export const InfoModal = () => { }} /> -
+
diff --git a/phone/src/apps/contacts/components/styles.contactmodal.ts b/phone/src/apps/contacts/components/styles.contactmodal.ts new file mode 100644 index 0000000..b208bb9 --- /dev/null +++ b/phone/src/apps/contacts/components/styles.contactmodal.ts @@ -0,0 +1,45 @@ +import { makeStyles, Theme } from '@material-ui/core/styles'; + +const useStyles = makeStyles((theme: Theme) => ({ + button: { + margin: 5, + marginTop: 20, + }, + root: { + position: 'fixed', + bottom: 380, + zIndex: 2, + background: '#232323', + marginLeft: '-4em', + height: '20%', + }, + clearButton: { + width: '10%', + position: 'absolute', + right: 0, + }, + textInputField: { + fontSize: 20, + borderBottomColor: 'red', + }, + addBtn: { + margin: 'auto', + fontSize: 16, + width: 150, + background: '#2196f3', + marginBottom: 10, + padding: 8, + }, + cancelBtn: { + margin: 'auto', + width: 150, + background: '#232323', + marginBottom: 20, + padding: 8, + }, + icons: { + marginRight: 5, + }, +})); + +export default useStyles; diff --git a/phone/src/apps/contacts/components/styles.contacts.ts b/phone/src/apps/contacts/components/styles.contacts.ts new file mode 100644 index 0000000..a7ada28 --- /dev/null +++ b/phone/src/apps/contacts/components/styles.contacts.ts @@ -0,0 +1,35 @@ +import { makeStyles, Theme } from '@material-ui/core/styles'; + +const useStyles = makeStyles((theme: Theme) => ({ + backgroundModal: { + background: 'black', + opacity: '0.6', + position: 'absolute', + top: 0, + left: 0, + right: 0, + bottom: 0, + zIndex: 5, + }, + absolute: { + position: 'sticky', + bottom: theme.spacing(2), + left: theme.spacing(3), + }, + // title + root: { + height: '60px', + width: '100%', + display: 'flex', + flexFlow: 'row nowrap', + justifyContent: 'center', + alignItems: 'center', + background: '#424242', + }, + icon: { + color: '#fff', + fontSize: 30, + }, +})); + +export default useStyles; diff --git a/phone/src/apps/contacts/hooks/state.ts b/phone/src/apps/contacts/hooks/state.ts index 0c5321b..e8ed8f8 100644 --- a/phone/src/apps/contacts/hooks/state.ts +++ b/phone/src/apps/contacts/hooks/state.ts @@ -1,24 +1,28 @@ -import { atom } from "recoil"; +import { atom } from 'recoil'; export const contactsState = { contacts: atom({ - key: "contactsList", + key: 'contactsList', default: [], }), showModal: atom({ - key: "showModal", + key: 'showModal', default: false, }), filterContacts: atom({ key: 'filterContacts', - default: "" + default: '', }), showContactsModal: atom({ key: 'showContactModal', - default: false + default: false, }), contactDetail: atom({ key: 'contactDetail', - default: null - }) + default: null, + }), + contactAlert: atom({ + key: 'contactAlert', + default: null, + }), }; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index e68f834..7f782aa 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -61,6 +61,13 @@ "APPS_MESSAGES_INVALID_PHONE_NUMBER": "Invalid phone number: ", "APPS_MESSAGES_MESSAGE_GROUP_DUPLICATE": "This message group already exists", "APPS_MESSAGES_MESSAGE_GROUP_CREATE_FAILED": "Failed to create message group", - "APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE": "You cannot add yourself!" + "APPS_MESSAGES_MESSAGE_GROUP_CREATE_MINE": "You cannot add yourself!", + + "APPS_CONTACTS_ADD_SUCCESS": "Successfully created contact!", + "APPS_CONTACTS_ADD_FAILED": "Failed to created contact!", + "APPS_CONTACTS_UPDATE_SUCCESS": "Successfully updated contact!", + "APPS_CONTACTS_UPDATE_FAILED": "Failed to update contact!", + "APPS_CONTACTS_DELETE_SUCCESS": "Successfully deleted contact!", + "APPS_CONTACTS_DELETE_FAILED": "Failed to delete contact!" } } diff --git a/resources/package.json b/resources/package.json index bd24e17..4873b0e 100644 --- a/resources/package.json +++ b/resources/package.json @@ -19,6 +19,7 @@ "@types/node": "^14.11.10", "axios": "^0.21.0", "connection-string-parser": "^1.0.3", + "esx.js": "^1.1.5", "fivem-esx-js": "^0.1.12", "fivem-js": "^1.3.1", "md5": "^2.3.0",