@@ -5,16 +5,14 @@ import { updatePolicyFormAction } from '@/actions/policies/update-policy-form-ac
55import { SelectAssignee } from '@/components/SelectAssignee' ;
66import { StatusIndicator } from '@/components/status-indicator' ;
77import { Button } from '@comp/ui/button' ;
8- import { Calendar } from '@comp/ui/calendar' ;
98import { cn } from '@comp/ui/cn' ;
10- import { Popover , PopoverContent , PopoverTrigger } from '@comp/ui/popover' ;
119import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from '@comp/ui/select' ;
1210import { Departments , Frequency , Member , type Policy , PolicyStatus , User } from '@db' ;
1311import { format } from 'date-fns' ;
1412import { CalendarIcon , Loader2 } from 'lucide-react' ;
1513import { useAction } from 'next-safe-action/hooks' ;
1614import { useRouter } from 'next/navigation' ;
17- import { useRef , useState } from 'react' ;
15+ import { useState } from 'react' ;
1816import { toast } from 'sonner' ;
1917import { SubmitApprovalDialog } from './SubmitApprovalDialog' ;
2018
@@ -42,11 +40,6 @@ export function UpdatePolicyOverview({
4240 // Track selected assignee
4341 const [ selectedAssigneeId , setSelectedAssigneeId ] = useState < string | null > ( policy . assigneeId ) ;
4442
45- // Date picker state - UI only
46- const [ isDatePickerOpen , setIsDatePickerOpen ] = useState ( false ) ;
47- const [ tempDate , setTempDate ] = useState < Date | undefined > ( undefined ) ;
48- const popoverRef = useRef < HTMLDivElement > ( null ) ;
49-
5043 // Loading state
5144 const [ isSubmitting , setIsSubmitting ] = useState ( false ) ;
5245
@@ -83,12 +76,6 @@ export function UpdatePolicyOverview({
8376 } ,
8477 } ) ;
8578
86- // Function to handle date confirmation
87- const handleDateConfirm = ( date : Date | undefined ) => {
88- setTempDate ( date ) ;
89- setIsDatePickerOpen ( false ) ;
90- } ;
91-
9279 // Function to handle form field changes
9380 const handleFormChange = ( ) => {
9481 setFormInteracted ( true ) ;
@@ -106,7 +93,7 @@ export function UpdatePolicyOverview({
10693 const reviewFrequency = formData . get ( 'review_frequency' ) as Frequency ;
10794
10895 // Get review date from the form or use the existing one
109- const reviewDate = tempDate || ( policy . reviewDate ? new Date ( policy . reviewDate ) : new Date ( ) ) ;
96+ const reviewDate = policy . reviewDate ? new Date ( policy . reviewDate ) : new Date ( ) ;
11097
11198 // Check if the policy is published and if there are changes
11299 const isPublishedWithChanges =
@@ -150,7 +137,7 @@ export function UpdatePolicyOverview({
150137 const reviewFrequency = formData . get ( 'review_frequency' ) as Frequency ;
151138
152139 // Get review date from the form or use the existing one
153- const reviewDate = tempDate || ( policy . reviewDate ? new Date ( policy . reviewDate ) : new Date ( ) ) ;
140+ const reviewDate = policy . reviewDate ? new Date ( policy . reviewDate ) : new Date ( ) ;
154141
155142 setIsSubmitting ( true ) ;
156143 submitForApproval . execute ( {
@@ -285,82 +272,32 @@ export function UpdatePolicyOverview({
285272 < label htmlFor = "review_date" className = "text-sm font-medium" >
286273 Review Date
287274 </ label >
288- < Popover
289- open = { isDatePickerOpen }
290- onOpenChange = { ( open ) => {
291- setIsDatePickerOpen ( open ) ;
292- if ( ! open ) {
293- setTempDate ( undefined ) ;
294- }
295- } }
296- >
297- < PopoverTrigger
298- asChild
299- disabled = { fieldsDisabled }
275+ < div className = "pt-1.5" >
276+ < Button
277+ type = "button"
278+ variant = "outline"
279+ disabled
300280 className = { cn (
301- fieldsDisabled && ' pointer-events-none cursor-not-allowed select-none',
281+ 'w-full pl-3 text-left font-normal pointer-events-none cursor-not-allowed select-none'
302282 ) }
303283 >
304- < div className = "pt-1.5" >
305- < Button
306- type = "button"
307- variant = { 'outline' }
308- disabled = { fieldsDisabled }
309- className = { cn ( 'w-full pl-3 text-left font-normal' ) }
310- >
311- { tempDate ? (
312- format ( tempDate , 'PPP' )
313- ) : policy . reviewDate ? (
314- format ( new Date ( policy . reviewDate ) , 'PPP' )
315- ) : (
316- < span > Select review date</ span >
317- ) }
318- < CalendarIcon className = "ml-auto h-4 w-4 opacity-50" />
319- </ Button >
320- </ div >
321- </ PopoverTrigger >
322- < PopoverContent className = "w-auto" align = "start" ref = { popoverRef } >
323- < div className = "p-1" >
324- < Calendar
325- mode = "single"
326- selected = {
327- tempDate || ( policy . reviewDate ? new Date ( policy . reviewDate ) : undefined )
328- }
329- onSelect = { ( date ) => {
330- setTempDate ( date ) ;
331- handleFormChange ( ) ;
332- } }
333- disabled = { ( date ) => date <= new Date ( ) }
334- initialFocus
335- />
336- < div className = "mt-4 flex justify-end gap-2" >
337- < Button
338- type = "button"
339- size = "sm"
340- variant = "outline"
341- onClick = { ( ) => {
342- setIsDatePickerOpen ( false ) ;
343- } }
344- >
345- Cancel
346- </ Button >
347- < Button type = "button" size = "sm" onClick = { ( ) => handleDateConfirm ( tempDate ) } >
348- Confirm Date
349- </ Button >
350- </ div >
351- </ div >
352- </ PopoverContent >
353- </ Popover >
284+ { policy . reviewDate ? (
285+ format ( new Date ( policy . reviewDate ) , 'PPP' )
286+ ) : (
287+ < span > None</ span >
288+ ) }
289+ < CalendarIcon className = "ml-auto h-4 w-4 opacity-50" />
290+ </ Button >
291+ </ div >
354292 { /* Hidden input to store the date value */ }
355293 < input
356294 type = "hidden"
357295 id = "review_date"
358296 name = "review_date"
359297 value = {
360- tempDate ?. toISOString ( ) ||
361- ( policy . reviewDate
298+ policy . reviewDate
362299 ? new Date ( policy . reviewDate ) . toISOString ( )
363- : new Date ( ) . toISOString ( ) )
300+ : new Date ( ) . toISOString ( )
364301 }
365302 />
366303 </ div >
0 commit comments