-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent auto-connecting as anonymous (#514)
- Loading branch information
1 parent
ba94d9b
commit b31394a
Showing
30 changed files
with
220 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import UserContext from 'auth/Context'; | ||
import useUser from 'auth/useUser'; | ||
import EditableLabel from 'components/EditableLabel'; | ||
import { useSnackbar } from 'notistack'; | ||
import { useCallback, useContext } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { updateUserName } from 'views/account/api'; | ||
|
||
export function NameEditor() { | ||
const { enqueueSnackbar } = useSnackbar(); | ||
const { t } = useTranslation(); | ||
const user = useUser(); | ||
const { setUser } = useContext(UserContext); | ||
const handleEditName = useCallback( | ||
async (name: string) => { | ||
const trimmed = name.trim(); | ||
if (!trimmed.length) { | ||
enqueueSnackbar(t('AccountPage.noEmptyNameError'), { | ||
variant: 'warning', | ||
}); | ||
} else { | ||
const updatedUser = await updateUserName(name); | ||
setUser(updatedUser); | ||
} | ||
}, | ||
[setUser, enqueueSnackbar, t] | ||
); | ||
|
||
if (!user) { | ||
return <>Stranger</>; | ||
} | ||
|
||
return <EditableLabel value={user.name} onChange={handleEditName} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.