🏷️(app-desk) rename type TeamResponse to Team

Rename type TeamResponse to Team, the components
using this type don't need to know that the data
is coming from the API.
This commit is contained in:
Anthony LC
2024-02-13 12:20:07 +01:00
committed by Anthony LC
parent 3f7e5c88bc
commit 035a7a1fcc
6 changed files with 16 additions and 15 deletions

View File

@@ -10,7 +10,7 @@ export interface Access {
user: string;
}
export interface TeamResponse {
export interface Team {
id: string;
name: string;
accesses: Access[];

View File

@@ -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<TeamResponse> => {
export const getTeam = async ({ id }: TeamParams): Promise<Team> => {
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<TeamResponse>;
return response.json() as Promise<Team>;
};
export const KEY_TEAM = 'team';
export function useTeam(
param: TeamParams,
queryConfig?: UseQueryOptions<TeamResponse, APIError, TeamResponse>,
queryConfig?: UseQueryOptions<Team, APIError, Team>,
) {
return useQuery<TeamResponse, APIError, TeamResponse>({
return useQuery<Team, APIError, Team>({
queryKey: [KEY_TEAM, param],
queryFn: () => getTeam(param),
...queryConfig,

View File

@@ -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<TeamResponse>;
type TeamsResponse = APIList<Team>;
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<TeamsResponse>;
};

View File

@@ -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) => {

View File

@@ -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 (

View File

@@ -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) => {