forked from subha0319/Project-Manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditProjectModal.jsx
More file actions
86 lines (78 loc) · 2.7 KB
/
EditProjectModal.jsx
File metadata and controls
86 lines (78 loc) · 2.7 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
import React, { useState, useEffect } from 'react';
import * as projectService from '../services/projectService';
const EditProjectModal = ({
isOpen,
onClose,
project,
onProjectUpdated
}) => {
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
// Pre-fill fields when modal opens or project changes
useEffect(() => {
if (project) {
setTitle(project.title || '');
setDescription(project.description || '');
}
}, [project]);
const handleSubmit = async (e) => {
e.preventDefault();
try {
const updatedProject = await projectService.updateProject(project._id, {
title,
description,
});
onProjectUpdated(updatedProject);
onClose();
} catch (error) {
console.error('Failed to update project:', error);
}
};
if (!isOpen) return null;
return (
<div className="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center z-50">
<div className="bg-gray-800 rounded-lg shadow-xl p-6 w-full max-w-lg">
<h2 className="text-2xl font-bold mb-4">Edit Project</h2>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label htmlFor="title" className="block text-sm font-medium text-gray-400">Title</label>
<input
id="title"
type="text"
value={title}
onChange={(e) => setTitle(e.target.value)}
required
className="w-full px-3 py-2 mt-1 text-white bg-gray-700 border border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div>
<label htmlFor="description" className="block text-sm font-medium text-gray-400">Description</label>
<textarea
id="description"
value={description}
onChange={(e) => setDescription(e.target.value)}
rows="3"
className="w-full px-3 py-2 mt-1 text-white bg-gray-700 border border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
/>
</div>
<div className="flex justify-end space-x-4 pt-4">
<button
type="button"
onClick={onClose}
className="px-4 py-2 font-semibold bg-gray-600 rounded-md hover:bg-gray-700"
>
Cancel
</button>
<button
type="submit"
className="px-4 py-2 font-semibold bg-blue-600 rounded-md hover:bg-blue-700"
>
Save Changes
</button>
</div>
</form>
</div>
</div>
);
};
export default EditProjectModal;