@@ -15,9 +15,8 @@ import type { DomainSelectorProps } from '../domains/DomainSelector';
15
15
import type { TagsSelectorProps } from '../tags/helpers/TagsSelector' ;
16
16
import type { TagsList } from '../tags/reducers/tagsList' ;
17
17
import { IconInput } from '../utils/components/IconInput' ;
18
- import type { DateTimeInputProps } from '../utils/dates/DateTimeInput' ;
19
- import { DateTimeInput } from '../utils/dates/DateTimeInput' ;
20
18
import { formatIsoDate } from '../utils/dates/helpers/date' ;
19
+ import { LabelledDateInput } from '../utils/dates/LabelledDateInput' ;
21
20
import { useFeature } from '../utils/features' ;
22
21
import { handleEventPreventingDefault , hasValue } from '../utils/helpers' ;
23
22
import { ShortUrlFormCheckboxGroup } from './helpers/ShortUrlFormCheckboxGroup' ;
@@ -26,7 +25,6 @@ import './ShortUrlForm.scss';
26
25
27
26
export type Mode = 'create' | 'create-basic' | 'edit' ;
28
27
29
- type DateFields = 'validSince' | 'validUntil' ;
30
28
type NonDateFields = 'longUrl' | 'customSlug' | 'shortCodeLength' | 'domain' | 'maxVisits' | 'title' ;
31
29
32
30
export interface ShortUrlFormProps < T extends ShlinkCreateShortUrlData | ShlinkEditShortUrlData > {
@@ -74,12 +72,9 @@ const ShortUrlForm: FCWithDeps<ShortUrlFormConnectProps, ShortUrlFormDeps> = (
74
72
// value gets removed. Otherwise, set undefined so that it gets ignored.
75
73
return hasValue ( initialValue ) ? null : undefined ;
76
74
} ;
77
- const submit = handleEventPreventingDefault ( async ( ) => onSave ( {
78
- ...shortUrlData ,
79
- validSince : formatIsoDate ( shortUrlData . validSince ) ?? null ,
80
- validUntil : formatIsoDate ( shortUrlData . validUntil ) ?? null ,
81
- maxVisits : ! hasValue ( shortUrlData . maxVisits ) ? null : Number ( shortUrlData . maxVisits ) ,
82
- } ) . then ( ( result : any ) => ! isEdit && ! isErrorAction ( result ) && reset ( ) ) . catch ( ( ) => { } ) ) ;
75
+ const submit = handleEventPreventingDefault ( async ( ) => onSave ( shortUrlData )
76
+ . then ( ( result : any ) => ! isEdit && ! isErrorAction ( result ) && reset ( ) )
77
+ . catch ( ( ) => { } ) ) ;
83
78
84
79
useEffect ( ( ) => {
85
80
setShortUrlData ( initialState ) ;
@@ -123,16 +118,6 @@ const ShortUrlForm: FCWithDeps<ShortUrlFormConnectProps, ShortUrlFormDeps> = (
123
118
} ) ) }
124
119
/>
125
120
) ;
126
- const renderDateInput = ( id : DateFields , placeholder : string , props : Partial < DateTimeInputProps > = { } ) => (
127
- < DateTimeInput
128
- name = { id }
129
- selected = { shortUrlData [ id ] ? toDate ( shortUrlData [ id ] as string | Date ) : null }
130
- placeholderText = { placeholder }
131
- isClearable
132
- onChange = { ( date ) => setShortUrlData ( ( prev ) => ( { ...prev , [ id ] : date } ) ) }
133
- { ...props }
134
- />
135
- ) ;
136
121
const basicComponents = (
137
122
< >
138
123
< FormGroup >
@@ -216,11 +201,44 @@ const ShortUrlForm: FCWithDeps<ShortUrlFormConnectProps, ShortUrlFormDeps> = (
216
201
217
202
< div className = "col-sm-6 mb-3" >
218
203
< SimpleCard title = "Limit access to the short URL" >
219
- { renderOptionalInput ( 'maxVisits' , 'Maximum number of visits allowed' , 'number' , { min : 1 } ) }
220
- < div className = "mb-3" >
221
- { renderDateInput ( 'validSince' , 'Enabled since...' , { maxDate : shortUrlData . validUntil ? toDate ( shortUrlData . validUntil ) : undefined } ) }
204
+ < div className = "row mb-3" >
205
+ < div className = "col-lg-6" >
206
+ < LabelledDateInput
207
+ label = "Enabled since"
208
+ withTime
209
+ maxDate = { shortUrlData . validUntil ? toDate ( shortUrlData . validUntil ) : undefined }
210
+ name = "validSince"
211
+ value = { shortUrlData . validSince ? toDate ( shortUrlData . validSince ) : null }
212
+ onChange = { ( date ) => setShortUrlData ( ( prev ) => ( { ...prev , validSince : formatIsoDate ( date ) } ) ) }
213
+ />
214
+ </ div >
215
+ < div className = "col-lg-6 mt-3 mt-lg-0" >
216
+ < LabelledDateInput
217
+ label = "Enabled until"
218
+ withTime
219
+ minDate = { shortUrlData . validSince ? toDate ( shortUrlData . validSince ) : undefined }
220
+ name = "validUntil"
221
+ value = { shortUrlData . validUntil ? toDate ( shortUrlData . validUntil ) : null }
222
+ onChange = { ( date ) => setShortUrlData ( ( prev ) => ( { ...prev , validUntil : formatIsoDate ( date ) } ) ) }
223
+ />
224
+ </ div >
225
+ </ div >
226
+
227
+ < div >
228
+ < label htmlFor = "maxVisits" className = "mb-1" > Maximum visits allowed:</ label >
229
+ < Input
230
+ name = "maxVisits"
231
+ id = "maxVisits"
232
+ type = "number"
233
+ min = { 1 }
234
+ placeholder = "25..."
235
+ value = { shortUrlData . maxVisits ?? '' }
236
+ onChange = { ( e ) => setShortUrlData ( ( prev ) => ( {
237
+ ...prev ,
238
+ maxVisits : ! hasValue ( e . target . value ) ? null : Number ( e . target . value ) ,
239
+ } ) ) }
240
+ />
222
241
</ div >
223
- { renderDateInput ( 'validUntil' , 'Enabled until...' , { minDate : shortUrlData . validSince ? toDate ( shortUrlData . validSince ) : undefined } ) }
224
242
</ SimpleCard >
225
243
</ div >
226
244
</ Row >
0 commit comments