1- import { createFileRoute } from "@tanstack/react-router" ;
1+ import { createFileRoute , useRouter } from "@tanstack/react-router" ;
22import { Duration , Effect } from "effect" ;
33import { ApiClient } from "../../lib/api-client" ;
44import { WEBSITE_URL } from "../../lib/constants" ;
@@ -29,6 +29,7 @@ export const Route = createFileRoute("/$workspaceId/token")({
2929function RouteComponent ( ) {
3030 const { workspaceId } = Route . useParams ( ) ;
3131 const { tokens, token } = Route . useLoaderData ( ) ;
32+ const router = useRouter ( ) ;
3233
3334 const [ , onIssueToken , issuing ] = useActionEffect ( ( formData : FormData ) =>
3435 Effect . gen ( function * ( ) {
@@ -48,6 +49,21 @@ function RouteComponent() {
4849 } )
4950 ) ;
5051
52+ const [ , onRevoke , revoking ] = useActionEffect ( ( formData : FormData ) =>
53+ Effect . gen ( function * ( ) {
54+ const api = yield * ApiClient ;
55+
56+ const clientId = formData . get ( "clientId" ) as string ;
57+
58+ yield * api . client . syncAuth . revokeToken ( {
59+ path : { workspaceId, clientId } ,
60+ headers : { "x-api-key" : token } ,
61+ } ) ;
62+
63+ yield * Effect . promise ( ( ) => router . invalidate ( { sync : true } ) ) ;
64+ } )
65+ ) ;
66+
5167 return (
5268 < div >
5369 < h1 > Tokens</ h1 >
@@ -88,13 +104,26 @@ function RouteComponent() {
88104 : "N/A" }
89105 </ td >
90106 < td >
91- { token . revokedAt
92- ? new Date ( token . revokedAt ) . toLocaleDateString ( undefined , {
107+ { token . revokedAt ? (
108+ < span >
109+ { new Date ( token . revokedAt ) . toLocaleDateString ( undefined , {
93110 year : "numeric" ,
94111 month : "long" ,
95112 day : "numeric" ,
96- } )
97- : "N/A" }
113+ } ) }
114+ </ span >
115+ ) : (
116+ < form action = { onRevoke } >
117+ < input
118+ type = "hidden"
119+ name = "clientId"
120+ value = { token . clientId }
121+ />
122+ < button type = "submit" disabled = { revoking } >
123+ Revoke access
124+ </ button >
125+ </ form >
126+ ) }
98127 </ td >
99128 < td >
100129 < button
0 commit comments