1 | import React, { useContext, useState } from "react";
|
---|
2 | import PropTypes from "prop-types";
|
---|
3 | import styles from "./CreateMapModal.module.css";
|
---|
4 |
|
---|
5 | const CreateMapModal = ({ isOpen, onClose,addMap}) => {
|
---|
6 | const [mapName, setMapName] = useState("");
|
---|
7 | const [mapType, setMapType] = useState("");
|
---|
8 |
|
---|
9 | const handleSubmit = (e) => {
|
---|
10 | const mapDetails = {
|
---|
11 | name: mapName,
|
---|
12 | type: mapType,
|
---|
13 | };
|
---|
14 |
|
---|
15 | addMap(mapDetails);
|
---|
16 |
|
---|
17 | onClose();
|
---|
18 | };
|
---|
19 |
|
---|
20 | if (!isOpen) return null;
|
---|
21 |
|
---|
22 | return (
|
---|
23 | <div className={styles.modalOverlay} onClick={onClose}>
|
---|
24 | <div className={styles.modalContent} onClick={(e) => e.stopPropagation()}>
|
---|
25 | <h2 className={styles.title}>Enter Map Details</h2>
|
---|
26 | <form onSubmit={handleSubmit} className={styles.formData}>
|
---|
27 | <label>
|
---|
28 | Map Name:
|
---|
29 | <input
|
---|
30 | type="text"
|
---|
31 | value={mapName}
|
---|
32 | onChange={(e) => setMapName(e.target.value)}
|
---|
33 | required
|
---|
34 | />
|
---|
35 | </label>
|
---|
36 | <label>
|
---|
37 | Map Type:
|
---|
38 | <input
|
---|
39 | type="text"
|
---|
40 | value={mapType}
|
---|
41 | onChange={(e) => setMapType(e.target.value)}
|
---|
42 | required
|
---|
43 | />
|
---|
44 | </label>
|
---|
45 | <div className={styles.modalButtons}>
|
---|
46 | <button type="submit" className={styles.modalSubmitButton}>
|
---|
47 | Submit
|
---|
48 | </button>
|
---|
49 | <button type="button" className={styles.modalCancelButton} onClick={onClose}>
|
---|
50 | Cancel
|
---|
51 | </button>
|
---|
52 | </div>
|
---|
53 | </form>
|
---|
54 | </div>
|
---|
55 | </div>
|
---|
56 | );
|
---|
57 | };
|
---|
58 |
|
---|
59 | CreateMapModal.propTypes = {
|
---|
60 | isOpen: PropTypes.bool.isRequired,
|
---|
61 | onClose: PropTypes.func.isRequired,
|
---|
62 | };
|
---|
63 |
|
---|
64 | export default CreateMapModal;
|
---|