mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
fix(phone/contacts): provide user feedback on max length data
This commit is contained in:
1 parent
02f0abd761
commit
dd99f7e241
4 files changed
+35
-9
No files matched your search
@@ -7,7 +7,7 @@ import { useContactActions } from '../../hooks/useContactActions';
|
|||||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||||
import { Contact, ContactEvents } from '../../../../../../typings/contact';
|
import { Contact, ContactEvents, ContactsDatabaseLimits } from '../../../../../../typings/contact';
|
||||||
import { TextField } from '../../../../ui/components/Input';
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
import { fetchNui } from '../../../../utils/fetchNui';
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
import { ServerPromiseResp } from '../../../../../../typings/common';
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
@@ -72,6 +72,24 @@ const ContactsInfoPage = () => {
|
|||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleNumberChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.number) return;
|
||||||
|
setNumber(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDisplayChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.display) return;
|
||||||
|
setName(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAvatarChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.avatar) return;
|
||||||
|
setAvatar(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (addNumber) {
|
if (addNumber) {
|
||||||
setNumber(addNumber);
|
setNumber(addNumber);
|
||||||
@@ -173,9 +191,10 @@ const ContactsInfoPage = () => {
|
|||||||
<MuiAvatar className={classes.avatar} src={avatar} />
|
<MuiAvatar className={classes.avatar} src={avatar} />
|
||||||
<TextField
|
<TextField
|
||||||
autoFocus
|
autoFocus
|
||||||
|
error={name.length === ContactsDatabaseLimits.display}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => setName(e.target.value)}
|
onChange={handleDisplayChange}
|
||||||
label={t('APPS_CONTACT_FORM_NAME')}
|
label={t('APPS_CONTACT_FORM_NAME')}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -184,8 +203,8 @@ const ContactsInfoPage = () => {
|
|||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
value={number}
|
value={number.length === ContactsDatabaseLimits.number}
|
||||||
onChange={(e) => setNumber(e.target.value)}
|
onChange={handleNumberChange}
|
||||||
label={t('APPS_CONTACT_FORM_NUMBER')}
|
label={t('APPS_CONTACT_FORM_NUMBER')}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -193,11 +212,12 @@ const ContactsInfoPage = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
|
error={avatar.length === ContactsDatabaseLimits.avatar}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
label={t('APPS_CONTACT_FORM_AVATAR')}
|
label={t('APPS_CONTACT_FORM_AVATAR')}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={avatar}
|
value={avatar}
|
||||||
onChange={(e) => setAvatar(e.target.value)}
|
onChange={handleAvatarChange}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
className: classes.inputProps,
|
className: classes.inputProps,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import React, { useCallback } from 'react';
|
import React, { useCallback } from 'react';
|
||||||
import MUITextField from '@material-ui/core/TextField';
|
import MUITextField from '@material-ui/core/TextField';
|
||||||
import MUIInputBase from '@material-ui/core/InputBase';
|
import MUIInputBase, { InputBaseProps } from '@material-ui/core/InputBase';
|
||||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import { PhoneEvents } from '../../../../typings/phone';
|
import { PhoneEvents } from '../../../../typings/phone';
|
||||||
|
import { TextFieldProps } from '@material-ui/core/TextField/TextField';
|
||||||
|
|
||||||
const useToggleFocus = () => {
|
const useToggleFocus = () => {
|
||||||
const Nui = useNuiRequest();
|
const Nui = useNuiRequest();
|
||||||
@@ -16,7 +17,7 @@ const useToggleFocus = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const TextField = (props) => {
|
export const TextField: React.FC<TextFieldProps> = (props) => {
|
||||||
const toggleKeys = useToggleFocus();
|
const toggleKeys = useToggleFocus();
|
||||||
return (
|
return (
|
||||||
<MUITextField
|
<MUITextField
|
||||||
@@ -37,7 +38,7 @@ export const TextField = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const InputBase = (props) => {
|
export const InputBase: React.FC<InputBaseProps> = (props) => {
|
||||||
const toggleKeys = useToggleFocus();
|
const toggleKeys = useToggleFocus();
|
||||||
return (
|
return (
|
||||||
<MUIInputBase
|
<MUIInputBase
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ class _ContactService {
|
|||||||
const identifier = PlayerService.getIdentifier(reqObj.source);
|
const identifier = PlayerService.getIdentifier(reqObj.source);
|
||||||
try {
|
try {
|
||||||
await this.contactsDB.updateContact(reqObj.data, identifier);
|
await this.contactsDB.updateContact(reqObj.data, identifier);
|
||||||
|
|
||||||
resp({ status: 'ok' });
|
resp({ status: 'ok' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
contactsLogger.error(`Error in handleUpdateContact (${identifier}), ${e.message}`);
|
contactsLogger.error(`Error in handleUpdateContact (${identifier}), ${e.message}`);
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ export interface ContactDeleteDTO {
|
|||||||
id: number;
|
id: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum ContactsDatabaseLimits {
|
||||||
|
avatar = 512,
|
||||||
|
number = 12,
|
||||||
|
display = 255,
|
||||||
|
}
|
||||||
|
|
||||||
export enum ContactEvents {
|
export enum ContactEvents {
|
||||||
GET_CONTACTS = 'npwd:getContacts',
|
GET_CONTACTS = 'npwd:getContacts',
|
||||||
ADD_CONTACT = 'npwd:addContacts',
|
ADD_CONTACT = 'npwd:addContacts',
|
||||||
|
|||||||
Reference in new issue
Block a user