Browse Source

feat: close modal after name change (#3084)

* feat: close modal after name change

* refactor: shortened modal name

* fix: added a no-op for NameChangeModal storybook
pull/3095/head
Mohib Khan 3 years ago committed by GitHub
parent
commit
6fa576a04a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      web/components/common/UserDropdown/UserDropdown.tsx
  2. 2
      web/components/modals/NameChangeModal/NameChangeModal.stories.tsx
  3. 7
      web/components/modals/NameChangeModal/NameChangeModal.tsx

8
web/components/common/UserDropdown/UserDropdown.tsx

@ -86,6 +86,10 @@ export const UserDropdown: FC<UserDropdownProps> = ({ @@ -86,6 +86,10 @@ export const UserDropdown: FC<UserDropdownProps> = ({
setShowNameChangeModal(true);
};
const closeChangeNameModal = () => {
setShowNameChangeModal(false);
};
// Register keyboard shortcut for the space bar to toggle playback
useHotkeys(
'c',
@ -153,9 +157,9 @@ export const UserDropdown: FC<UserDropdownProps> = ({ @@ -153,9 +157,9 @@ export const UserDropdown: FC<UserDropdownProps> = ({
<Modal
title="Change Chat Display Name"
open={showNameChangeModal}
handleCancel={() => setShowNameChangeModal(false)}
handleCancel={closeChangeNameModal}
>
<NameChangeModal />
<NameChangeModal closeModal={closeChangeNameModal} />
</Modal>
<Modal
title="Authenticate"

2
web/components/modals/NameChangeModal/NameChangeModal.stories.tsx

@ -27,7 +27,7 @@ const Example = () => { @@ -27,7 +27,7 @@ const Example = () => {
return (
<div>
<NameChangeModal />
<NameChangeModal closeModal={() => {}} />
</div>
);
};

7
web/components/modals/NameChangeModal/NameChangeModal.tsx

@ -22,7 +22,11 @@ const UserColor: FC<UserColorProps> = ({ color }) => { @@ -22,7 +22,11 @@ const UserColor: FC<UserColorProps> = ({ color }) => {
return <div style={style} />;
};
export const NameChangeModal: FC = () => {
type NameChangeModalProps = {
closeModal: () => void;
};
export const NameChangeModal: FC<NameChangeModalProps> = ({ closeModal }) => {
const currentUser = useRecoilValue(currentUserAtom);
const websocketService = useRecoilValue<WebsocketService>(websocketServiceAtom);
const [newName, setNewName] = useState<string>(currentUser?.displayName);
@ -44,6 +48,7 @@ export const NameChangeModal: FC = () => { @@ -44,6 +48,7 @@ export const NameChangeModal: FC = () => {
newName,
};
websocketService.send(nameChange);
closeModal();
};
const handleColorChange = (color: string) => {

Loading…
Cancel
Save