Skip to content

Commit 9a2f677

Browse files
authored
ref(tsc): user-reports endpoint to apiOptions (#112572)
1 parent 19943b9 commit 9a2f677

File tree

4 files changed

+40
-41
lines changed

4 files changed

+40
-41
lines changed

static/app/utils/useLocation.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import type {Location, Query} from 'history';
44

55
import {location6ToLocation3} from './reactRouter6Compat/location';
66

7-
type DefaultQuery<T = string> = Record<string, T | T[] | null | undefined>;
7+
export type QueryParamValue<T = string> = T | T[] | null | undefined;
8+
type DefaultQuery<T = string> = Record<string, QueryParamValue<T>>;
89

910
export function useLocation<Q extends Query = DefaultQuery>(): Location<Q> {
1011
const router6Location = useReactRouter6Location();

static/app/views/issueDetails/groupUserFeedback.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import {Fragment} from 'react';
22
import styled from '@emotion/styled';
3+
import {useQuery} from '@tanstack/react-query';
34

45
import {EventUserFeedback} from 'sentry/components/events/userFeedback';
56
import * as Layout from 'sentry/components/layouts/thirds';
67
import {LoadingError} from 'sentry/components/loadingError';
78
import {LoadingIndicator} from 'sentry/components/loadingIndicator';
89
import {Pagination} from 'sentry/components/pagination';
910
import {t} from 'sentry/locale';
11+
import {selectJsonWithHeaders} from 'sentry/utils/api/apiOptions';
1012
import {useLocation} from 'sentry/utils/useLocation';
1113
import {useOrganization} from 'sentry/utils/useOrganization';
1214
import {useParams} from 'sentry/utils/useParams';
1315
import {FeedbackEmptyState} from 'sentry/views/feedback/feedbackEmptyState';
16+
import {groupUserFeedbackApiOptions} from 'sentry/views/issueDetails/groupUserFeedbackApiOptions';
1417
import {useGroup} from 'sentry/views/issueDetails/useGroup';
15-
import {useGroupUserFeedback} from 'sentry/views/issueDetails/useGroupUserFeedback';
1618

1719
function GroupUserFeedback() {
1820
const organization = useOrganization();
@@ -28,17 +30,14 @@ function GroupUserFeedback() {
2830
groupId: params.groupId,
2931
});
3032

31-
const {
32-
data: reportList,
33-
isPending,
34-
isError,
35-
refetch,
36-
getResponseHeader,
37-
} = useGroupUserFeedback({
38-
groupId: params.groupId,
39-
query: {
40-
cursor: location.query.cursor as string | undefined,
41-
},
33+
const {data, isPending, isError, refetch} = useQuery({
34+
...groupUserFeedbackApiOptions(organization, {
35+
groupId: params.groupId,
36+
query: {
37+
cursor: location.query.cursor,
38+
},
39+
}),
40+
select: selectJsonWithHeaders,
4241
});
4342

4443
if (isError || isErrorGroup) {
@@ -62,7 +61,8 @@ function GroupUserFeedback() {
6261
);
6362
}
6463

65-
const pageLinks = getResponseHeader?.('Link');
64+
const reportList = data?.json ?? [];
65+
const pageLinks = data?.headers.Link;
6666
const hasUserFeedback = group.project.hasUserReports;
6767

6868
return (
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type {UserReport} from 'sentry/types/group';
2+
import type {Organization} from 'sentry/types/organization';
3+
import {apiOptions} from 'sentry/utils/api/apiOptions';
4+
import type {QueryParamValue} from 'sentry/utils/useLocation';
5+
6+
interface GroupUserFeedbackProps {
7+
groupId: string;
8+
query: {
9+
cursor?: QueryParamValue;
10+
};
11+
}
12+
13+
export function groupUserFeedbackApiOptions(
14+
organization: Organization,
15+
{groupId, query}: GroupUserFeedbackProps
16+
) {
17+
return apiOptions.as<UserReport[]>()(
18+
'/organizations/$organizationIdOrSlug/issues/$issueId/user-reports/',
19+
{
20+
path: {organizationIdOrSlug: organization.slug, issueId: groupId},
21+
query,
22+
staleTime: 0,
23+
}
24+
);
25+
}

static/app/views/issueDetails/useGroupUserFeedback.tsx

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)