@@ -4,6 +4,8 @@ import { X, Check } from 'lucide-react';
44import type { Subscription , BillingFrequency } from '../../types/subscription' ;
55import { formatDate , parseDate , isValidDate } from '../../utils/date' ;
66
7+ import { DatePicker } from './DatePicker' ;
8+
79interface AddSubscriptionModalProps {
810 onAdd : ( sub : Omit < Subscription , 'id' > ) => void ;
911 onClose : ( ) => void ;
@@ -16,7 +18,7 @@ export const AddSubscriptionModal: React.FC<AddSubscriptionModalProps> = ({ onAd
1618 price : initialData ?. price . toString ( ) || '' ,
1719 frequency : ( initialData ?. frequency || 'monthly' ) as BillingFrequency ,
1820 category : initialData ?. category || '' ,
19- nextRenewal : initialData ? formatDate ( initialData . nextRenewal ) : formatDate ( new Date ( ) . toISOString ( ) . split ( 'T' ) [ 0 ] ) ,
21+ nextRenewal : initialData ?. nextRenewal ? formatDate ( initialData . nextRenewal ) : '' , // Optional renewal
2022 expirationDate : initialData ?. expirationDate ? formatDate ( initialData . expirationDate ) : ''
2123 } ) ;
2224
@@ -25,7 +27,7 @@ export const AddSubscriptionModal: React.FC<AddSubscriptionModalProps> = ({ onAd
2527 if ( ! formData . name || ! formData . price ) return ;
2628
2729 // Validate dates if present
28- if ( ! isValidDate ( formData . nextRenewal ) ) {
30+ if ( formData . nextRenewal && ! isValidDate ( formData . nextRenewal ) ) {
2931 alert ( 'Please enter a valid renewal date (DD/MM/YYYY)' ) ;
3032 return ;
3133 }
@@ -39,12 +41,13 @@ export const AddSubscriptionModal: React.FC<AddSubscriptionModalProps> = ({ onAd
3941 price : parseFloat ( formData . price ) ,
4042 frequency : formData . frequency ,
4143 category : formData . category ,
42- nextRenewal : parseDate ( formData . nextRenewal ) ,
44+ nextRenewal : formData . nextRenewal ? parseDate ( formData . nextRenewal ) : undefined ,
4345 expirationDate : formData . expirationDate ? parseDate ( formData . expirationDate ) : undefined
4446 } ) ;
4547 onClose ( ) ;
4648 } ;
4749
50+
4851 return (
4952 < div className = "fixed inset-0 z-50 flex items-center justify-center p-4 bg-ink/20 backdrop-blur-sm" >
5053 < div className = "bg-paper border-2 border-structural w-full max-w-lg shadow-2xl relative" >
@@ -140,31 +143,23 @@ export const AddSubscriptionModal: React.FC<AddSubscriptionModalProps> = ({ onAd
140143
141144 < div className = "space-y-2" >
142145 < label htmlFor = "sub-renewal" className = "block" >
143- < Body variant = "caption" className = "text-ink/60" > Initial Renewal</ Body >
146+ < Body variant = "caption" className = "text-ink/60" > Initial Renewal (Optional) </ Body >
144147 </ label >
145- < input
148+ < DatePicker
146149 id = "sub-renewal"
147- title = "Initial Renewal Date"
148- type = "text"
149- placeholder = "DD/MM/YYYY"
150- className = "w-full bg-concrete border-b border-structural p-3 font-mono text-sm focus:outline-none focus:border-signal uppercase"
151150 value = { formData . nextRenewal }
152- onChange = { e => setFormData ( { ...formData , nextRenewal : e . target . value } ) }
151+ onChange = { val => setFormData ( { ...formData , nextRenewal : val } ) }
153152 />
154153 </ div >
155154
156155 < div className = "space-y-2" >
157156 < label htmlFor = "sub-expires" className = "block" >
158157 < Body variant = "caption" className = "text-ink/60" > Expiration Date (Optional)</ Body >
159158 </ label >
160- < input
159+ < DatePicker
161160 id = "sub-expires"
162- title = "Expiration Date"
163- type = "text"
164- placeholder = "DD/MM/YYYY"
165- className = "w-full bg-concrete border-b border-structural p-3 font-mono text-sm focus:outline-none focus:border-signal uppercase"
166161 value = { formData . expirationDate }
167- onChange = { e => setFormData ( { ...formData , expirationDate : e . target . value } ) }
162+ onChange = { val => setFormData ( { ...formData , expirationDate : val } ) }
168163 />
169164 </ div >
170165
0 commit comments