diff --git a/core/chat/events.go b/core/chat/events.go index fa4d0b45c..892d26421 100644 --- a/core/chat/events.go +++ b/core/chat/events.go @@ -114,6 +114,10 @@ func (s *Server) userColorChanged(eventData chatClientEvent) { if err := user.ChangeUserColor(eventData.client.User.ID, receivedEvent.NewColor); err != nil { log.Errorln("error changing user display color", err) } + + // Resend client's user info with new color, otherwise the name change dialog would still show the old color + eventData.client.User.DisplayColor = receivedEvent.NewColor + eventData.client.sendConnectedClientInfo() } func (s *Server) userMessageSent(eventData chatClientEvent) { diff --git a/web/components/modals/NameChangeModal/NameChangeModal.tsx b/web/components/modals/NameChangeModal/NameChangeModal.tsx index dfb3cc12f..6571614aa 100644 --- a/web/components/modals/NameChangeModal/NameChangeModal.tsx +++ b/web/components/modals/NameChangeModal/NameChangeModal.tsx @@ -1,6 +1,6 @@ import React, { CSSProperties, FC, useState } from 'react'; import { useRecoilValue } from 'recoil'; -import { Input, Button, Select } from 'antd'; +import { Input, Button, Select, Form } from 'antd'; import { MessageType } from '../../../interfaces/socket-events'; import WebsocketService from '../../../services/websocket-service'; import { websocketServiceAtom, currentUserAtom } from '../../stores/ClientConfigStore'; @@ -32,7 +32,12 @@ export const NameChangeModal: FC = () => { const { displayName, displayColor } = currentUser; + const saveEnabled = () => + newName !== displayName && newName !== '' && websocketService?.isConnected(); + const handleNameChange = () => { + if (!saveEnabled()) return; + const nameChange = { type: MessageType.NAME_CHANGE, newName, @@ -40,8 +45,6 @@ export const NameChangeModal: FC = () => { websocketService.send(nameChange); }; - const saveEnabled = newName !== displayName && newName !== '' && websocketService?.isConnected(); - const handleColorChange = (color: string) => { const colorChange = { type: MessageType.COLOR_CHANGE, @@ -53,29 +56,32 @@ export const NameChangeModal: FC = () => { const maxColor = 8; // 0...n const colorOptions = [...Array(maxColor)].map((e, i) => i); + const saveButton = ( + + ); + return (