@@ -16,7 +16,7 @@ import {
1616 DialogTitle ,
1717 DialogTrigger ,
1818} from "@/components/ui/dialog" ;
19- import { Plus , Loader2 , Check , AlertCircle } from "lucide-react" ;
19+ import { Plus , Loader2 , Check , AlertCircle , X } from "lucide-react" ;
2020import { F } from "@/components/ui/f" ;
2121
2222// Known brand configs
@@ -144,7 +144,7 @@ interface Subscription {
144144 is_paid : boolean ;
145145 is_overdue : boolean ;
146146 is_priority : number ;
147- patterns : string [ ] ;
147+ patterns : { id : number ; pattern : string } [ ] ;
148148}
149149
150150export default function SubscriptionsPage ( ) {
@@ -274,6 +274,17 @@ export default function SubscriptionsPage() {
274274 } catch ( err ) { console . error ( "[subscriptions] Add pattern error:" , err ) ; }
275275 } ;
276276
277+ const deletePattern = async ( patternId : number ) => {
278+ try {
279+ await fetch ( "/api/matches" , {
280+ method : "DELETE" ,
281+ headers : { "Content-Type" : "application/json" } ,
282+ body : JSON . stringify ( { id : patternId } ) ,
283+ } ) ;
284+ loadSubscriptions ( ) ;
285+ } catch ( err ) { console . error ( "[subscriptions] Delete pattern error:" , err ) ; }
286+ } ;
287+
277288 const active = subscriptions . filter ( ( s ) => s . is_active ) ;
278289 const monthlyTotal = active . reduce ( ( s , sub ) => s + sub . amount , 0 ) ;
279290 const yearlyTotal = monthlyTotal * 12 ;
@@ -353,7 +364,7 @@ export default function SubscriptionsPage() {
353364 </ div >
354365 < p className = "subscription-card-meta" >
355366 { locale === "fi" ? "Veloitus" : "Billing" } { sub . due_day } . { locale === "fi" ? "päivä" : "" }
356- { sub . patterns . length > 0 && < span className = "list-item-patterns" > – { sub . patterns . join ( ", " ) } </ span > }
367+ { sub . patterns . length > 0 && < span className = "list-item-patterns" > – { sub . patterns . map ( ( p ) => p . pattern ) . join ( ", " ) } </ span > }
357368 </ p >
358369 </ div >
359370 < div className = "subscription-card-right" >
@@ -406,8 +417,13 @@ export default function SubscriptionsPage() {
406417 </ div >
407418 { editTarget . patterns . length > 0 && (
408419 < div className = "match-pattern-list" >
409- { editTarget . patterns . map ( ( p , i ) => (
410- < span key = { i } className = "match-pattern-tag" > { p } </ span >
420+ { editTarget . patterns . map ( ( p ) => (
421+ < div key = { p . id } className = "match-pattern-item" >
422+ < span className = "match-pattern-tag" > { p . pattern } </ span >
423+ < button type = "button" className = "batch-remove-btn" onClick = { ( ) => deletePattern ( p . id ) } >
424+ < X />
425+ </ button >
426+ </ div >
411427 ) ) }
412428 </ div >
413429 ) }
0 commit comments