44// SPDX-License-Identifier: AGPL-3.0-only
55// Please see LICENSE in the repository root for full details.
66
7+ import { useMutation , useQueryClient } from "@tanstack/react-query" ;
78import { parseISO } from "date-fns" ;
89import { useTranslation } from "react-i18next" ;
9- import { useMutation } from "urql" ;
10-
1110import { type FragmentType , graphql , useFragment } from "../gql" ;
12- import { DeviceType } from "../gql/graphql" ;
13-
11+ import { graphqlClient } from "../graphql" ;
1412import { browserLogoUri } from "./BrowserSession" ;
1513import DateTime from "./DateTime" ;
1614import EndSessionButton from "./Session/EndSessionButton" ;
@@ -44,7 +42,6 @@ export const END_SESSION_MUTATION = graphql(/* GraphQL */ `
4442 status
4543 compatSession {
4644 id
47- finishedAt
4845 }
4946 }
5047 }
@@ -54,7 +51,7 @@ export const simplifyUrl = (url: string): string => {
5451 let parsed : URL ;
5552 try {
5653 parsed = new URL ( url ) ;
57- } catch ( e ) {
54+ } catch ( _e ) {
5855 // Not a valid URL, return the original
5956 return url ;
6057 }
@@ -76,10 +73,21 @@ const CompatSession: React.FC<{
7673} > = ( { session } ) => {
7774 const { t } = useTranslation ( ) ;
7875 const data = useFragment ( FRAGMENT , session ) ;
79- const [ , endCompatSession ] = useMutation ( END_SESSION_MUTATION ) ;
76+ const queryClient = useQueryClient ( ) ;
77+ const endSession = useMutation ( {
78+ mutationFn : ( id : string ) =>
79+ graphqlClient . request ( END_SESSION_MUTATION , { id } ) ,
80+ onSuccess : ( data ) => {
81+ queryClient . invalidateQueries ( { queryKey : [ "sessionsOverview" ] } ) ;
82+ queryClient . invalidateQueries ( { queryKey : [ "appSessionList" ] } ) ;
83+ queryClient . invalidateQueries ( {
84+ queryKey : [ "sessionDetail" , data . endCompatSession . compatSession ?. id ] ,
85+ } ) ;
86+ } ,
87+ } ) ;
8088
8189 const onSessionEnd = async ( ) : Promise < void > => {
82- await endCompatSession ( { id : data . id } ) ;
90+ await endSession . mutateAsync ( data . id ) ;
8391 } ;
8492
8593 const clientName = data . ssoLogin ?. redirectUri
0 commit comments