-
Notifications
You must be signed in to change notification settings - Fork 26
feat(UserNicknamesPanel): add ability to set IRC display nickname #449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 1 commit
57091d6
82a1a37
1d5a845
d6d113d
01f2d22
7bb727c
64c2433
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { HttpStatus } from '@fuelrats/web-util/http' | ||
| import PropTypes from 'prop-types' | ||
|
|
||
| import ApiErrorBox from '~/components/MessageBox/ApiErrorBox' | ||
|
|
||
|
|
||
| function getErrorText (error) { | ||
| switch (error.code) { | ||
| case HttpStatus.CONFLICT: | ||
| return 'Nickname already registered.' | ||
|
|
||
| case HttpStatus.NOT_FOUND: | ||
| return 'Nickname not found or no longer exists.' | ||
|
|
||
| case HttpStatus.UNPROCESSABLE_ENTITY: | ||
| return 'Nickname format is invalid.' | ||
|
|
||
| default: | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| function NicknameErrorBox (props) { | ||
| const { error } = props | ||
|
|
||
| if (!error) { | ||
| return null | ||
| } | ||
|
|
||
| return (<ApiErrorBox error={error} renderError={getErrorText} />) | ||
| } | ||
|
|
||
| NicknameErrorBox.propTypes = { | ||
| error: PropTypes.object, | ||
| } | ||
|
|
||
|
|
||
| export default NicknameErrorBox |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,18 @@ | ||
| import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' | ||
| import { HttpStatus } from '@fuelrats/web-util/http' | ||
| import { isError } from 'flux-standard-action' | ||
| import { useCallback, useState } from 'react' | ||
| import { useDispatch, useSelector } from 'react-redux' | ||
|
|
||
| import ConfirmActionButton from '~/components/ConfirmActionButton' | ||
| import AddNicknameForm from '~/components/Forms/AddNicknameForm/AddNicknameForm' | ||
| import MessageBox from '~/components/MessageBox' | ||
| import { deleteNickname, setDisplayNickname, getUserProfile } from '~/store/actions/user' | ||
| import { | ||
| selectUserById, | ||
| withCurrentUserId, | ||
| selectNicknamesByUserId, | ||
| } from '~/store/selectors' | ||
| import getResponseError from '~/util/getResponseError' | ||
|
|
||
| import NicknameErrorBox from './NicknameErrorBox' | ||
| import styles from './UserNicknamesPanel.module.scss' | ||
|
|
||
|
|
||
|
|
@@ -34,40 +33,37 @@ function UserNicknamesPanel () { | |
| const user = useSelector(withCurrentUserId(selectUserById)) | ||
|
|
||
| const handleDeleteNickname = useCallback(async (event) => { | ||
| setError(null) | ||
| const response = await dispatch(deleteNickname(user, nicknames.find((nick) => { | ||
| return nick.id === event.target.name | ||
| }))) | ||
|
|
||
| if (isError(response)) { | ||
| const { meta, payload } = response | ||
| let errorMessage = 'Unknown error occurred.' | ||
|
|
||
| if (HttpStatus.isClientError(meta.response.status)) { | ||
| errorMessage = payload.errors?.length ? payload.errors[0].detail : 'Client communication error' | ||
| } | ||
|
|
||
| if (HttpStatus.isServerError(meta.response.status)) { | ||
| errorMessage = 'Server communication error' | ||
| } | ||
|
|
||
| setError(errorMessage) | ||
| return errorMessage | ||
| const responseError = getResponseError(response) | ||
| if (responseError) { | ||
| setError(responseError) | ||
| return responseError | ||
| } | ||
|
|
||
| return undefined | ||
| return true | ||
| }, [dispatch, nicknames, user]) | ||
|
|
||
| const handleSetDisplayNickname = useCallback(async (event) => { | ||
| setError(null) | ||
| const nickname = nicknames.find((nick) => { | ||
| return nick.id === event.target.name | ||
| }) | ||
|
|
||
| const response = await dispatch(setDisplayNickname(nickname.id, nickname.attributes.nick)) | ||
|
|
||
| if (!isError(response)) { | ||
| // Refresh user profile to get updated nicknames | ||
| await dispatch(getUserProfile()) | ||
| const responseError = getResponseError(response) | ||
| if (responseError) { | ||
| setError(responseError) | ||
| return responseError | ||
| } | ||
|
|
||
| // Refresh user profile to get updated nicknames | ||
| await dispatch(getUserProfile()) | ||
| return true | ||
| }, [dispatch, nicknames]) | ||
|
|
||
| const nickCount = nicknames?.length | ||
|
|
@@ -85,7 +81,7 @@ function UserNicknamesPanel () { | |
| <div className={styles.userNicknames}> | ||
| { | ||
| error && ( | ||
| <MessageBox>{error}</MessageBox> | ||
| <NicknameErrorBox error={error} /> | ||
| ) | ||
| } | ||
| <ul className={styles.nickList}> | ||
|
|
@@ -125,7 +121,7 @@ function UserNicknamesPanel () { | |
| title="Set as display nickname" | ||
| onConfirm={handleSetDisplayNickname} | ||
| onConfirmText=""> | ||
| <FontAwesomeIcon fixedWidth icon={['far', 'star']} /> | ||
| <FontAwesomeIcon fixedWidth icon="farStar" title="Set as display nickname" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the previous We only need to rename the export in |
||
| </ConfirmActionButton> | ||
| <ConfirmActionButton | ||
| className="icon" | ||
|
|
@@ -136,7 +132,7 @@ function UserNicknamesPanel () { | |
| title="Delete nickname" | ||
| onConfirm={handleDeleteNickname} | ||
| onConfirmText=""> | ||
| <FontAwesomeIcon fixedWidth icon="trash" /> | ||
| <FontAwesomeIcon fixedWidth icon="trash" title="Delete nickname" /> | ||
| </ConfirmActionButton> | ||
| </> | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.