-
Notifications
You must be signed in to change notification settings - Fork 16
/
vidushipr3
60 lines (48 loc) · 1.79 KB
/
vidushipr3
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
import { useState } from 'react';
import axios from 'axios';
const projectID = '1b7801d6-8a66-4be4-a442-89219d833dfc';
const Modal = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
const authObject = { 'Project-ID': projectID, 'User-Name': username, 'User-Secret': password };
try {
await axios.get('https://api.chatengine.io/chats', { headers: authObject });
localStorage.setItem('username', username);
localStorage.setItem('password', password);
window.location.reload();
setError('');
} catch (err) {
setError('Oops, incorrect credentials.');
}
};
return (
<div className="wrapper">
<div className="form">
<h1 className="title">Chat Application</h1>
<form onSubmit={handleSubmit}>
<input type="text" value={username} onChange={(e) => setUsername(e.target.value)} className="input" placeholder="Username" required />
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} className="input" placeholder="Password" required />
<div align="center">
<button type="submit" className="button">
<span>Start chatting</span>
</button>
</div>
</form>
<h1>{error}</h1>
</div>
</div>
);
};
export default Modal;
2
src/components/MessageForm.jsx
@@ -25,7 +25,7 @@ const MessageForm = (props) => {
};
const handleUpload = (event) => {
sendMessage(creds, chatId, { files: event.target.files });
sendMessage(creds, chatId, { files: event.target.files, text: '' });
};
return (