🏷️(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:
@@ -10,7 +10,7 @@ export interface Access {
|
|||||||
user: string;
|
user: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TeamResponse {
|
export interface Team {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
accesses: Access[];
|
accesses: Access[];
|
||||||
|
|||||||
@@ -2,29 +2,29 @@ import { UseQueryOptions, useQuery } from '@tanstack/react-query';
|
|||||||
|
|
||||||
import { APIError, errorCauses, fetchAPI } from '@/api';
|
import { APIError, errorCauses, fetchAPI } from '@/api';
|
||||||
|
|
||||||
import { TeamResponse } from './types';
|
import { Team } from './types';
|
||||||
|
|
||||||
export type TeamParams = {
|
export type TeamParams = {
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTeam = async ({ id }: TeamParams): Promise<TeamResponse> => {
|
export const getTeam = async ({ id }: TeamParams): Promise<Team> => {
|
||||||
const response = await fetchAPI(`teams/${id}`);
|
const response = await fetchAPI(`teams/${id}`);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new APIError('Failed to get the team', await errorCauses(response));
|
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 const KEY_TEAM = 'team';
|
||||||
|
|
||||||
export function useTeam(
|
export function useTeam(
|
||||||
param: TeamParams,
|
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],
|
queryKey: [KEY_TEAM, param],
|
||||||
queryFn: () => getTeam(param),
|
queryFn: () => getTeam(param),
|
||||||
...queryConfig,
|
...queryConfig,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
|
|
||||||
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
|
import { APIError, APIList, errorCauses, fetchAPI } from '@/api';
|
||||||
|
|
||||||
import { TeamResponse } from './types';
|
import { Team } from './types';
|
||||||
|
|
||||||
export enum TeamsOrdering {
|
export enum TeamsOrdering {
|
||||||
BY_CREATED_ON = 'created_at',
|
BY_CREATED_ON = 'created_at',
|
||||||
@@ -21,7 +21,7 @@ type TeamsAPIParams = TeamsParams & {
|
|||||||
page: number;
|
page: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TeamsResponse = APIList<TeamResponse>;
|
type TeamsResponse = APIList<Team>;
|
||||||
|
|
||||||
export const getTeams = async ({
|
export const getTeams = async ({
|
||||||
ordering,
|
ordering,
|
||||||
@@ -33,6 +33,7 @@ export const getTeams = async ({
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new APIError('Failed to get the teams', await errorCauses(response));
|
throw new APIError('Failed to get the teams', await errorCauses(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json() as Promise<TeamsResponse>;
|
return response.json() as Promise<TeamsResponse>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ import IconGroup from '@/assets/icons/icon-group.svg';
|
|||||||
import { Box, StyledLink, Text } from '@/components';
|
import { Box, StyledLink, Text } from '@/components';
|
||||||
import { useCunninghamTheme } from '@/cunningham';
|
import { useCunninghamTheme } from '@/cunningham';
|
||||||
|
|
||||||
import { TeamResponse } from '../api/types';
|
import { Team } from '../api/types';
|
||||||
import IconNone from '../assets/icon-none.svg';
|
import IconNone from '../assets/icon-none.svg';
|
||||||
|
|
||||||
interface TeamProps {
|
interface TeamProps {
|
||||||
team: TeamResponse;
|
team: Team;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PanelTeam = ({ team }: TeamProps) => {
|
export const PanelTeam = ({ team }: TeamProps) => {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { Box, Text } from '@/components';
|
import { Box, Text } from '@/components';
|
||||||
import { InfiniteScroll } from '@/components/InfiniteScroll';
|
import { InfiniteScroll } from '@/components/InfiniteScroll';
|
||||||
|
|
||||||
import { TeamResponse } from '../api/types';
|
import { Team } from '../api/types';
|
||||||
import { useTeams } from '../api/useTeams';
|
import { useTeams } from '../api/useTeams';
|
||||||
import { useTeamStore } from '../store/useTeamsStore';
|
import { useTeamStore } from '../store/useTeamsStore';
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ import { PanelTeam } from './PanelTeam';
|
|||||||
interface PanelTeamsStateProps {
|
interface PanelTeamsStateProps {
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
isError: boolean;
|
isError: boolean;
|
||||||
teams?: TeamResponse[];
|
teams?: Team[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const PanelTeamsState = ({
|
const PanelTeamsState = ({
|
||||||
@@ -76,7 +76,7 @@ export const PanelTeams = () => {
|
|||||||
const teams = useMemo(() => {
|
const teams = useMemo(() => {
|
||||||
return data?.pages.reduce((acc, page) => {
|
return data?.pages.reduce((acc, page) => {
|
||||||
return acc.concat(page.results);
|
return acc.concat(page.results);
|
||||||
}, [] as TeamResponse[]);
|
}, [] as Team[]);
|
||||||
}, [data?.pages]);
|
}, [data?.pages]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import IconGroup from '@/assets/icons/icon-group2.svg';
|
|||||||
import { Box, Card, Text } from '@/components';
|
import { Box, Card, Text } from '@/components';
|
||||||
import { useCunninghamTheme } from '@/cunningham';
|
import { useCunninghamTheme } from '@/cunningham';
|
||||||
|
|
||||||
import { TeamResponse } from '../api/types';
|
import { Team } from '../api/types';
|
||||||
|
|
||||||
interface TeamInfoProps {
|
interface TeamInfoProps {
|
||||||
team: TeamResponse;
|
team: Team;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TeamInfo = ({ team }: TeamInfoProps) => {
|
export const TeamInfo = ({ team }: TeamInfoProps) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user