diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index 5d5600f..0865345 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -135,7 +135,7 @@ setTimeout(() => {
id: 1,
number: "345-4366",
display: "chip",
- avatar: 'https://i.imgur.com/Qpw6j8D.png'
+ avatar: 'https://upload.wikimedia.org/wikipedia/commons/thumb/2/2c/Rotating_earth_%28large%29.gif/200px-Rotating_earth_%28large%29.gif'
},
{
id: 2,
diff --git a/phone/src/apps/contacts/components/ContactsApp.tsx b/phone/src/apps/contacts/components/ContactsApp.tsx
index fa47d34..7ef050c 100644
--- a/phone/src/apps/contacts/components/ContactsApp.tsx
+++ b/phone/src/apps/contacts/components/ContactsApp.tsx
@@ -8,9 +8,11 @@ import { useApp } from "../../../os/apps/hooks/useApps";
import { AddContactModal } from "./ContactModal";
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 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";
const useStyles = makeStyles((theme: Theme) =>
createStyles({
@@ -36,7 +38,7 @@ export const ContactsApp = () => {
const classes = useStyles();
const { showModal, setShowModal } = useModal();
const contacts = useApp("CONTACTS");
- const { showContactModal } = useContactModal();
+ const { contactDetail } = useContactDetail();
const openModal = () => {
setShowModal(true);
@@ -47,6 +49,7 @@ export const ContactsApp = () => {
+
diff --git a/phone/src/apps/contacts/components/List/ContactList.tsx b/phone/src/apps/contacts/components/List/ContactList.tsx
index 699111c..2edfdcf 100644
--- a/phone/src/apps/contacts/components/List/ContactList.tsx
+++ b/phone/src/apps/contacts/components/List/ContactList.tsx
@@ -1,14 +1,14 @@
import React from "react";
import ListItemText from "@material-ui/core/ListItemText";
-import {
- Button,
+import {
+ Button,
ListItemAvatar,
Avatar as MuiAvatar,
List,
ListItem,
TextField,
Collapse,
- makeStyles
+ makeStyles,
} from "@material-ui/core";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
@@ -18,39 +18,43 @@ 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 { useContactModal } from "../../hooks/useContactModal";
+import { useContactDetail } from "../../hooks/useContactDetail";
import Nui from "../../../../os/nui-events/utils/Nui";
-import "../Contact.css"
+import "../Contact.css";
const useStyles = makeStyles((theme) => ({
updateButton: {
- margin: 'auto',
+ margin: "auto",
fontSize: 14,
width: 150,
background: "#2196f3",
marginBottom: 10,
- padding: 8
+ padding: 8,
},
collapseItem: {
- margin: 'auto',
- width: '50%'
- }
-}))
-
+ margin: "auto",
+ width: "50%",
+ },
+}));
export const ContactList = () => {
- const classes = useStyles()
+ const classes = useStyles();
const { filteredContacts } = useFilteredContacts();
- const { showContactModal, setShowContactModal } = useContactModal();
+ const { setShowContactModal } = useContactModal();
+ const { contactDetail, setContactDetail } = useContactDetail();
const contacts = useContacts();
- const openContactInfo = () => {
- setShowContactModal(!showContactModal);
- }
+ const openContactInfo = (contact) => {
+ setShowContactModal(true);
+ setContactDetail(contact);
+ console.log("CONTACT", contactDetail);
+ };
const startCall = (number) => {
console.log(number);
Nui.send("phone:startCall", {
@@ -60,52 +64,47 @@ export const ContactList = () => {
return (
- {contacts.contacts.filter(contact => contact.display.includes(filteredContacts) || contact.number.includes(filteredContacts)).map((contact) => (
- <>
-
-
- {contact.avatar ? (
-
- ): (
- {contact.display.slice(0, 1).toUpperCase()}
- )}
-
-
-
-
-
-
-
-
-
-
+ contact.display.includes(filteredContacts) ||
+ contact.number.includes(filteredContacts)
+ )
+ .map((contact) => (
+ <>
+
+
+ {contact.avatar ? (
+
+ ) : (
+
+ {contact.display.slice(0, 1).toUpperCase()}
+
+ )}
+
+
-
-
-
-
-
-
-
-
- >
- ))}
+ >
+ ))}
);
};
diff --git a/phone/src/apps/contacts/components/modal/InfoModal.tsx b/phone/src/apps/contacts/components/modal/InfoModal.tsx
new file mode 100644
index 0000000..07456b3
--- /dev/null
+++ b/phone/src/apps/contacts/components/modal/InfoModal.tsx
@@ -0,0 +1,111 @@
+import React, { useState } from "react";
+import {
+ Paper,
+ Slide,
+ Button,
+ TextField,
+ Avatar as MuiAvatar,
+} from "@material-ui/core";
+import useStyles from "./modal.styles";
+import { useContactModal } from "../../hooks/useContactModal";
+import ArrowBackIcon from "@material-ui/icons/ArrowBack";
+
+import { useTranslation } from "react-i18next";
+import { useContactDetail } from "../../hooks/useContactDetail";
+import Nui from "../../../../os/nui-events/utils/Nui";
+
+export const InfoModal = () => {
+ const classes = useStyles();
+ const { showContactModal, setShowContactModal } = useContactModal();
+ const { t } = useTranslation();
+ const { contactDetail, setContactDetail } = useContactDetail();
+
+ const [display, setDisplay] = useState(
+ contactDetail ? contactDetail.display : ""
+ );
+ console.log(contactDetail);
+ const [number, setNumber] = useState(
+ contactDetail ? contactDetail.number : ""
+ );
+ const [avatar, setAvatar] = useState(
+ contactDetail ? contactDetail.avatar : ""
+ );
+
+ const closeModal = () => {
+ setShowContactModal(false);
+ setContactDetail(null);
+ };
+
+ const updateContact = () => {
+ Nui.send("phone:updateContact", {
+ id: contactDetail.id,
+ display,
+ number,
+ avatar,
+ });
+ setContactDetail(null);
+ setShowContactModal(false);
+ };
+
+ const deleteContact = () => {
+ Nui.send("phone:deleteContact", {
+ id: contactDetail.id,
+ });
+ setContactDetail(null);
+ setShowContactModal(false);
+ };
+
+ return (
+
+
+
+
+
+
+
+
setDisplay(e.target.value)}
+ placeholder={t("APPS_CONTACT_FORM_NAME")}
+ fullWidth
+ inputProps={{
+ className: classes.inputProps,
+ }}
+ />
+ setNumber(e.target.value)}
+ placeholder={t("APPS_CONTACT_FORM_NUMBER")}
+ fullWidth
+ inputProps={{
+ className: classes.inputProps,
+ }}
+ />
+ setAvatar(e.target.value)}
+ inputProps={{
+ className: classes.inputProps,
+ }}
+ />
+
+
+
+ Update
+
+
+ Delete
+
+
+
+
+
+ );
+};
diff --git a/phone/src/apps/contacts/components/modal/modal.styles.ts b/phone/src/apps/contacts/components/modal/modal.styles.ts
new file mode 100644
index 0000000..7f0af19
--- /dev/null
+++ b/phone/src/apps/contacts/components/modal/modal.styles.ts
@@ -0,0 +1,49 @@
+import { makeStyles } from '@material-ui/core';
+
+const useStyles = makeStyles((theme) => ({
+ modalRoot: {
+ zIndex: 10,
+ position: 'absolute',
+ height: '100%',
+ width: '100%'
+ },
+ modalHide: {
+ display: 'none'
+ },
+ 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
+ },
+ updateButton: {
+ background: '#2196f3',
+ width: 150,
+ height: 45,
+ fontSize: 16,
+ marginTop: 29,
+ marginBottom: 29
+ },
+ deleteButton: {
+ background: '#d32f2f',
+ width: 150,
+ height: 40,
+ fontSize: 16
+ }
+}))
+
+export default useStyles;
\ No newline at end of file
diff --git a/phone/src/apps/contacts/hooks/state.ts b/phone/src/apps/contacts/hooks/state.ts
index 8d725c3..0c5321b 100644
--- a/phone/src/apps/contacts/hooks/state.ts
+++ b/phone/src/apps/contacts/hooks/state.ts
@@ -16,5 +16,9 @@ export const contactsState = {
showContactsModal: atom({
key: 'showContactModal',
default: false
+ }),
+ contactDetail: atom({
+ key: 'contactDetail',
+ default: null
})
};
diff --git a/phone/src/apps/contacts/hooks/useContactDetail.ts b/phone/src/apps/contacts/hooks/useContactDetail.ts
new file mode 100644
index 0000000..9c064e9
--- /dev/null
+++ b/phone/src/apps/contacts/hooks/useContactDetail.ts
@@ -0,0 +1,7 @@
+import { useRecoilState } from 'recoil';
+import { contactsState } from './state';
+
+export const useContactDetail = (): any => {
+ const [ contactDetail, setContactDetail ] = useRecoilState(contactsState.contactDetail);
+ return { contactDetail, setContactDetail };
+}
\ No newline at end of file
diff --git a/phone/src/apps/dialer/hooks/useDialerHistory.ts b/phone/src/apps/dialer/hooks/useDialerHistory.ts
index cfc6d31..6a8e19a 100644
--- a/phone/src/apps/dialer/hooks/useDialerHistory.ts
+++ b/phone/src/apps/dialer/hooks/useDialerHistory.ts
@@ -3,12 +3,6 @@ import { useRecoilState, atom } from "recoil";
const dialerHistoryState = atom({
key: "dialerHistory",
default: [
- {
- id: 0,
- caller: "Kidz",
- phoneNumber: "000-1111",
- type: "incoming",
- },
{
id: 1,
caller: "ROCKY",
diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json
index 6b5bee5..4094108 100644
--- a/phone/src/locale/en.json
+++ b/phone/src/locale/en.json
@@ -44,6 +44,11 @@
"APPS_BANK_ACCOUNT_TITLE": "Account Summary",
"APPS_BANK_ACCOUNT_TRANSACTIONS": "Transactions",
"APPS_BANK_ACCOUNT_SEE_TRANSACTION": "See all",
- "APPS_BANK_ACTIONS_TRANSFER": "Transfer"
+ "APPS_BANK_ACTIONS_TRANSFER": "Transfer",
+
+ "APPS_CONTACT_FORM_NAME": "Name",
+ "APPS_CONTACT_FORM_NUMBER": "Number",
+ "APPS_CONTACT_FORM_AVATAR": "Avatar URL"
+
}
}
diff --git a/resources/client/cl_contacts.ts b/resources/client/cl_contacts.ts
index a052a41..0f12dc8 100644
--- a/resources/client/cl_contacts.ts
+++ b/resources/client/cl_contacts.ts
@@ -17,8 +17,29 @@ on(`__cfx_nui:${events.CONTACTS_ADD_CONTACT}`, (data: any) => {
const avatar = data.avatar;
emitNet(events.CONTACTS_ADD_CONTACT, number, display, avatar);
- setTimeout(() => {
- emitNet(events.CONTACTS_GET_CONTACTS)
- }, 500)
});
+onNet(events.CONTACTS_ADD_CONTACT_SUCCESS, () => {
+ emitNet(events.CONTACTS_GET_CONTACTS)
+})
+
+
+RegisterNuiCallbackType(events.CONTACTS_UPDATE_CONTACT);
+on(`__cfx_nui:${events.CONTACTS_UPDATE_CONTACT}`, (data: any) => {
+ const contact = data;
+ emitNet(events.CONTACTS_UPDATE_CONTACT, contact)
+})
+
+onNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, () => {
+ emitNet(events.CONTACTS_GET_CONTACTS)
+})
+
+RegisterNuiCallbackType(events.CONTACTS_DELETE_CONTACT);
+on(`__cfx_nui:${events.CONTACTS_DELETE_CONTACT}`, (data: any) => {
+ const contact = data;
+ emitNet(events.CONTACTS_DELETE_CONTACT, contact)
+})
+
+onNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, () => {
+ emitNet(events.CONTACTS_GET_CONTACTS)
+})
\ No newline at end of file
diff --git a/resources/server/sv_contacts.ts b/resources/server/sv_contacts.ts
index f0fcfba..47b6e0c 100644
--- a/resources/server/sv_contacts.ts
+++ b/resources/server/sv_contacts.ts
@@ -1,12 +1,20 @@
-import { ESX } from "./server";
+import { ESX, getSource } from "./server";
import { pool } from "./db";
import events from "../utils/events";
+import { useIdentifier } from './functions'
interface Contacts {
+ id?: number;
display: string;
number: string;
+ avatar: string;
}
+interface ContactId {
+ id: number;
+}
+
+
async function fetchAllContacts(identifier: string): Promise {
const query = "SELECT * FROM npwd_phone_contacts WHERE identifier = ?";
const [results] = await pool.query(query, [identifier]);
@@ -26,6 +34,25 @@ async function addContact(
await pool.query(query, [identifier, number, display, avatar]);
}
+async function updateContact(contact: Contacts, identifier: string): Promise {
+ const query = "UPDATE npwd_phone_contacts SET number = ?, display = ?, avatar = ? WHERE id = ? AND identifier = ?"
+ await pool.query(query, [
+ contact.number,
+ contact.display,
+ contact.avatar,
+ contact.id,
+ identifier
+ ])
+}
+
+async function deleteContact(contact: ContactId, identifier: string): Promise {
+ const query = "DELETE FROM npwd_phone_contacts WHERE id = ? AND identifier = ?"
+ await pool.query(query, [
+ contact.id,
+ identifier
+ ])
+}
+
onNet(events.CONTACTS_GET_CONTACTS, async () => {
try {
const _source = (global as any).source;
@@ -39,16 +66,36 @@ onNet(events.CONTACTS_GET_CONTACTS, async () => {
}
})
-onNet(events.CONTACTS_ADD_CONTACT, (number: string, display: string, avatar: string) => {
+onNet(events.CONTACTS_ADD_CONTACT, async (number: string, display: string, avatar: string) => {
try {
const _source = (global as any).source;
- const xPlayer = ESX.GetPlayerFromId(_source);
- const _identifier = xPlayer.getIdentifier()
+ const _identifier = await useIdentifier()
addContact(_identifier, number, display, avatar);
- //emit(events.CONTACTS_GET_CONTACTS);
+ emitNet(events.CONTACTS_ADD_CONTACT_SUCCESS, _source)
} catch(error) {
console.log("Failed to add contact: ", error);
}
});
+onNet(events.CONTACTS_UPDATE_CONTACT, async (contact: Contacts) => {
+ try {
+ const _source = (global as any)._source
+ const _identifier = await useIdentifier()
+ updateContact(contact, _identifier)
+ emitNet(events.CONTACTS_UPDATE_CONTACT_SUCCESS, _source)
+
+ } catch (error) {
+ console.log(error)
+ }
+})
+
+onNet(events.CONTACTS_DELETE_CONTACT, async (contact: ContactId) => {
+ try {
+ const _identifier = await useIdentifier()
+ deleteContact(contact, _identifier)
+ emitNet(events.CONTACTS_DELETE_CONTACT_SUCCESS, getSource())
+ } catch (error) {
+ console.log("DELETE CONTACT ERROR", error)
+ }
+})
diff --git a/resources/utils/events.ts b/resources/utils/events.ts
index 7623d9c..0dc62a1 100644
--- a/resources/utils/events.ts
+++ b/resources/utils/events.ts
@@ -32,7 +32,11 @@ export default {
CONTACTS_GET_CONTACTS: 'phone:getContacts',
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
CONTACTS_ADD_CONTACT: 'contacts:add',
- CONTACTS_UPDATE_CONTACTS: 'phone:updateContacts',
+ CONTACTS_ADD_CONTACT_SUCCESS: 'contacts:addSuccess',
+ CONTACTS_UPDATE_CONTACT: 'phone:updateContact',
+ CONTACTS_DELETE_CONTACT: 'phone:deleteContact',
+ CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess',
+ CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess',
// Sellout
SELLOUT_ADD_LISTING: 'phone:addListing',