2022-05-26 23:52:04 +03:00
|
|
|
import { useState } from 'react';
|
2022-05-14 01:07:49 +03:00
|
|
|
import { useRecoilValue } from 'recoil';
|
2022-05-26 23:52:04 +03:00
|
|
|
import { Input, Button } from 'antd';
|
|
|
|
import { MessageType } from '../../interfaces/socket-events';
|
2022-05-14 01:07:49 +03:00
|
|
|
import WebsocketService from '../../services/websocket-service';
|
2022-05-26 23:52:04 +03:00
|
|
|
import { websocketServiceAtom, chatDisplayNameAtom } from '../stores/ClientConfigStore';
|
2022-05-14 01:07:49 +03:00
|
|
|
|
|
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
|
|
interface Props {}
|
|
|
|
|
|
|
|
export default function NameChangeModal(props: Props) {
|
|
|
|
const websocketService = useRecoilValue<WebsocketService>(websocketServiceAtom);
|
2022-05-26 23:52:04 +03:00
|
|
|
const chatDisplayName = useRecoilValue<string>(chatDisplayNameAtom);
|
|
|
|
const [newName, setNewName] = useState<any>(chatDisplayName);
|
2022-05-14 01:07:49 +03:00
|
|
|
|
2022-05-26 23:52:04 +03:00
|
|
|
const handleNameChange = () => {
|
|
|
|
const nameChange = {
|
|
|
|
type: MessageType.NAME_CHANGE,
|
|
|
|
newName,
|
|
|
|
};
|
|
|
|
websocketService.send(nameChange);
|
|
|
|
};
|
2022-05-14 01:07:49 +03:00
|
|
|
|
2022-05-26 23:52:04 +03:00
|
|
|
const saveEnabled =
|
|
|
|
newName !== chatDisplayName && newName !== '' && websocketService?.isConnected();
|
2022-05-14 01:07:49 +03:00
|
|
|
|
2022-05-26 23:52:04 +03:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
Your chat display name is what people see when you send chat messages. Other information can
|
|
|
|
go here to mention auth, and stuff.
|
|
|
|
<Input
|
|
|
|
value={newName}
|
|
|
|
onChange={e => setNewName(e.target.value)}
|
|
|
|
placeholder="Your chat display name"
|
|
|
|
maxLength={10}
|
|
|
|
showCount
|
|
|
|
defaultValue={chatDisplayName}
|
|
|
|
/>
|
|
|
|
<Button disabled={!saveEnabled} onClick={handleNameChange}>
|
|
|
|
Change name
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
);
|
2022-05-14 01:07:49 +03:00
|
|
|
}
|