forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtranscript.legacyActivityMiddleware.passwordInput.html
More file actions
152 lines (135 loc) · 4.46 KB
/
transcript.legacyActivityMiddleware.passwordInput.html
File metadata and controls
152 lines (135 loc) · 4.46 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<!doctype html>
<html lang="en-US">
<head>
<link href="/assets/activityGrouping.css" rel="stylesheet" type="text/css" />
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone@7.8.7/babel.min.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react@16.8.6/umd/react.development.js"></script>
<script crossorigin="anonymous" src="https://unpkg.com/react-dom@16.8.6/umd/react-dom.development.js"></script>
<script crossorigin="anonymous" src="/test-harness.js"></script>
<script crossorigin="anonymous" src="/test-page-object.js"></script>
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
<style type="text/css">
.password-input {
margin: 10px;
}
.password-input .password-input__form {
background-color: Red;
border-radius: 3px;
color: White;
display: flex;
font-family: Calibri, 'Helvetica Neue', Arial, sans-serif;
padding: 5px;
}
.password-input .password-input__box {
display: flex;
flex: 1;
}
.password-input .password-input__label {
padding: 10px;
}
.password-input .password-input__input {
border: 0px;
border-radius: 3px;
flex: 1;
letter-spacing: 0.5em;
outline: 0;
padding: 0 10px;
width: 100%;
}
.password-input .password-input__input:disabled {
background-color: rgba(255, 255, 255, 0.5);
color: White;
}
</style>
</head>
<body>
<main id="webchat"></main>
<script type="text/babel" data-presets="env,stage-3,react">
const {
React: { useCallback, useState },
WebChat: {
hooks: { useCreateActivityStatusRenderer, useSendPostBack }
}
} = window;
const PasswordInputActivity = ({ activity }) => {
const [twoFACode, setTwoFACode] = useState('');
const [submitted, setSubmitted] = useState(false);
const renderActivityStatus = useCreateActivityStatusRenderer()({ activity });
const sendPostBack = useSendPostBack();
const handleCodeChange = useCallback(
({ target: { value } }) => {
setTwoFACode(value);
},
[setTwoFACode]
);
const handleSubmit = useCallback(
event => {
event.preventDefault();
sendPostBack({ code: twoFACode });
setSubmitted(true);
},
[sendPostBack, setSubmitted, twoFACode]
);
return (
<div className="password-input">
<form className="password-input__form" onSubmit={handleSubmit}>
<label className="password-input__box">
<span className="password-input__label">Please input your 2FA code</span>
<input
autoFocus={true}
className="password-input__input"
disabled={submitted}
onChange={handleCodeChange}
type="password"
value={twoFACode}
/>
</label>
</form>
{renderActivityStatus()}
</div>
);
};
const activityMiddleware =
() =>
next =>
(...args) => {
const [{ activity }] = args;
if (activity.type === 'password-input') {
return () => <PasswordInputActivity activity={activity} />;
}
return next(...args);
};
run(async function () {
const now = Date.now();
WebChat.renderWebChat(
{
activityMiddleware,
directLine: await testHelpers.createDirectLineWithTranscript([
{
from: {
role: 'bot'
},
text: 'Hello, World!',
textFormat: 'markdown',
timestamp: new Date(now).toISOString(),
type: 'message'
},
{
from: {
role: 'bot'
},
timestamp: new Date(now).toISOString(),
type: 'password-input'
}
]),
store: testHelpers.createStore()
},
document.getElementById('webchat')
);
await pageConditions.uiConnected();
await host.snapshot();
});
</script>
</body>
</html>