Skip to content

Commit

Permalink
refactor: convert masquerade UI widgets to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Nov 6, 2024
1 parent 6534347 commit c6c60e0
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 349 deletions.

This file was deleted.

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 src/instructor-toolbar/masquerade-widget/MasqueradeWidget.jsx

This file was deleted.

Loading

0 comments on commit c6c60e0

Please sign in to comment.