-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit-part-modal.tsx
66 lines (61 loc) · 1.62 KB
/
edit-part-modal.tsx
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
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { Textarea } from '@/components/ui/textarea'
import { trimText } from '@/lib/text'
import type { Part } from '@/lib/types'
import { useState } from 'react'
interface EditPartModalProps {
part: Part
isOpen: boolean
onClose: () => void
onSave: (updatedPart: Part) => void
}
export function EditPartModal({
part,
isOpen,
onClose,
onSave,
}: EditPartModalProps) {
const [editedPart, setEditedPart] = useState(part)
const handleNameChange = (e: React.ChangeEvent<HTMLTextAreaElement>) => {
setEditedPart({ ...editedPart, name: e.target.value })
}
const handleSave = () => {
onSave({ ...editedPart, name: trimText(editedPart.name) })
onClose()
}
return (
<Dialog open={isOpen} onOpenChange={onClose}>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit Part</DialogTitle>
</DialogHeader>
<DialogDescription>
Edit the name of the selected part. You can use multiple lines if
needed.
</DialogDescription>
<div className="py-4">
<Textarea
value={editedPart.name}
onChange={handleNameChange}
placeholder="Enter part name"
rows={3}
/>
</div>
<DialogFooter>
<Button variant="outline" onClick={onClose}>
Cancel
</Button>
<Button onClick={handleSave}>Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}