diff --git a/src/components/Base/RoutineFormActionsProvider/routine-form-actions-provider.tsx b/src/components/Base/RoutineFormActionsProvider/routine-form-actions-provider.tsx index c906bdc73..af7cac7c1 100644 --- a/src/components/Base/RoutineFormActionsProvider/routine-form-actions-provider.tsx +++ b/src/components/Base/RoutineFormActionsProvider/routine-form-actions-provider.tsx @@ -1,7 +1,7 @@ import React, { createContext, ReactElement, useContext } from 'react' import { useRecoilState } from 'recoil' -import { useRoutineFormAnswers } from 'src/components/Routine/hooks/setRoutineFormAnswers/set-routine-form-answers' +import { useRoutineFormAnswers } from 'src/components/Routine/hooks/new/use-routine-form-answer' import { currentRoutinePropertiesAtom } from 'src/state/recoil/routine/current-routine-properties' import { retrospectiveRoutineIndexQuestionAtom } from 'src/state/recoil/routine/retrospective-showed-question' diff --git a/src/components/Page/Team/Highlights/highlights.tsx b/src/components/Page/Team/Highlights/highlights.tsx index 438a2657b..7b9cfd40c 100644 --- a/src/components/Page/Team/Highlights/highlights.tsx +++ b/src/components/Page/Team/Highlights/highlights.tsx @@ -49,9 +49,7 @@ export const Highlights = ({ teamId, isLoading }: HighlightsProperties) => { useEffect(() => { const getRoutinesHighlights = async (id: Team['id']) => { const { routines } = await servicesPromise - const { data: flags } = await routines.get( - `/answers/flags/${id}`, - ) + const flags = await routines.getFlags(id) setRoutineFlags(flags) } diff --git a/src/components/Page/Team/team.tsx b/src/components/Page/Team/team.tsx index c86f8ed4b..89721a630 100644 --- a/src/components/Page/Team/team.tsx +++ b/src/components/Page/Team/team.tsx @@ -81,6 +81,10 @@ const ExploreTeamPage = ({ teamId }: ExploreTeamPageProperties) => { if (tabs.has(routerTab) && routerTab !== activeTab) { setActiveTab(routerTab) } + + if (!routerTab) { + setActiveTab('okrs') + } // eslint-disable-next-line react-hooks/exhaustive-deps }, [router]) diff --git a/src/components/Routine/Drawer/Base/TeamRedirectPage/team-redirect-page.tsx b/src/components/Routine/Drawer/Base/TeamRedirectPage/team-redirect-page.tsx index ffe3c13d7..0c1c32790 100644 --- a/src/components/Routine/Drawer/Base/TeamRedirectPage/team-redirect-page.tsx +++ b/src/components/Routine/Drawer/Base/TeamRedirectPage/team-redirect-page.tsx @@ -1,4 +1,5 @@ import { Box, Button, Flex, Text } from '@chakra-ui/react' +import { useQueryClient } from '@tanstack/react-query' import React from 'react' import { useIntl } from 'react-intl' import { useRecoilState, useRecoilValue } from 'recoil' @@ -18,6 +19,12 @@ const TeamRedirectPage = () => { const userTeams = useRecoilValue(routineAnswersReturnedData) const intl = useIntl() const routineTabName = useRoutineTab() + const queryClient = useQueryClient() + + const redirectToTeam = (teamId: string) => { + setIsOpen(false) + queryClient.invalidateQueries({ queryKey: [`routines:getAnswer:${teamId}`] }) + } return ( setIsOpen(false)}> @@ -49,7 +56,7 @@ const TeamRedirectPage = () => { desc={intl.formatMessage(messages.title)} /> } - onClick={() => setIsOpen(false)} + onClick={() => redirectToTeam(team.id)} > {team.name} diff --git a/src/components/Routine/NotificationSettings/index.ts b/src/components/Routine/NotificationSettings/index.ts deleted file mode 100644 index 3849ba71f..000000000 --- a/src/components/Routine/NotificationSettings/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { NotificationSettingsModal } from './notification-settings' diff --git a/src/components/Routine/NotificationSettings/notification-settings.tsx b/src/components/Routine/NotificationSettings/index.tsx similarity index 100% rename from src/components/Routine/NotificationSettings/notification-settings.tsx rename to src/components/Routine/NotificationSettings/index.tsx diff --git a/src/components/Routine/Retrospective/wrapper.tsx b/src/components/Routine/Retrospective/wrapper.tsx index a04204ff9..f37d0a1e0 100644 --- a/src/components/Routine/Retrospective/wrapper.tsx +++ b/src/components/Routine/Retrospective/wrapper.tsx @@ -8,7 +8,7 @@ import { retrospectiveRoutineIndexQuestionAtom } from 'src/state/recoil/routine/ import RoutineDrawer from '../Drawer/Base/drawer' import RoutineFormQuestion from '../Drawer/Questions' import { FormQuestion } from '../Drawer/Questions/types' -import { useRoutineFormQuestions } from '../hooks/getRoutineForm/get-routine-form' +import { useRoutineFormQuestions } from '../hooks/new/use-get-routine-form' const updateDependQuestions = (questionId: string, value: string) => (question: FormQuestion) => { if (question.conditional?.dependsOn !== questionId) { diff --git a/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/LongTextAnswerCard/long-text.tsx b/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/LongTextAnswerCard/long-text.tsx index d397f391e..eb1fb7e97 100644 --- a/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/LongTextAnswerCard/long-text.tsx +++ b/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/LongTextAnswerCard/long-text.tsx @@ -2,10 +2,8 @@ import { Box, Skeleton, Text } from '@chakra-ui/react' import styled from '@emotion/styled' import React, { useEffect, useMemo, useRef, useState } from 'react' import { useIntl } from 'react-intl' -import { useRecoilValue } from 'recoil' import { StarIcon, TargetIcon, WriteIcon } from 'src/components/Icon' -import { answerDetailedAtom } from 'src/state/recoil/routine/answer' import { routineAnswer } from '../../../types' import { themeColor } from '../../../utils/contants' @@ -24,44 +22,41 @@ const StyledListItem = styled.span` ` const LongTextAnswerCard = ({ answerData, isLoaded }: LongTextAnswerCardProperties) => { - const reference = useRef(null) - const [width, setWidth] = useState(0) - const answerDetailed = useRecoilValue(answerDetailedAtom) const intl = useIntl() - const isDependentThat = answerDetailed.answers.find( - (answer) => answer.id === answerData.conditional?.dependsOn, - ) + const reference = useRef(null) + + const [width, setWidth] = useState(0) useEffect(() => { if (reference.current) setWidth(reference.current?.offsetWidth) - }, [answerDetailed]) + }, []) const answerValueThatDepends = useMemo(() => { - if (isDependentThat?.values) { - if (isDependentThat.type === 'value_range') { - const lastValue = isDependentThat.values[isDependentThat.values.length - 1] + if (answerData.dependsThat?.values) { + if (answerData.dependsThat?.type === 'value_range') { + const lastValue = answerData.dependsThat?.values[answerData.dependsThat?.values.length - 1] return Number(lastValue?.value) <= 3 } - if (isDependentThat.type === 'road_block') { - const lastValue = isDependentThat.values[isDependentThat.values.length - 2] + if (answerData.dependsThat?.type === 'road_block') { + const lastValue = answerData.dependsThat?.values[answerData.dependsThat?.values.length - 2] return lastValue?.value === 'y' } } - }, [isDependentThat]) + }, [answerData.dependsThat]) const justifyContent = useMemo(() => { if (answerValueThatDepends === false) return 'flex-start' - if (answerValueThatDepends === true || isDependentThat?.type === 'emoji_scale') + if (answerValueThatDepends === true || answerData.dependsThat?.type === 'emoji_scale') return 'flex-end' - if (isDependentThat?.type === 'emoji_scale' && width > 780) return 'flex-end' - }, [answerValueThatDepends, isDependentThat?.type, width]) + if (answerData.dependsThat?.type === 'emoji_scale' && width > 780) return 'flex-end' + }, [answerValueThatDepends, answerData.dependsThat?.type, width]) const paddingRight = useMemo(() => { - if (isDependentThat?.type === 'emoji_scale' && width > 756) return 0 + if (answerData.dependsThat?.type === 'emoji_scale' && width > 756) return 0 return 0 - }, [isDependentThat?.type, width]) + }, [answerData.dependsThat?.type, width]) const icons: Record = { '95b84e67-d5b6-4fcf-938a-b4c9897596cb': ( @@ -75,7 +70,7 @@ const LongTextAnswerCard = ({ answerData, isLoaded }: LongTextAnswerCardProperti ), } - const theme = themeColor(isDependentThat?.type ?? '') + const theme = themeColor(answerData.dependsThat?.type ?? '') return answerData.value ? ( diff --git a/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/UserAnswer/user-answer.tsx b/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/UserAnswer/user-answer.tsx index 66e74ac27..d4dc9a505 100644 --- a/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/UserAnswer/user-answer.tsx +++ b/src/components/Routine/RetrospectiveTab/Answers/AnswerContent/AnswerCards/UserAnswer/user-answer.tsx @@ -20,9 +20,10 @@ import messages from './messages' interface UserAnswerProperties { user: Partial + isLoaded: boolean } -export const UserAnswer = ({ user }: UserAnswerProperties) => { +export const UserAnswer = ({ user, isLoaded }: UserAnswerProperties) => { const [newGray600] = useToken('colors', ['new-gray.600']) const router = useRouter() const intl = useIntl() @@ -73,13 +74,13 @@ export const UserAnswer = ({ user }: UserAnswerProperties) => { - + { { - const answerDetailed = useRecoilValue(answerDetailedAtom) - const setComments = useSetRecoilState(commentsAtom) - +const AnswerContent = ({ teamId, answerId, answerDetailed, isLoaded }: AnswerContent) => { const intl = useIntl() + const router = useRouter() + const queryClient = useQueryClient() + + const [answerDetailedFormatted, setAnswerDetailedFormatted] = useState< + AnswerDetails | undefined + >() + + useEffect(() => { + setAnswerDetailedFormatted({ + ...answerDetailed, + answers: answerDetailed.answers.map((answer) => { + const dependsThat = answerDetailed.answers.find( + (answerDepend) => answerDepend.id === answer.conditional?.dependsOn, + ) + + return { + ...answer, + dependsThat, + } + }), + }) + }, [answerDetailed]) const userID = useRecoilValue(meAtom) + const setComments = useSetRecoilState(commentsAtom) - const { deleteRoutineAnswer } = useDeleteRoutineAnswer() + const { mutate: deleteAnswer } = useDeleteAnswerMutation() const hasPermission = userID === answerDetailed.user.id useEffect(() => { setComments([]) - // eslint-disable-next-line react-hooks/exhaustive-deps }, [answerId]) const menuOptions: Option[] = [ { value: intl.formatMessage(messages.firstMenuOption), - onSelect: async () => deleteRoutineAnswer(answerId), + onSelect: async () => { + deleteAnswer(answerId) + setTimeout( + async () => queryClient.invalidateQueries({ queryKey: [`routines:getAnswer:${teamId}`] }), + 5000, + ) + router.push( + { + query: { + ...router.query, + answerId: undefined, + }, + }, + undefined, + { shallow: true }, + ) + }, }, ] return ( <> - {answerDetailed.history.length > 0 && ( + {answerDetailedFormatted && answerDetailedFormatted.history.length > 0 && ( {hasPermission && ( { gap={1} /> )} - - {answerDetailed.answers.map((answer) => { + + {answerDetailedFormatted.answers.map((answer) => { return ( ) diff --git a/src/components/Routine/RetrospectiveTab/Answers/answer-row.tsx b/src/components/Routine/RetrospectiveTab/Answers/AnswerRow/index.tsx similarity index 97% rename from src/components/Routine/RetrospectiveTab/Answers/answer-row.tsx rename to src/components/Routine/RetrospectiveTab/Answers/AnswerRow/index.tsx index a3bcc134f..9aa61071e 100644 --- a/src/components/Routine/RetrospectiveTab/Answers/answer-row.tsx +++ b/src/components/Routine/RetrospectiveTab/Answers/AnswerRow/index.tsx @@ -11,9 +11,8 @@ import { EventType } from 'src/state/hooks/useEvent/event-type' import { useEvent } from 'src/state/hooks/useEvent/hook' import useRelativeDate from 'src/state/hooks/useRelativeDate' -import { AnswerSummary } from '../retrospective-tab-content' - -import messages from './messages' +import { AnswerSummary } from '../../types' +import messages from '../messages' interface AnswerRowComponentProperties { answer: AnswerSummary @@ -21,8 +20,10 @@ interface AnswerRowComponentProperties { const AnswerRowComponent = ({ answer }: AnswerRowComponentProperties) => { const intl = useIntl() - const { dispatch } = useEvent(EventType.ROUTINE_ANSWER_ROW_CLICK) const router = useRouter() + + const { dispatch } = useEvent(EventType.ROUTINE_ANSWER_ROW_CLICK) + const [formattedRelativeDate] = useRelativeDate(new Date(answer.timestamp ?? '')) const isTheDateToday = answer.timestamp ? isToday(new Date(answer.timestamp)) : undefined diff --git a/src/components/Routine/RetrospectiveTab/Answers/AnswerView/index.tsx b/src/components/Routine/RetrospectiveTab/Answers/AnswerView/index.tsx new file mode 100644 index 000000000..79f42dc99 --- /dev/null +++ b/src/components/Routine/RetrospectiveTab/Answers/AnswerView/index.tsx @@ -0,0 +1,89 @@ +import { Divider, Flex, Stack } from '@chakra-ui/react' +import { useRouter } from 'next/router' +import React, { useEffect } from 'react' +import { useIntl } from 'react-intl' + +import { getScrollableItem } from 'src/components/Base/ScrollableItem' +import { Team } from 'src/components/Team/types' + +import RoutineComments from '../../Comments' +import RoutineCommentsInput from '../../Comments/CommentInput/wrapper' +import RoutinesOverview, { RoutinesOverviewProperties } from '../../RoutinesOverview' +import AnswerContent from '../AnswerContent' +import { UserAnswer } from '../AnswerContent/AnswerCards/UserAnswer' + +import { useLogic } from './use-logic' + +interface AnswerContentProperties { + teamId: Team['id'] + after: RoutinesOverviewProperties['after'] + before: RoutinesOverviewProperties['before'] + week: RoutinesOverviewProperties['week'] + isLoaded?: boolean +} + +const ScrollableItem = getScrollableItem() + +const AnswerViewContent = ({ after, before, week, teamId, isLoaded }: AnswerContentProperties) => { + const router = useRouter() + const intl = useIntl() + + const { answerId, answerDetailed, isUserDetailedLoaded, comments } = useLogic({ + router, + intl, + }) + + const element = document.querySelector('#comments-list') + const scrollToShowLastComment = () => { + if (element) { + element.scrollIntoView({ behavior: 'smooth', block: 'end' }) + } + } + + useEffect(() => { + if (!isUserDetailedLoaded && element) { + element.scrollIntoView({ block: 'start', behavior: 'smooth' }) + } + }, [element, isUserDetailedLoaded]) + + return ( + + {answerId && answerDetailed && answerDetailed.answers.length > 0 && ( + <> + + + + + + )} + + {answerDetailed && answerId && answerDetailed.answers.length > 0 ? ( +
+ + + +
+ ) : ( + + )} +
+
+ ) +} + +export default AnswerViewContent diff --git a/src/components/Routine/RetrospectiveTab/Answers/AnswerView/use-logic.tsx b/src/components/Routine/RetrospectiveTab/Answers/AnswerView/use-logic.tsx new file mode 100644 index 000000000..608db4749 --- /dev/null +++ b/src/components/Routine/RetrospectiveTab/Answers/AnswerView/use-logic.tsx @@ -0,0 +1,89 @@ +/* eslint-disable import/order */ +import { NextRouter } from 'next/router' +import { useEffect, useState } from 'react' +import { IntlShape } from 'react-intl' +import { useSetRecoilState } from 'recoil' + +import { hasCallToActionOnAnswerDetails } from 'src/state/recoil/routine/has-call-to-action' + +import { useGetCommentsByEntityMutation } from '../../../hooks/getCommentsByEntity' +import { useGetAnswersDetailedMutation } from '../../../hooks/new/use-get-answer-detailed' +import { AnswerDetails } from '../types' + +import { COMMENT_DOMAIN } from '../utils/constants' + +interface useLogicProperties { + router: NextRouter + intl: IntlShape +} + +export const useLogic = ({ router, intl }: useLogicProperties) => { + // Local state + const [answerId, setAnswerId] = useState() + const [entity, setEntity] = useState() + const [answerDetailed, setAnswerDetailed] = useState() + + // Global state + const setHasCallToAction = useSetRecoilState(hasCallToActionOnAnswerDetails) + + // Hooks + const { data: comments } = useGetCommentsByEntityMutation({ + entity, + }) + + const { data: dataAnswerDetailed, isFetching: isUserDetailedLoaded } = + useGetAnswersDetailedMutation({ + answerId, + locale: intl.locale, + }) + + useEffect(() => { + const answerQuery = router?.query?.answerId + const answerId = Array.isArray(answerQuery) ? answerQuery[0] : answerQuery + setAnswerId(answerId) + setEntity(`${COMMENT_DOMAIN.routine}:${answerId ?? ''}`) + }, [router.query]) + + useEffect(() => { + if (dataAnswerDetailed && entity) { + setHasCallToAction(needCallToAction) + } + + if (dataAnswerDetailed) { + setAnswerDetailed(dataAnswerDetailed) + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [answerId, dataAnswerDetailed]) + + // Utils + const needCallToAction = () => { + if (!dataAnswerDetailed) return false + return dataAnswerDetailed.answers.some((answer) => { + if (answer.values) { + if ( + answer.type === 'value_range' && + Number(answer.values[answer.values.length - 1].value) <= 3 + ) + return true + + if ( + answer.type === 'emoji_scale' && + Number(answer.values[answer.values.length - 1].value) <= 2 + ) + return true + + if (answer.type === 'road_block' && answer.values[answer.values.length - 2].value === 'y') + return true + } + + return false + }) + } + + return { + answerId, + answerDetailed, + isUserDetailedLoaded, + comments, + } +} diff --git a/src/components/Routine/RetrospectiveTab/Answers/index.tsx b/src/components/Routine/RetrospectiveTab/Answers/index.tsx index 50ece5ec1..79a4efb85 100644 --- a/src/components/Routine/RetrospectiveTab/Answers/index.tsx +++ b/src/components/Routine/RetrospectiveTab/Answers/index.tsx @@ -1,292 +1,189 @@ import { Flex, Text, IconButton, GridItem, Divider, Box, Spinner } from '@chakra-ui/react' -import { format, add, sub, isBefore } from 'date-fns' +import { format, add, sub } from 'date-fns' import pt from 'date-fns/locale/pt' -import debounce from 'lodash/debounce' import { useRouter } from 'next/router' -import React, { memo, useCallback, useEffect, useMemo, useState } from 'react' +import React from 'react' import { useIntl } from 'react-intl' -import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil' import { Button } from 'src/components/Base/Button' import { getScrollableItem } from 'src/components/Base/ScrollableItem' import { SearchBar } from 'src/components/Base/SearchBar/wrapper' import { ArrowRight } from 'src/components/Icon' import BrilliantBellIcon from 'src/components/Icon/BrilliantBell' -import { useConnectionEdges } from 'src/state/hooks/useConnectionEdges/hook' -import { EventType } from 'src/state/hooks/useEvent/event-type' -import { useEvent } from 'src/state/hooks/useEvent/hook' -import { answerSummaryAtom } from 'src/state/recoil/routine/answer-summary' -import { isAnswerSummaryLoad } from 'src/state/recoil/routine/is-answers-summary-load' -import { routineDrawerOpened } from 'src/state/recoil/routine/opened-routine-drawer' -import { - getRoutineDateRangeDateFormat, - isNextWeekDisabled, - routineDatesRangeAtom, -} from 'src/state/recoil/routine/routine-dates-range' -import { answerSummaryLoadStateAtom } from 'src/state/recoil/routine/users-summary-load-state' -import { filteredUsersCompany } from 'src/state/recoil/team/users-company' -import meAtom from 'src/state/recoil/user/me' -import selectUser from 'src/state/recoil/user/selector' -import { useAnswerSummaryPagination } from '../../hooks/useAnswerSummaryPagination' -import { useFetchSummaryData } from '../../hooks/useFetchSummaryData' +import { AnswerSummary } from '../types' -import AnswerRowComponent from './answer-row' +import AnswerRowComponent from './AnswerRow' import messages from './messages' +import { useLogic } from './use-logic' interface AnswersComponentProperties { teamId: string - onGetNoCurrentAnswers: (after: Date, before: Date) => Promise after: Date before: Date week: number + dataAnswers: AnswerSummary[] | undefined + loadingAnswers: boolean + loadMore: boolean + usersSelected: string[] + setNewDate: (newDate: Date) => Promise handleViewMore?: () => void + setUsersSelected: React.Dispatch> } const ScrollableItem = getScrollableItem() -const SEARCH_CHARACTERS_LIMIT = 3 - -const AnswersComponent = memo( - ({ +const AnswersComponent = ({ + teamId, + after, + before, + week, + dataAnswers, + loadingAnswers, + loadMore, + usersSelected, + setNewDate, + handleViewMore, + setUsersSelected, +}: AnswersComponentProperties) => { + const intl = useIntl() + const router = useRouter() + + const { + search, + SEARCH_CHARACTERS_LIMIT, + showAnswerNowButton, + filteredAnswers, + loadingSearch, + dispatchChangeTimePeriod, + isNextWeekDisabled, + handleSearch, + setIsRoutineDrawerOpen, + dispatchAnswerNowFormClick, + } = useLogic({ teamId, - after, before, - week, - onGetNoCurrentAnswers, - handleViewMore, - }: AnswersComponentProperties) => { - const { dispatch: dispatchAnswerNowFormClick } = useEvent(EventType.ANSWER_NOW_FORM_CLICK) - const { dispatch: dispatchChangeTimePeriod } = useEvent(EventType.CHANGE_TIME_PERIOD_CLICK) - const [isAnswerSummaryLoading, setIsAnswerSummaryLoading] = useRecoilState( - answerSummaryLoadStateAtom, - ) - - const { fetchAnswers } = useFetchSummaryData() - const { limitedTeamUsers } = useAnswerSummaryPagination(teamId) - const teamUsers = useRecoilValue(filteredUsersCompany(teamId)) - const [answersSummary, setAnswersSummary] = useRecoilState(answerSummaryAtom) - const [search, setSearch] = useState('') - - const filteredAnswers = useMemo(() => { - const uniqueIds = new Set() - return answersSummary.filter((answer) => { - if ( - answer.name.toLowerCase().includes(search.toLocaleLowerCase()) && - !uniqueIds.has(answer.userId) - ) { - uniqueIds.add(answer.userId) - return true - } - - return false - }) - }, [answersSummary, search]) - - const intl = useIntl() - const router = useRouter() - - const userID = useRecoilValue(meAtom) - const [date, setDate] = useRecoilState(routineDatesRangeAtom) - const setIsAnswerSummaryLoaded = useSetRecoilState(isAnswerSummaryLoad) - const setIsRoutineDrawerOpen = useSetRecoilState(routineDrawerOpened) - const user = useRecoilValue(selectUser(userID)) - const [userTeams, updateTeams] = useConnectionEdges(user?.teams?.edges) - const [userCompanies, updateUserCompanies] = useConnectionEdges(user?.companies?.edges) - const userTeamIds = userTeams.map((team) => team.id) - const userCompanie = userCompanies[0]?.id - const isUserFromTheTeam = [...userTeamIds, userCompanie].includes(teamId) - - const haveUserAnswered = answersSummary.find( - (answer) => answer.userId === userID && answer.timestamp, - ) - const isActiveRoutine = isBefore(new Date(), before) - - const showAnswerNowButton = Boolean( - isUserFromTheTeam && isActiveRoutine && !haveUserAnswered && answersSummary.length > 0, - ) - - const setNewDate = useCallback( - async (newDate: Date) => { - const dateRange = getRoutineDateRangeDateFormat(newDate) - setDate(dateRange) - - router.push( - { - query: { - ...(router?.query ?? {}), - before: format(dateRange.before, 'dd/MM/yyyy'), - after: format(dateRange.after, 'dd/MM/yyyy'), - }, - }, - undefined, - { shallow: true }, - ) - - await onGetNoCurrentAnswers(dateRange.after, dateRange.before) - }, - [onGetNoCurrentAnswers, router, setDate], - ) - - const performDebounced = useCallback( - async (searchTerm: string) => { - const usersSearched = teamUsers.filter((user) => - user.fullName.toLocaleLowerCase().includes(searchTerm.toLocaleLowerCase()), - ) - - const teamUsersIds = usersSearched.map((user) => user.id) - - const usersAreBeingRequestedForTheFirstTime = !teamUsersIds.some((userId) => { - return answersSummary.some((user) => user.userId === userId) - }) - - if (usersAreBeingRequestedForTheFirstTime && teamUsersIds.length > 0) { - const searchDataFormatted = await fetchAnswers({ teamId, after, before, teamUsersIds }) - - if (searchDataFormatted) - setAnswersSummary((previousAnswers) => [...previousAnswers, ...searchDataFormatted]) - } - - setIsAnswerSummaryLoading(false) - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [after, before, teamUsers], - ) - - const debouncedSearch = debounce(performDebounced, 2500) - - const handleSearch = useCallback( - async (value: string) => { - if (value.length >= SEARCH_CHARACTERS_LIMIT) { - setSearch(value) - setIsAnswerSummaryLoading(true) - await debouncedSearch(value) - } else { - setIsAnswerSummaryLoading(false) - setSearch('') - } - }, - [debouncedSearch, setIsAnswerSummaryLoading], - ) - - useEffect(() => { - updateTeams(user?.teams?.edges) - updateUserCompanies(user?.companies?.edges) - }, [updateTeams, updateUserCompanies, user?.companies?.edges, user?.teams]) - - return ( - - - - } - onClick={() => { - setIsAnswerSummaryLoaded(false) - setNewDate(sub(date.after, { weeks: 1 })) - dispatchChangeTimePeriod({}) - }} - /> - + {/* Seletor de semana */} + + + } + onClick={() => { + setNewDate(sub(after, { weeks: 1 })) + dispatchChangeTimePeriod({}) + }} + /> + + {intl.formatMessage(messages.weekText)} {week} ( + {format(new Date(after), 'dd/MMM', { locale: pt })} a{' '} + {format(new Date(before), 'dd/MMM', { locale: pt })}) + + + } + onClick={() => { + setNewDate(add(after, { weeks: 1 })) + dispatchChangeTimePeriod({}) + }} + /> + + + + + {/* Pesquisa de usuário */} + + + + + {/* Lista de respostas por usuários */} + + {filteredAnswers.map((answer) => ( + + ))} + {(loadingAnswers || loadingSearch) && ( + + + + )} + {!loadingAnswers && loadMore && ( +