From 035a7a1fcc86b906c2a3a783146fecbff53ba7ef Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 13 Feb 2024 12:20:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=B7=EF=B8=8F(app-desk)=20rename=20type?= =?UTF-8?q?=20TeamResponse=20to=20Team?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename type TeamResponse to Team, the components using this type don't need to know that the data is coming from the API. --- .../apps/desk/src/features/teams/api/types.tsx | 2 +- .../apps/desk/src/features/teams/api/useTeam.tsx | 10 +++++----- .../apps/desk/src/features/teams/api/useTeams.tsx | 5 +++-- .../desk/src/features/teams/components/PanelTeam.tsx | 4 ++-- .../desk/src/features/teams/components/PanelTeams.tsx | 6 +++--- .../desk/src/features/teams/components/TeamInfo.tsx | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/frontend/apps/desk/src/features/teams/api/types.tsx b/src/frontend/apps/desk/src/features/teams/api/types.tsx index b407a86..9274f36 100644 --- a/src/frontend/apps/desk/src/features/teams/api/types.tsx +++ b/src/frontend/apps/desk/src/features/teams/api/types.tsx @@ -10,7 +10,7 @@ export interface Access { user: string; } -export interface TeamResponse { +export interface Team { id: string; name: string; accesses: Access[]; diff --git a/src/frontend/apps/desk/src/features/teams/api/useTeam.tsx b/src/frontend/apps/desk/src/features/teams/api/useTeam.tsx index deb09ca..bff61d2 100644 --- a/src/frontend/apps/desk/src/features/teams/api/useTeam.tsx +++ b/src/frontend/apps/desk/src/features/teams/api/useTeam.tsx @@ -2,29 +2,29 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query'; import { APIError, errorCauses, fetchAPI } from '@/api'; -import { TeamResponse } from './types'; +import { Team } from './types'; export type TeamParams = { id: string; }; -export const getTeam = async ({ id }: TeamParams): Promise => { +export const getTeam = async ({ id }: TeamParams): Promise => { const response = await fetchAPI(`teams/${id}`); if (!response.ok) { throw new APIError('Failed to get the team', await errorCauses(response)); } - return response.json() as Promise; + return response.json() as Promise; }; export const KEY_TEAM = 'team'; export function useTeam( param: TeamParams, - queryConfig?: UseQueryOptions, + queryConfig?: UseQueryOptions, ) { - return useQuery({ + return useQuery({ queryKey: [KEY_TEAM, param], queryFn: () => getTeam(param), ...queryConfig, diff --git a/src/frontend/apps/desk/src/features/teams/api/useTeams.tsx b/src/frontend/apps/desk/src/features/teams/api/useTeams.tsx index 05d1fc7..973a4f3 100644 --- a/src/frontend/apps/desk/src/features/teams/api/useTeams.tsx +++ b/src/frontend/apps/desk/src/features/teams/api/useTeams.tsx @@ -7,7 +7,7 @@ import { import { APIError, APIList, errorCauses, fetchAPI } from '@/api'; -import { TeamResponse } from './types'; +import { Team } from './types'; export enum TeamsOrdering { BY_CREATED_ON = 'created_at', @@ -21,7 +21,7 @@ type TeamsAPIParams = TeamsParams & { page: number; }; -type TeamsResponse = APIList; +type TeamsResponse = APIList; export const getTeams = async ({ ordering, @@ -33,6 +33,7 @@ export const getTeams = async ({ if (!response.ok) { throw new APIError('Failed to get the teams', await errorCauses(response)); } + return response.json() as Promise; }; diff --git a/src/frontend/apps/desk/src/features/teams/components/PanelTeam.tsx b/src/frontend/apps/desk/src/features/teams/components/PanelTeam.tsx index 8f12bf9..da6d1c9 100644 --- a/src/frontend/apps/desk/src/features/teams/components/PanelTeam.tsx +++ b/src/frontend/apps/desk/src/features/teams/components/PanelTeam.tsx @@ -6,11 +6,11 @@ import IconGroup from '@/assets/icons/icon-group.svg'; import { Box, StyledLink, Text } from '@/components'; import { useCunninghamTheme } from '@/cunningham'; -import { TeamResponse } from '../api/types'; +import { Team } from '../api/types'; import IconNone from '../assets/icon-none.svg'; interface TeamProps { - team: TeamResponse; + team: Team; } export const PanelTeam = ({ team }: TeamProps) => { diff --git a/src/frontend/apps/desk/src/features/teams/components/PanelTeams.tsx b/src/frontend/apps/desk/src/features/teams/components/PanelTeams.tsx index 2f03c02..cd48bf9 100644 --- a/src/frontend/apps/desk/src/features/teams/components/PanelTeams.tsx +++ b/src/frontend/apps/desk/src/features/teams/components/PanelTeams.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'; import { Box, Text } from '@/components'; import { InfiniteScroll } from '@/components/InfiniteScroll'; -import { TeamResponse } from '../api/types'; +import { Team } from '../api/types'; import { useTeams } from '../api/useTeams'; import { useTeamStore } from '../store/useTeamsStore'; @@ -14,7 +14,7 @@ import { PanelTeam } from './PanelTeam'; interface PanelTeamsStateProps { isLoading: boolean; isError: boolean; - teams?: TeamResponse[]; + teams?: Team[]; } const PanelTeamsState = ({ @@ -76,7 +76,7 @@ export const PanelTeams = () => { const teams = useMemo(() => { return data?.pages.reduce((acc, page) => { return acc.concat(page.results); - }, [] as TeamResponse[]); + }, [] as Team[]); }, [data?.pages]); return ( diff --git a/src/frontend/apps/desk/src/features/teams/components/TeamInfo.tsx b/src/frontend/apps/desk/src/features/teams/components/TeamInfo.tsx index 20d49af..5407ca6 100644 --- a/src/frontend/apps/desk/src/features/teams/components/TeamInfo.tsx +++ b/src/frontend/apps/desk/src/features/teams/components/TeamInfo.tsx @@ -5,10 +5,10 @@ import IconGroup from '@/assets/icons/icon-group2.svg'; import { Box, Card, Text } from '@/components'; import { useCunninghamTheme } from '@/cunningham'; -import { TeamResponse } from '../api/types'; +import { Team } from '../api/types'; interface TeamInfoProps { - team: TeamResponse; + team: Team; } export const TeamInfo = ({ team }: TeamInfoProps) => {