Skip to content

Commit 0188cab

Browse files
authored
fix: module date picker (#6691)
* fix: Handled workspace switcher closing on click * fix: reverted module date picker changes
1 parent 392a6e0 commit 0188cab

File tree

3 files changed

+75
-113
lines changed

3 files changed

+75
-113
lines changed

web/core/components/modules/analytics-sidebar/root.tsx

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { useParams } from "next/navigation";
66
import { Controller, useForm } from "react-hook-form";
77
import {
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";
4746
import {
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
/>

web/core/components/modules/module-card-item.tsx

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { SyntheticEvent, useRef } from "react";
44
import { observer } from "mobx-react";
55
import Link from "next/link";
66
import { useParams, usePathname, useSearchParams } from "next/navigation";
7-
import { CalendarCheck2, CalendarClock, Info, SquareUser } from "lucide-react";
7+
import { Info, SquareUser } from "lucide-react";
88
// plane package imports
99
import {
1010
MODULE_STATUS,
@@ -14,7 +14,6 @@ import {
1414
EUserPermissions,
1515
EUserPermissionsLevel,
1616
} from "@plane/constants";
17-
import { useTranslation } from "@plane/i18n";
1817
import { IModule } from "@plane/types";
1918
import {
2019
Card,
@@ -27,7 +26,7 @@ import {
2726
setToast,
2827
} from "@plane/ui";
2928
// components
30-
import { DateDropdown } from "@/components/dropdowns";
29+
import { DateRangeDropdown } from "@/components/dropdowns";
3130
import { ButtonAvatars } from "@/components/dropdowns/member/avatar";
3231
import { ModuleQuickActions } from "@/components/modules";
3332
import { ModuleStatusDropdown } from "@/components/modules/module-status-dropdown";
@@ -59,14 +58,15 @@ export const ModuleCardItem: React.FC<Props> = observer((props) => {
5958
const { getModuleById, addModuleToFavorites, removeModuleFromFavorites, updateModuleDetails } = useModule();
6059
const { getUserDetails } = useMember();
6160
const { captureEvent } = useEventTracker();
62-
const { t } = useTranslation();
61+
6362
// derived values
6463
const moduleDetails = getModuleById(moduleId);
6564
const isEditingAllowed = allowPermissions(
6665
[EUserPermissions.ADMIN, EUserPermissions.MEMBER],
6766
EUserPermissionsLevel.PROJECT
6867
);
6968
const isDisabled = !isEditingAllowed || !!moduleDetails?.archived_at;
69+
const renderIcon = Boolean(moduleDetails?.start_date) || Boolean(moduleDetails?.target_date);
7070

7171
const { isMobile } = usePlatformOS();
7272
const handleAddToFavorites = (e: React.MouseEvent<HTMLButtonElement>) => {
@@ -236,38 +236,27 @@ export const ModuleCardItem: React.FC<Props> = observer((props) => {
236236
)}
237237
</div>
238238
<LinearProgressIndicator size="lg" data={progressIndicatorData} />
239-
<div className="flex items-center gap-2 py-0.5" onClick={handleEventPropagation}>
240-
<DateDropdown
241-
value={moduleDetails.start_date}
242-
onChange={(val) => {
243-
handleModuleDetailsChange({
244-
start_date: val ? renderFormattedPayloadDate(val) : null,
245-
});
239+
<div className="flex items-center justify-between py-0.5" onClick={handleEventPropagation}>
240+
<DateRangeDropdown
241+
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 border-[0.5px] border-custom-border-300 rounded text-xs`}
242+
buttonVariant="transparent-with-text"
243+
className="h-7"
244+
value={{
245+
from: getDate(moduleDetails.start_date),
246+
to: getDate(moduleDetails.target_date),
246247
}}
247-
placeholder={t("common.order_by.start_date")}
248-
icon={<CalendarClock className="h-3 w-3 flex-shrink-0" />}
249-
buttonVariant={moduleDetails.start_date ? "border-with-text" : "border-without-text"}
250-
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 rounded text-xs`}
251-
optionsClassName="z-10"
252-
disabled={isDisabled}
253-
showTooltip
254-
maxDate={getDate(moduleDetails.target_date)}
255-
/>
256-
<DateDropdown
257-
value={moduleDetails.target_date}
258-
onChange={(val) => {
248+
onSelect={(val) => {
259249
handleModuleDetailsChange({
260-
target_date: val ? renderFormattedPayloadDate(val) : null,
250+
start_date: val?.from ? renderFormattedPayloadDate(val.from) : null,
251+
target_date: val?.to ? renderFormattedPayloadDate(val.to) : null,
261252
});
262253
}}
263-
placeholder={t("common.order_by.due_date")}
264-
icon={<CalendarCheck2 className="h-3 w-3 flex-shrink-0" />}
265-
buttonVariant={moduleDetails.target_date ? "border-with-text" : "border-without-text"}
266-
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 rounded text-xs`}
267-
optionsClassName="z-10"
254+
placeholder={{
255+
from: "Start date",
256+
to: "End date",
257+
}}
268258
disabled={isDisabled}
269-
showTooltip
270-
minDate={getDate(moduleDetails.start_date)}
259+
hideIcon={{ from: renderIcon ?? true, to: renderIcon }}
271260
/>
272261
</div>
273262
</div>

web/core/components/modules/module-list-item-action.tsx

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { FC } from "react";
44
import { observer } from "mobx-react";
55
import { useParams } from "next/navigation";
66
// icons
7-
import { CalendarCheck2, CalendarClock, SquareUser } from "lucide-react";
7+
import { SquareUser } from "lucide-react";
88
// types
99
import {
1010
MODULE_STATUS,
@@ -18,7 +18,7 @@ import { IModule } from "@plane/types";
1818
// ui
1919
import { FavoriteStar, TOAST_TYPE, Tooltip, setPromiseToast, setToast } from "@plane/ui";
2020
// components
21-
import { DateDropdown } from "@/components/dropdowns";
21+
import { DateRangeDropdown } from "@/components/dropdowns";
2222
import { ModuleQuickActions } from "@/components/modules";
2323
import { ModuleStatusDropdown } from "@/components/modules/module-status-dropdown";
2424
// constants
@@ -138,38 +138,28 @@ export const ModuleListItemAction: FC<Props> = observer((props) => {
138138

139139
return (
140140
<>
141-
<DateDropdown
142-
value={moduleDetails.start_date}
143-
onChange={(val) => {
144-
handleModuleDetailsChange({
145-
start_date: val ? renderFormattedPayloadDate(val) : null,
146-
});
141+
<DateRangeDropdown
142+
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 border-[0.5px] border-custom-border-300 rounded text-xs`}
143+
buttonVariant="transparent-with-text"
144+
className="h-7"
145+
value={{
146+
from: getDate(moduleDetails.start_date),
147+
to: getDate(moduleDetails.target_date),
147148
}}
148-
placeholder={t("common.order_by.start_date")}
149-
icon={<CalendarClock className="h-3 w-3 flex-shrink-0" />}
150-
buttonVariant={moduleDetails.start_date ? "border-with-text" : "border-without-text"}
151-
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 rounded text-xs`}
152-
optionsClassName="z-10"
153-
disabled={isDisabled}
154-
showTooltip
155-
maxDate={getDate(moduleDetails.target_date)}
156-
/>
157-
<DateDropdown
158-
value={moduleDetails.target_date}
159-
onChange={(val) => {
149+
onSelect={(val) => {
160150
handleModuleDetailsChange({
161-
target_date: val ? renderFormattedPayloadDate(val) : null,
151+
start_date: val?.from ? renderFormattedPayloadDate(val.from) : null,
152+
target_date: val?.to ? renderFormattedPayloadDate(val.to) : null,
162153
});
163154
}}
164-
placeholder={t("common.order_by.due_date")}
165-
icon={<CalendarCheck2 className="h-3 w-3 flex-shrink-0" />}
166-
buttonVariant={moduleDetails.target_date ? "border-with-text" : "border-without-text"}
167-
buttonContainerClassName={`h-6 w-full flex ${isDisabled ? "cursor-not-allowed" : "cursor-pointer"} items-center gap-1.5 text-custom-text-300 rounded text-xs`}
168-
optionsClassName="z-10"
155+
placeholder={{
156+
from: t("start_date"),
157+
to: t("end_date"),
158+
}}
169159
disabled={isDisabled}
170-
showTooltip
171-
minDate={getDate(moduleDetails.start_date)}
160+
hideIcon={{ from: renderIcon ?? true, to: renderIcon }}
172161
/>
162+
173163
{moduleStatus && (
174164
<ModuleStatusDropdown
175165
isDisabled={isDisabled}

0 commit comments

Comments
 (0)