-
Notifications
You must be signed in to change notification settings - Fork 205
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 TypeScript
- Loading branch information
1 parent
6534347
commit c6c60e0
Showing
10 changed files
with
313 additions
and
349 deletions.
There are no files selected for viewing
64 changes: 0 additions & 64 deletions
64
src/instructor-toolbar/masquerade-widget/MasqueradeUserNameInput.jsx
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
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,52 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
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} | ||
/> | ||
); | ||
}; |
163 changes: 0 additions & 163 deletions
163
src/instructor-toolbar/masquerade-widget/MasqueradeWidget.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.