-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathSendStatus.tsx
More file actions
58 lines (47 loc) · 1.91 KB
/
SendStatus.tsx
File metadata and controls
58 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { validateProps } from '@msinternal/botframework-webchat-react-valibot';
import { hooks } from 'botframework-webchat-api';
import { useStyles } from '@msinternal/botframework-webchat-styles/react';
import React, { memo, useCallback } from 'react';
import { any, literal, object, pipe, readonly, union, type InferInput } from 'valibot';
import useFocus from '../../hooks/useFocus';
import { SENDING, SEND_FAILED, SENT } from '../../types/internal/SendStatus';
import SendFailedRetry from './private/SendFailedRetry';
import styles from '../ActivityStatus.module.css';
const { useLocalizer, usePostActivity } = hooks;
const sendStatusPropsSchema = pipe(
object({
activity: any(),
sendStatus: union([literal(SENDING), literal(SEND_FAILED), literal(SENT)])
}),
readonly()
);
type SendStatusProps = InferInput<typeof sendStatusPropsSchema>;
function SendStatus(props: SendStatusProps) {
const { activity, sendStatus } = validateProps(sendStatusPropsSchema, props);
const focus = useFocus();
const localize = useLocalizer();
const postActivity = usePostActivity();
const classNames = useStyles(styles);
const handleRetryClick = useCallback(() => {
postActivity(activity);
// After clicking on "retry", the button will be gone and focus will be lost (back to document.body)
// We want to make sure the user stay inside Web Chat
focus('sendBoxWithoutKeyboard');
}, [activity, focus, postActivity]);
const sendingText = localize('ACTIVITY_STATUS_SEND_STATUS_ALT_SENDING');
return (
<React.Fragment>
<span className={classNames['activity-status']}>
{sendStatus === SENDING ? (
sendingText
) : sendStatus === SEND_FAILED ? (
<SendFailedRetry onRetryClick={handleRetryClick} />
) : (
false
)}
</span>
</React.Fragment>
);
}
export default memo(SendStatus);
export { sendStatusPropsSchema, type SendStatusProps };