diff --git a/src/components/CriteriaForm/CriteriaForm.i18n/en.json b/src/components/CriteriaForm/CriteriaForm.i18n/en.json index cafa32f28..1ceaed1f5 100644 --- a/src/components/CriteriaForm/CriteriaForm.i18n/en.json +++ b/src/components/CriteriaForm/CriteriaForm.i18n/en.json @@ -1,10 +1,13 @@ { - "Weight is required": "", - "Weight must be integer": "", "Weight": "No more than {upTo}", "Criteria or Goal": "", "Add achievement criteria": "", "Weight must be in range": "Weight must be between 1 and {upTo}", "Add": "", - "Title must be unique": "" + "Title must be unique": "", + "Press key to add criteria": "Press {key} to add the criteria", + "Enter goal name": "", + "Enter criteria": "", + "Search by goals": "", + "Weight must be integer": "" } diff --git a/src/components/CriteriaForm/CriteriaForm.i18n/ru.json b/src/components/CriteriaForm/CriteriaForm.i18n/ru.json index e672de3cc..d85e2485f 100644 --- a/src/components/CriteriaForm/CriteriaForm.i18n/ru.json +++ b/src/components/CriteriaForm/CriteriaForm.i18n/ru.json @@ -1,10 +1,13 @@ { - "Weight is required": "Вес обязателен", "Weight must be integer": "Вес должен быть числом", "Weight": "Не более {upTo}", "Criteria or Goal": "Критерий или цель", "Add achievement criteria": "Добавить критерий", "Weight must be in range": "Вес критерия должен быть от 1 до {upTo}", "Add": "Добавить", - "Title must be unique": "Критерий должен быть уникальным" + "Title must be unique": "Критерий должен быть уникальным", + "Press key to add criteria": "Нажмите {key}, чтобы добавить критерий", + "Enter goal name": "Введите название цели", + "Enter criteria": "Укажите критерий", + "Search by goals": "Поиск по целям" } diff --git a/src/components/CriteriaForm/CriteriaForm.tsx b/src/components/CriteriaForm/CriteriaForm.tsx index 6556dc741..c4b2b6e46 100644 --- a/src/components/CriteriaForm/CriteriaForm.tsx +++ b/src/components/CriteriaForm/CriteriaForm.tsx @@ -1,26 +1,18 @@ -import React, { useState, useEffect, useCallback, useReducer, useRef, forwardRef, ReactEventHandler } from 'react'; +import React, { useState, useCallback, forwardRef, ReactEventHandler, useRef } from 'react'; import styled from 'styled-components'; import { zodResolver } from '@hookform/resolvers/zod'; -import { - ComboBox, - Button, - GoalIcon, - nullable, - FormInput, - useClickOutside, - useKeyboard, - KeyCode, - PlusIcon, -} from '@taskany/bricks'; +import { Button, GoalIcon, FormInput, PlusIcon } from '@taskany/bricks'; import { gray7, gray8 } from '@taskany/colors'; import { Controller, UseFormSetError, useForm } from 'react-hook-form'; -import { Goal, State } from '@prisma/client'; +import { Goal } from '@prisma/client'; +import Popup from '@taskany/bricks/components/Popup'; import { InlineTrigger } from '../InlineTrigger'; import { AddCriteriaScheme, criteriaSchema } from '../../schema/criteria'; -import { Table, TableRow, TitleItem, ContentItem, Title, TextItem, TitleContainer } from '../Table'; -import { StateDot } from '../StateDot'; -import { trpc } from '../../utils/trpcClient'; +import { GoalSuggest } from '../GoalSuggest'; +import { InlineForm } from '../InlineForm'; +import { Keyboard } from '../Keyboard'; +import { Tip } from '../Tip'; import { tr } from './CriteriaForm.i18n'; @@ -33,13 +25,6 @@ const StyledInlineTrigger = styled(InlineTrigger)` line-height: 28px; `; -const StyledTableResults = styled(Table)` - position: relative; - grid-template-columns: 30px 210px 40px minmax(max-content, 120px); - width: fit-content; - z-index: 2; -`; - const StyledFormInput = styled(FormInput)` font-size: 14px; font-weight: normal; @@ -55,9 +40,7 @@ const StyledFormInput = styled(FormInput)` const StyledTableRow = styled.div` display: grid; - grid-template-columns: - minmax(calc(250px + 10px /* gap of sibling table */), 20%) - repeat(2, max-content); + grid-template-columns: 35px minmax(calc(240px), 20%) repeat(2, max-content); `; const StyledSubmitButton = styled(Button)` @@ -66,51 +49,6 @@ const StyledSubmitButton = styled(Button)` justify-content: center; `; -interface GoalSuggestItemProps { - title: string; - state?: State | null; - projectId: string; - focused: boolean; - onClick: () => void; -} - -const GoalSuggestItem: React.FC = ({ - onClick, - title, - projectId, - state, - focused, -}): React.ReactElement => { - const handleClick = useCallback>( - (event) => { - event.preventDefault(); - onClick(); - }, - [onClick], - ); - - return ( - - - - - - - {title} - - - - {nullable(state, (s) => ( - - ))} - - - {projectId} - - - ); -}; - interface WeightFieldProps { name: 'weight'; value?: string; @@ -179,59 +117,9 @@ interface CriteriaTitleFieldProps { export const CriteriaTitleField = forwardRef( ({ name, value = '', error, onSelect, onChange, titles = [], setError }, ref) => { - const [completionVisible, setCompletionVisibility] = useState(false); - const [[text, type], setQuery] = useState<[string, 'plain' | 'search']>([value, 'plain']); - - const results = trpc.goal.suggestions.useQuery( - { - input: text.slice(1), - limit: 5, - }, - { - enabled: type === 'search' && text.length > 2, - staleTime: 0, - cacheTime: 0, - }, - ); - - useEffect(() => { - if (value !== text) { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - setQuery(([_, prevType]) => { - return [value, prevType]; - }); - } - }, [value, text]); - - const handleInputChange = useCallback>( - (event) => { - const { value } = event.target; - - setQuery(() => { - const isSearchInput = value[0] === '#'; - - return [value, isSearchInput ? 'search' : 'plain']; - }); - - onChange(event); - - setCompletionVisibility(true); - }, - [onChange], - ); - - type GoalFromResults = NonNullable[number]; - - const handleSelectGoal = useCallback( - (item: GoalFromResults) => { - if (type === 'search') { - onSelect(item); - setQuery(['', 'plain']); - setCompletionVisibility(false); - } - }, - [onSelect, type], - ); + const [type, setType] = useState<'plain' | 'search'>('plain'); + const [popupVisible, setPopupVisible] = useState(false); + const btnRef = useRef(null); const onlyUniqueTitleHandler = useCallback>( (event) => { @@ -247,34 +135,53 @@ export const CriteriaTitleField = forwardRef ( + <> +