✨ feat: improve MilestonesList.tsx
swadhinbiswas committed 3 months ago
9004b79
1 parent 8363805
commit 9004b79
1 file changed
+36 -3
Showing 1 changed file+36-3
▼src/components/milestones/MilestonesList.tsx
+36-3
| @@ -16,6 +16,7 @@ import { | ||
16 | 16 | Archive |
17 | 17 | } from "lucide-react"; |
18 | 18 | import { useState } from "react"; |
19 | +import { toast } from "sonner"; | |
19 | 20 | |
20 | 21 | interface MilestoneItem { |
21 | 22 | id: string; |
| @@ -188,15 +189,47 @@ export default function MilestonesList({ milestones, repoOwner, repoName }: Prop | ||
188 | 189 | className="absolute right-0 top-full mt-1 w-40 rounded-lg border border-border bg-accent shadow-xl z-10" |
189 | 190 | > |
190 | 191 | <div className="p-1"> |
191 | - <button className="w-full flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:bg-accent rounded-md"> | |
192 | + <button | |
193 | + onClick={() => { setShowMenu(null); window.location.href = `/${repoOwner}/${repoName}/milestones/${milestone.id}/edit`; }} | |
194 | + className="w-full flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:bg-accent rounded-md" | |
195 | + > | |
192 | 196 | <Edit3 className="h-4 w-4" /> |
193 | 197 | Edit |
194 | 198 | </button> |
195 | - <button className="w-full flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:bg-accent rounded-md"> | |
199 | + <button | |
200 | + onClick={async () => { | |
201 | + setShowMenu(null); | |
202 | + try { | |
203 | + const res = await fetch(`/api/repos/${repoOwner}/${repoName}/milestones/${milestone.id}`, { | |
204 | + method: 'PATCH', | |
205 | + headers: { 'Content-Type': 'application/json' }, | |
206 | + body: JSON.stringify({ state: 'closed' }), | |
207 | + }); | |
208 | + if (!res.ok) throw new Error('Failed'); | |
209 | + toast.success('Milestone closed'); | |
210 | + window.location.reload(); | |
211 | + } catch { toast.error('Failed to close milestone'); } | |
212 | + }} | |
213 | + className="w-full flex items-center gap-2 px-3 py-2 text-sm text-muted-foreground hover:bg-accent rounded-md" | |
214 | + > | |
196 | 215 | <Archive className="h-4 w-4" /> |
197 | 216 | Close |
198 | 217 | </button> |
199 | - <button className="w-full flex items-center gap-2 px-3 py-2 text-sm text-red-400 hover:bg-red-500/10 rounded-md"> | |
218 | + <button | |
219 | + onClick={async () => { | |
220 | + setShowMenu(null); | |
221 | + if (!confirm('Delete this milestone?')) return; | |
222 | + try { | |
223 | + const res = await fetch(`/api/repos/${repoOwner}/${repoName}/milestones/${milestone.id}`, { | |
224 | + method: 'DELETE', | |
225 | + }); | |
226 | + if (!res.ok) throw new Error('Failed'); | |
227 | + toast.success('Milestone deleted'); | |
228 | + window.location.reload(); | |
229 | + } catch { toast.error('Failed to delete milestone'); } | |
230 | + }} | |
231 | + className="w-full flex items-center gap-2 px-3 py-2 text-sm text-red-400 hover:bg-red-500/10 rounded-md" | |
232 | + > | |
200 | 233 | <Trash2 className="h-4 w-4" /> |
201 | 234 | Delete |
202 | 235 | </button> |
203 | 236 | |