forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsernameModal.jsx
More file actions
47 lines (42 loc) · 1.47 KB
/
Copy pathUsernameModal.jsx
File metadata and controls
47 lines (42 loc) · 1.47 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
import React, { useState } from 'react';
import { useUsername } from '../context/UsernameContext';
const UsernameModal = ({ isOpen, onClose }) => {
const [inputValue, setInputValue] = useState('');
const { setCurrentUsername } = useUsername();
const handleSubmit = (e) => {
e.preventDefault();
if (inputValue.trim()) {
setCurrentUsername(inputValue.trim());
setInputValue('');
onClose();
}
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div className="bg-white rounded-lg p-6 w-full max-w-md">
<h2 className="text-2xl font-bold mb-4">Enter Username</h2>
<form onSubmit={handleSubmit}>
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
placeholder="Username (1-50 characters)"
maxLength="50"
minLength="1"
className="w-full px-4 py-2 border border-gray-300 rounded-lg mb-4 focus:outline-none focus:ring-2 focus:ring-blue-500"
autoFocus
/>
<button
type="submit"
disabled={!inputValue.trim()}
className="w-full bg-blue-500 text-white py-2 rounded-lg hover:bg-blue-600 disabled:opacity-50 disabled:cursor-not-allowed"
>
Continue
</button>
</form>
</div>
</div>
);
};
export default UsernameModal;