Skip to content

Commit

Permalink
fix(EstimateDropdown): calculate estimate value
Browse files Browse the repository at this point in the history
  • Loading branch information
LamaEats authored and asabotovich committed Jun 27, 2024
1 parent 7c1b9c9 commit f592dc1
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/components/EstimateDropdown/EstimateDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { nullable } from '@taskany/bricks';
import { formateEstimate, getDateString } from '../../utils/dateTime';
import { DropdownPanel, Dropdown, DropdownTrigger } from '../Dropdown/Dropdown';
import { useLocale } from '../../hooks/useLocale';
import { DateType } from '../../types/date';
import { DateRange, DateType } from '../../types/date';
import { estimateYearTrigger, estimateQuarterTrigger, estimateStrictDateTrigger } from '../../utils/domObjects';

import { tr } from './EstimateDropdown.i18n';
import s from './EstimateDropdown.module.css';

interface Estimate {
range?: DateRange;
date: string;
type?: DateType;
}
Expand All @@ -31,10 +32,22 @@ interface EstimateDropdownProps {
onClose?: () => void;
}

const toEstimateState = (value: Estimate): EstimateState => ({
range: { end: new Date(value.date) },
type: value.type,
});
const toEstimateState = (value: Estimate): EstimateState => {
if (value.range) {
return {
range: {
end: new Date(value.range.end),
start: value.range.start != null ? new Date(value.range.start) : undefined,
},
type: value.type,
};
}

return {
range: { end: new Date(value.date), start: undefined },
type: value.type,
};
};

export const EstimateDropdown = ({ value, onChange, onClose, placement, ...props }: EstimateDropdownProps) => {
const locale = useLocale();
Expand Down

0 comments on commit f592dc1

Please sign in to comment.