| 1 | import * as React from "react"; |
| 2 | import { |
| 3 | Dialog, |
| 4 | DialogContent, |
| 5 | DialogDescription, |
| 6 | DialogFooter, |
| 7 | DialogHeader, |
| 8 | DialogTitle, |
| 9 | } from "@/components/ui/dialog"; |
| 10 | import { Button } from "@/components/ui/button"; |
| 11 | import { Input } from "@/components/ui/input"; |
| 12 | import { Label } from "@/components/ui/label"; |
| 13 | |
| 14 | interface CategoryEditDialogProps { |
| 15 | open: boolean; |
| 16 | onOpenChange: (open: boolean) => void; |
| 17 | currentCategory: string; |
| 18 | onRename: (newName: string) => void; |
| 19 | } |
| 20 | |
| 21 | export function CategoryEditDialog({ |
| 22 | open, |
| 23 | onOpenChange, |
| 24 | currentCategory, |
| 25 | onRename, |
| 26 | }: CategoryEditDialogProps) { |
| 27 | const [newName, setNewName] = React.useState(currentCategory); |
| 28 | |
| 29 | React.useEffect(() => { |
| 30 | setNewName(currentCategory); |
| 31 | }, [currentCategory]); |
| 32 | |
| 33 | const handleSubmit = (e: React.FormEvent) => { |
| 34 | e.preventDefault(); |
| 35 | if (newName.trim() && newName !== currentCategory) { |
| 36 | onRename(newName.trim()); |
| 37 | onOpenChange(false); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | return ( |
| 42 | <Dialog open={open} onOpenChange={onOpenChange}> |
| 43 | <DialogContent className="sm:max-w-[425px]"> |
| 44 | <DialogHeader> |
| 45 | <DialogTitle>Rename Category</DialogTitle> |
| 46 | <DialogDescription> |
| 47 | Rename "{currentCategory}" to a new name. This will update all feeds |
| 48 | in this category. |
| 49 | </DialogDescription> |
| 50 | </DialogHeader> |
| 51 | <form onSubmit={handleSubmit}> |
| 52 | <div className="grid gap-4 py-4"> |
| 53 | <div className="grid gap-2"> |
| 54 | <Label htmlFor="category-name">Category Name</Label> |
| 55 | <Input |
| 56 | id="category-name" |
| 57 | value={newName} |
| 58 | onChange={(e) => setNewName(e.target.value)} |
| 59 | placeholder="Enter category name" |
| 60 | maxLength={50} |
| 61 | autoFocus |
| 62 | /> |
| 63 | </div> |
| 64 | </div> |
| 65 | <DialogFooter> |
| 66 | <Button |
| 67 | type="button" |
| 68 | variant="outline" |
| 69 | onClick={() => onOpenChange(false)} |
| 70 | > |
| 71 | Cancel |
| 72 | </Button> |
| 73 | <Button type="submit" disabled={!newName.trim()}> |
| 74 | Rename |
| 75 | </Button> |
| 76 | </DialogFooter> |
| 77 | </form> |
| 78 | </DialogContent> |
| 79 | </Dialog> |
| 80 | ); |
| 81 | } |