mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
handle all configuration cases
This commit is contained in:
1 parent
8000cc3d3f
commit
97f5c99cc0
12 files changed
+289
-157
No files matched your search
@@ -5,7 +5,12 @@ import { useTranslation } from 'react-i18next';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import ProfileField from './ProfileField';
|
||||
import DefaultProfilePrompt from './DefaultProfilePrompt';
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { twitterState } from '../../hooks/state';
|
||||
import { useSettings } from '../../../settings/hooks/useSettings';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -23,23 +28,43 @@ export function ProfilePrompt() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profile } = useProfile();
|
||||
const defaultProfileNames = useRecoilValue(twitterState.defaultProfileNames);
|
||||
const [profileName, setProfileName] = useState(profile?.profile_name || '');
|
||||
const { config } = usePhone();
|
||||
|
||||
const [name, handleNameChange] = useState(profile.profile_name || '');
|
||||
const showDefaultProfileNames = !config.twitter.allowEdtiableProfileName && !profile;
|
||||
const eventName = showDefaultProfileNames
|
||||
? 'phone:createTwitterProfile'
|
||||
: 'phone:updateTwitterProfile';
|
||||
|
||||
const handleUpdate = () => {
|
||||
const data = {
|
||||
Nui.send(eventName, {
|
||||
...profile,
|
||||
profile_name: name,
|
||||
};
|
||||
Nui.send('phone:updateTwitterProfile', data);
|
||||
profile_name: profileName,
|
||||
});
|
||||
};
|
||||
|
||||
// case where profile doesn't exist, couldn't be created automatically
|
||||
// and the player is not allowed to edit their own profile name
|
||||
if (showDefaultProfileNames) {
|
||||
return (
|
||||
<DefaultProfilePrompt
|
||||
profileName={profileName}
|
||||
defaultProfileNames={defaultProfileNames}
|
||||
setProfileName={setProfileName}
|
||||
handleUpdate={handleUpdate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// case where profile doesn't exist, couldn't be created automatically
|
||||
// but the player IS allowed to edit their own profile name
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<ProfileField
|
||||
label={t('APPS_TWITTER_EDIT_PROFILE_NAME')}
|
||||
value={name}
|
||||
handleChange={handleNameChange}
|
||||
value={profileName}
|
||||
handleChange={setProfileName}
|
||||
allowChange
|
||||
/>
|
||||
<ProfileUpdateButton handleClick={handleUpdate} />
|
||||
|
||||
Reference in new issue
Block a user