-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert masquerade UI widgets to Function Components + Type…
…Script (#1513) * refactor: convert masquerade UI widgets to TypeScript * test: improve test coverage * chore: upgrade @testing-library/user-event to v14 * test: improve test coverage * test: improve test coverage
- Loading branch information
1 parent
f5b6243
commit 4a925f9
Showing
22 changed files
with
562 additions
and
519 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
64 changes: 0 additions & 64 deletions
64
src/instructor-toolbar/masquerade-widget/MasqueradeUserNameInput.jsx
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
src/instructor-toolbar/masquerade-widget/MasqueradeUserNameInput.tsx
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,51 @@ | ||
import React from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Input } from '@openedx/paragon'; | ||
|
||
import { MasqueradeStatus, Payload } from './data/api'; | ||
import messages from './messages'; | ||
|
||
interface Props extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onSubmit' | 'onError'> { | ||
onError: (error: string) => void; | ||
onSubmit: (payload: Payload) => Promise<MasqueradeStatus>; | ||
} | ||
|
||
export const MasqueradeUserNameInput: React.FC<Props> = ({ onSubmit, onError, ...otherProps }) => { | ||
const intl = useIntl(); | ||
|
||
const handleSubmit = React.useCallback((userIdentifier: string) => { | ||
const payload: Payload = { | ||
role: 'student', | ||
user_name: userIdentifier, // user name or email | ||
}; | ||
onSubmit(payload).then((data) => { | ||
if (data && data.success) { | ||
global.location.reload(); | ||
} else { | ||
const error = (data && data.error) || ''; | ||
onError(error); | ||
} | ||
}).catch(() => { | ||
const message = intl.formatMessage(messages.genericError); | ||
onError(message); | ||
}); | ||
return true; | ||
}, [onError]); | ||
|
||
const handleKeyPress = React.useCallback((event: React.KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
return handleSubmit(event.currentTarget.value); | ||
} | ||
return true; | ||
}, [handleSubmit]); | ||
|
||
return ( | ||
<Input | ||
aria-labelledby="masquerade-search-label" | ||
label={intl.formatMessage(messages.userNameLabel)} | ||
onKeyPress={handleKeyPress} | ||
type="text" | ||
{...otherProps} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.