@@ -6,7 +6,6 @@ import { useParams } from "next/navigation";
66import { Controller , useForm } from "react-hook-form" ;
77import {
88 ArchiveRestoreIcon ,
9- CalendarCheck2 ,
109 CalendarClock ,
1110 ChevronDown ,
1211 ChevronRight ,
@@ -43,7 +42,7 @@ import {
4342 TextArea ,
4443} from "@plane/ui" ;
4544// components
46- import { DateDropdown , MemberDropdown } from "@/components/dropdowns" ;
45+ import { DateRangeDropdown , MemberDropdown } from "@/components/dropdowns" ;
4746import {
4847 ArchiveModuleModal ,
4948 DeleteModuleModal ,
@@ -105,7 +104,7 @@ export const ModuleAnalyticsSidebar: React.FC<Props> = observer((props) => {
105104 const estimateType = areEstimateEnabled && currentActiveEstimateId && estimateById ( currentActiveEstimateId ) ;
106105 const isEstimatePointValid = estimateType && estimateType ?. type == EEstimateSystem . POINTS ? true : false ;
107106
108- const { reset, control, getValues } = useForm ( {
107+ const { reset, control } = useForm ( {
109108 defaultValues,
110109 } ) ;
111110
@@ -195,8 +194,11 @@ export const ModuleAnalyticsSidebar: React.FC<Props> = observer((props) => {
195194 } ) ;
196195 } ;
197196
198- const handleDateChange = async ( data : Partial < IModule > ) => {
199- submitChanges ( data ) ;
197+ const handleDateChange = async ( startDate : Date | undefined , targetDate : Date | undefined ) => {
198+ submitChanges ( {
199+ start_date : startDate ? renderFormattedPayloadDate ( startDate ) : null ,
200+ target_date : targetDate ? renderFormattedPayloadDate ( targetDate ) : null ,
201+ } ) ;
200202 setToast ( {
201203 type : TOAST_TYPE . SUCCESS ,
202204 title : "Success!" ,
@@ -413,59 +415,40 @@ export const ModuleAnalyticsSidebar: React.FC<Props> = observer((props) => {
413415 < div className = "flex items-center justify-start gap-1" >
414416 < div className = "flex w-2/5 items-center justify-start gap-2 text-custom-text-300" >
415417 < CalendarClock className = "h-4 w-4" />
416- < span className = "text-base" > Start date</ span >
417- </ div >
418- < div className = "flex flex-wrap items-center gap-2" >
419- < Controller
420- name = "start_date"
421- control = { control }
422- rules = { { required : "Please select a date" } }
423- render = { ( { field : { value, onChange } } ) => (
424- < DateDropdown
425- value = { value ?? null }
426- onChange = { ( val ) => {
427- console . log ( val ) ;
428- onChange ( renderFormattedPayloadDate ( val ) ) ;
429- handleDateChange ( { start_date : val ? renderFormattedPayloadDate ( val ) : null } ) ;
430- } }
431- placeholder = { t ( "common.order_by.start_date" ) }
432- icon = { < CalendarClock className = "h-3 w-3 flex-shrink-0" /> }
433- buttonVariant = { value ? "border-with-text" : "border-without-text" }
434- buttonContainerClassName = { `h-6 w-full flex ${ ! isEditingAllowed || isArchived ? "cursor-not-allowed" : "cursor-pointer" } items-center gap-1.5 text-custom-text-300 rounded text-xs` }
435- optionsClassName = "z-30"
436- disabled = { ! isEditingAllowed || isArchived }
437- showTooltip
438- maxDate = { getDate ( getValues ( "target_date" ) ) }
439- />
440- ) }
441- />
442- </ div >
443- </ div >
444- < div className = "flex items-center justify-start gap-1" >
445- < div className = "flex w-2/5 items-center justify-start gap-2 text-custom-text-300" >
446- < CalendarClock className = "h-4 w-4" />
447- < span className = "text-base" > Due date</ span >
418+ < span className = "text-base" > { t ( "date_range" ) } </ span >
448419 </ div >
449- < div className = "flex flex-wrap items-center gap-2 " >
420+ < div className = "h-7 w-3/5 " >
450421 < Controller
451- name = "target_date"
452422 control = { control }
453- rules = { { required : "Please select a date" } }
454- render = { ( { field : { value, onChange } } ) => (
455- < DateDropdown
456- value = { getDate ( value ) ?? null }
457- onChange = { ( val ) => {
458- onChange ( renderFormattedPayloadDate ( val ) ) ;
459- handleDateChange ( { target_date : val ? renderFormattedPayloadDate ( val ) : null } ) ;
423+ name = "start_date"
424+ render = { ( { field : { value : startDateValue , onChange : onChangeStartDate } } ) => (
425+ < Controller
426+ control = { control }
427+ name = "target_date"
428+ render = { ( { field : { value : endDateValue , onChange : onChangeEndDate } } ) => {
429+ const startDate = getDate ( startDateValue ) ;
430+ const endDate = getDate ( endDateValue ) ;
431+ return (
432+ < DateRangeDropdown
433+ buttonContainerClassName = "w-full"
434+ buttonVariant = "background-with-text"
435+ value = { {
436+ from : startDate ,
437+ to : endDate ,
438+ } }
439+ onSelect = { ( val ) => {
440+ onChangeStartDate ( val ?. from ? renderFormattedPayloadDate ( val . from ) : null ) ;
441+ onChangeEndDate ( val ?. to ? renderFormattedPayloadDate ( val . to ) : null ) ;
442+ handleDateChange ( val ?. from , val ?. to ) ;
443+ } }
444+ placeholder = { {
445+ from : t ( "start_date" ) ,
446+ to : t ( "target_date" ) ,
447+ } }
448+ disabled = { ! isEditingAllowed || isArchived }
449+ />
450+ ) ;
460451 } }
461- placeholder = { t ( "common.order_by.due_date" ) }
462- icon = { < CalendarCheck2 className = "h-3 w-3 flex-shrink-0" /> }
463- buttonVariant = { value ? "border-with-text" : "border-without-text" }
464- buttonContainerClassName = { `h-6 w-full flex ${ ! isEditingAllowed || isArchived ? "cursor-not-allowed" : "cursor-pointer" } items-center gap-1.5 text-custom-text-300 rounded text-xs` }
465- optionsClassName = "z-30"
466- disabled = { ! isEditingAllowed || isArchived }
467- showTooltip
468- minDate = { getDate ( getValues ( "start_date" ) ) }
469452 />
470453 ) }
471454 />
0 commit comments