11"use client" ;
22
33import * as React from "react" ;
4- import { format } from "date-fns" ;
5- import { CalendarIcon } from "lucide-react" ;
64import { motion } from "motion/react" ;
75import { useLocale , useTranslations } from "next-intl" ;
86
@@ -33,10 +31,8 @@ import {
3331 DropdownMenuSeparator ,
3432 DropdownMenuTrigger ,
3533} from "@/components/ui/dropdown-menu" ;
36- import { Calendar } from "@/components/ui/calendar" ;
3734import { Input } from "@/components/ui/input" ;
3835import { Label } from "@/components/ui/label" ;
39- import { Popover , PopoverContent , PopoverTrigger } from "@/components/ui/popover" ;
4036import {
4137 Sheet ,
4238 SheetContent ,
@@ -54,7 +50,7 @@ import {
5450import { resolveAvatarImageSrc } from "@/shared/lib/avatar" ;
5551import { TimeZoneSelect } from "@/shared/components/time-zone-select" ;
5652import { cn } from "@/lib/utils" ;
57- import { ADMIN_DATE_PICKER_TRIGGER_CLASSNAME } from "@/features/admin/components/admin-date-range-filter " ;
53+ import { AdminDateTimePicker } from "@/features/admin/components/admin-date-time-picker " ;
5854import type { UserDTO } from "@/shared/api/auth.types" ;
5955import type { AdminUserRole , AdminUserStatus } from "@/features/admin/api/admin.types" ;
6056import {
@@ -134,7 +130,6 @@ type CreateUserDialogProps = {
134130 username : string ;
135131 displayName : string ;
136132 } ;
137- createSubscriptionExpiryDate ?: Date ;
138133 onOpenCreateAvatarDialog : ( ) => void ;
139134 onCreateSubmit : React . FormEventHandler < HTMLFormElement > ;
140135 resolveCreateUserInitial : ( username : string , displayName : string ) => string ;
@@ -150,7 +145,6 @@ export function CreateUserDialog({
150145 billingMode,
151146 billingPlans,
152147 createAvatarSource,
153- createSubscriptionExpiryDate,
154148 onOpenCreateAvatarDialog,
155149 onCreateSubmit,
156150 resolveCreateUserInitial,
@@ -252,40 +246,20 @@ export function CreateUserDialog({
252246 </ div >
253247
254248 < DialogCollapsible open = { createPayload . subscriptionTier !== "free" } >
255- < div className = "space-y-1 pt-0.5" >
256- < p className = "text-xs text-muted-foreground" > { t ( "editor.expiryTime" ) } </ p >
257- < Popover >
258- < PopoverTrigger asChild >
259- < Button
260- type = "button"
261- variant = "outline"
262- className = { cn (
263- ADMIN_DATE_PICKER_TRIGGER_CLASSNAME ,
264- "justify-between" ,
265- ! createSubscriptionExpiryDate && "text-muted-foreground" ,
266- ) }
267- disabled = { createPayload . subscriptionTier === "free" }
268- >
269- { createSubscriptionExpiryDate ? format ( createSubscriptionExpiryDate , "yyyy-MM-dd" ) : t ( "editor.selectExpiryDate" ) }
270- < CalendarIcon className = "size-3.5 opacity-70" />
271- </ Button >
272- </ PopoverTrigger >
273- < PopoverContent className = "w-auto p-0" align = "start" >
274- < Calendar
275- mode = "single"
276- selected = { createSubscriptionExpiryDate }
277- onSelect = { ( date ) =>
278- setCreatePayload ( ( current ) => ( {
279- ...current ,
280- subscriptionExpiresAt : date ? format ( date , "yyyy-MM-dd" ) : "" ,
281- } ) )
282- }
283- disabled = { { before : new Date ( ) } }
284- autoFocus
285- />
286- </ PopoverContent >
287- </ Popover >
288- </ div >
249+ < AdminDateTimePicker
250+ value = { createPayload . subscriptionExpiresAt }
251+ label = { t ( "editor.expiryTime" ) }
252+ placeholder = { t ( "editor.selectExpiryDate" ) }
253+ granularity = "date"
254+ disabled = { createPayload . subscriptionTier === "free" }
255+ disabledDate = { { before : new Date ( ) } }
256+ onChange = { ( value ) =>
257+ setCreatePayload ( ( current ) => ( {
258+ ...current ,
259+ subscriptionExpiresAt : value ,
260+ } ) )
261+ }
262+ />
289263 </ DialogCollapsible >
290264 </ div >
291265 ) : null }
@@ -313,7 +287,6 @@ type EditUserSheetProps = {
313287 setEditPayload : React . Dispatch < React . SetStateAction < EditUserPayload > > ;
314288 billingMode : AdminBillingMode ;
315289 billingPlans : AdminBillingPlanDTO [ ] ;
316- editSubscriptionExpiryDate ?: Date ;
317290 statusChanged : boolean ;
318291 timeZoneOptions : string [ ] ;
319292 roleOptions : AdminUserRole [ ] ;
@@ -380,7 +353,6 @@ export function EditUserSheet({
380353 setEditPayload,
381354 billingMode,
382355 billingPlans,
383- editSubscriptionExpiryDate,
384356 statusChanged,
385357 timeZoneOptions,
386358 roleOptions,
@@ -638,40 +610,20 @@ export function EditUserSheet({
638610 </ Combobox >
639611 </ div >
640612 < DialogCollapsible open = { editPayload . subscriptionTier !== "free" } >
641- < div className = "space-y-1" >
642- < Label className = "text-xs text-muted-foreground" > { t ( "editor.expiryTime" ) } </ Label >
643- < Popover >
644- < PopoverTrigger asChild >
645- < Button
646- type = "button"
647- variant = "outline"
648- className = { cn (
649- ADMIN_DATE_PICKER_TRIGGER_CLASSNAME ,
650- "justify-between" ,
651- ! editSubscriptionExpiryDate && "text-muted-foreground" ,
652- ) }
653- disabled = { pending || editPayload . subscriptionTier === "free" }
654- >
655- { editSubscriptionExpiryDate ? format ( editSubscriptionExpiryDate , "yyyy-MM-dd" ) : t ( "editor.selectExpiryDate" ) }
656- < CalendarIcon className = "size-3.5 opacity-70" />
657- </ Button >
658- </ PopoverTrigger >
659- < PopoverContent className = "w-auto p-0" align = "start" >
660- < Calendar
661- mode = "single"
662- selected = { editSubscriptionExpiryDate }
663- onSelect = { ( date ) =>
664- setEditPayload ( ( current ) => ( {
665- ...current ,
666- subscriptionExpiresAt : date ? format ( date , "yyyy-MM-dd" ) : "" ,
667- } ) )
668- }
669- disabled = { { before : new Date ( ) } }
670- autoFocus
671- />
672- </ PopoverContent >
673- </ Popover >
674- </ div >
613+ < AdminDateTimePicker
614+ value = { editPayload . subscriptionExpiresAt }
615+ label = { t ( "editor.expiryTime" ) }
616+ placeholder = { t ( "editor.selectExpiryDate" ) }
617+ granularity = "date"
618+ disabled = { pending || editPayload . subscriptionTier === "free" }
619+ disabledDate = { { before : new Date ( ) } }
620+ onChange = { ( value ) =>
621+ setEditPayload ( ( current ) => ( {
622+ ...current ,
623+ subscriptionExpiresAt : value ,
624+ } ) )
625+ }
626+ />
675627 </ DialogCollapsible >
676628 </ div >
677629 ) : null }
0 commit comments