11import React from 'react' ;
22import { Display , Body , Mono } from './Typography' ;
3+ import { formatDate } from '../../utils/date' ;
4+
5+ import type { Subscription } from '../../types/subscription' ;
36
47interface SubscriptionProps {
58 id : string ; // Added ID for deletion
@@ -11,6 +14,7 @@ interface SubscriptionProps {
1114 category : string ;
1215 expirationDate ?: string ;
1316 onDelete ?: ( id : string ) => void ;
17+ onEdit ?: ( sub : Subscription ) => void ;
1418}
1519
1620export const SubscriptionCard : React . FC < SubscriptionProps > = ( {
@@ -22,7 +26,8 @@ export const SubscriptionCard: React.FC<SubscriptionProps> = ({
2226 nextPayment,
2327 category,
2428 expirationDate,
25- onDelete
29+ onDelete,
30+ onEdit
2631} ) => {
2732 return (
2833 < div className = "group relative border-b border-structural p-4 md:px-6 hover:bg-concrete/50 transition-colors duration-200" >
@@ -36,14 +41,25 @@ export const SubscriptionCard: React.FC<SubscriptionProps> = ({
3641 < Display as = "h3" variant = "medium" className = "text-xl md:text-2xl" > { name } </ Display >
3742 < div className = "flex items-center gap-2 mt-1" >
3843 < Mono variant = "label" className = "inline-block" > { category } </ Mono >
39- { onDelete && (
40- < button
41- onClick = { ( ) => onDelete ( id ) }
42- className = "md:hidden text-xs font-mono text-red-500 hover:underline uppercase"
43- >
44- [DELETE]
45- </ button >
46- ) }
44+ < Mono variant = "label" className = "inline-block" > { category } </ Mono >
45+ < div className = "flex gap-2" >
46+ { onEdit && (
47+ < button
48+ onClick = { ( ) => onEdit ( { id, name, price, frequency : cycle , nextRenewal : nextPayment , category, expirationDate } ) }
49+ className = "md:hidden text-xs font-mono text-ink/50 hover:underline uppercase"
50+ >
51+ [EDIT]
52+ </ button >
53+ ) }
54+ { onDelete && (
55+ < button
56+ onClick = { ( ) => onDelete ( id ) }
57+ className = "md:hidden text-xs font-mono text-red-500 hover:underline uppercase"
58+ >
59+ [DELETE]
60+ </ button >
61+ ) }
62+ </ div >
4763 </ div >
4864 </ div >
4965 </ div >
@@ -52,11 +68,11 @@ export const SubscriptionCard: React.FC<SubscriptionProps> = ({
5268 < div className = "flex items-end md:items-center justify-between md:justify-end gap-2 md:gap-12 min-w-[300px]" >
5369 < div className = "text-right" >
5470 < Body variant = "caption" className = "block mb-1" > Next Billing</ Body >
55- < Mono variant = "code" className = "bg-transparent text-ink/70" > { nextPayment } </ Mono >
71+ < Mono variant = "code" className = "bg-transparent text-ink/70" > { formatDate ( nextPayment ) } </ Mono >
5672 { expirationDate && (
5773 < div className = "mt-2" >
5874 < Body variant = "caption" className = "block mb-1 text-ink/50" > Expires</ Body >
59- < Mono variant = "code" className = "bg-transparent text-ink/70 text-xs" > { expirationDate } </ Mono >
75+ < Mono variant = "code" className = "bg-transparent text-ink/70 text-xs" > { formatDate ( expirationDate ) } </ Mono >
6076 </ div >
6177 ) }
6278 </ div >
@@ -70,15 +86,26 @@ export const SubscriptionCard: React.FC<SubscriptionProps> = ({
7086 </ div >
7187 < div className = "flex items-center gap-3" >
7288 < Body variant = "caption" className = "text-right text-signal" > /{ cycle } </ Body >
73- { onDelete && (
74- < button
75- onClick = { ( ) => onDelete ( id ) }
76- className = "hidden md:block opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono text-red-500 hover:text-red-600 uppercase"
77- title = "Remove Entry"
78- >
79- [DELETE]
80- </ button >
81- ) }
89+ < div className = "flex gap-2" >
90+ { onEdit && (
91+ < button
92+ onClick = { ( ) => onEdit ( { id, name, price, frequency : cycle , nextRenewal : nextPayment , category, expirationDate } ) }
93+ className = "hidden md:block opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono text-ink/50 hover:text-ink uppercase"
94+ title = "Edit Entry"
95+ >
96+ [EDIT]
97+ </ button >
98+ ) }
99+ { onDelete && (
100+ < button
101+ onClick = { ( ) => onDelete ( id ) }
102+ className = "hidden md:block opacity-0 group-hover:opacity-100 transition-opacity text-xs font-mono text-red-500 hover:text-red-600 uppercase"
103+ title = "Remove Entry"
104+ >
105+ [DELETE]
106+ </ button >
107+ ) }
108+ </ div >
82109 </ div >
83110 </ div >
84111 </ div >
0 commit comments