Skip to content

Commit

Permalink
fix: goal form update state problem
Browse files Browse the repository at this point in the history
  • Loading branch information
asabotovich committed May 30, 2024
1 parent 180dc40 commit 7b89b94
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/components/EstimateDropdown/EstimateDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DatePicker, DatePickerYear, DatePickerQuarter, DatePickerStrict, Text } from '@taskany/bricks/harmony';
import { ComponentProps, useCallback, useMemo, useState } from 'react';
import { ComponentProps, useCallback, useEffect, useMemo, useState } from 'react';
import { nullable } from '@taskany/bricks';

import { formateEstimate, getDateString } from '../../utils/dateTime';
Expand Down Expand Up @@ -31,16 +31,18 @@ interface EstimateDropdownProps {
onClose?: () => void;
}

const toEstimateState = (value: Estimate): EstimateState => ({
range: { end: new Date(value.date) },
type: value.type,
});

export const EstimateDropdown = ({ value, onChange, onClose, placement, ...props }: EstimateDropdownProps) => {
const locale = useLocale();
const [estimate, setEstimate] = useState<EstimateState | undefined>(
value
? {
range: { end: new Date(value.date) },
type: value.type,
}
: undefined,
);
const [estimate, setEstimate] = useState<EstimateState | undefined>(value ? toEstimateState(value) : undefined);

useEffect(() => {
setEstimate(value ? toEstimateState(value) : undefined);
}, [value]);

const onChangeHandler = useCallback(
(value?: EstimateState) => {
Expand Down
11 changes: 11 additions & 0 deletions src/components/GoalForm/GoalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ export const GoalForm: React.FC<GoalFormProps> = ({
tags,
id,
},
defaultValues: {
title: '',
description: '',
owner: null,
parent: null,
state: null,
priority: null,
estimate: null,
tags: [],
id: null,
},
});

const parentWatcher = watch('parent');
Expand Down
1 change: 1 addition & 0 deletions trpc/queries/projectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const getProjectList = ({ activityId, role, limit = 5 }: GetProjectListPa
'Project.averageScore',
'Project.updatedAt',
'Project.activityId',
'Project.flowId',
jsonBuildObject({
id: ref('activity.id'),
user: fn.toJson('user'),
Expand Down

0 comments on commit 7b89b94

Please sign in to comment.