2023-10-30 07:29:50 +00:00
|
|
|
'use client'
|
|
|
|
|
|
2023-12-09 17:11:14 +00:00
|
|
|
import { useEffect, useState } from 'react'
|
|
|
|
|
|
2023-12-08 04:40:45 +00:00
|
|
|
import { graphql } from '@/lib/gql/generates'
|
|
|
|
|
import { useHealth } from '@/lib/hooks/use-health'
|
2023-12-10 04:16:31 +00:00
|
|
|
import { useAuthenticatedGraphQLQuery, useGraphQLForm } from '@/lib/tabby/gql'
|
|
|
|
|
import { Button } from '@/components/ui/button'
|
2023-12-09 17:11:14 +00:00
|
|
|
import {
|
|
|
|
|
CardContent,
|
|
|
|
|
CardFooter,
|
|
|
|
|
CardHeader,
|
|
|
|
|
CardTitle
|
|
|
|
|
} from '@/components/ui/card'
|
2023-12-10 04:16:31 +00:00
|
|
|
import { IconRotate } from '@/components/ui/icons'
|
2023-12-09 17:11:14 +00:00
|
|
|
import { Input } from '@/components/ui/input'
|
2023-12-10 04:16:31 +00:00
|
|
|
import { Label } from '@/components/ui/label'
|
2023-11-23 00:58:21 +00:00
|
|
|
import { CopyButton } from '@/components/copy-button'
|
2023-12-09 16:51:05 +00:00
|
|
|
import SlackDialog from '@/components/slack-dialog'
|
2023-10-30 07:29:50 +00:00
|
|
|
|
|
|
|
|
export default function Home() {
|
|
|
|
|
return (
|
2023-10-30 21:47:38 +00:00
|
|
|
<div className="p-4 lg:p-16">
|
2023-10-30 07:29:50 +00:00
|
|
|
<MainPanel />
|
2023-12-09 16:51:05 +00:00
|
|
|
<SlackDialog />
|
2023-10-30 07:29:50 +00:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-09 16:51:05 +00:00
|
|
|
const meQuery = graphql(/* GraphQL */ `
|
|
|
|
|
query MeQuery {
|
|
|
|
|
me {
|
|
|
|
|
authToken
|
|
|
|
|
}
|
2023-12-06 14:57:04 +00:00
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
|
2023-12-10 04:16:31 +00:00
|
|
|
const resetUserAuthTokenDocument = graphql(/* GraphQL */ `
|
|
|
|
|
mutation ResetUserAuthToken {
|
|
|
|
|
resetUserAuthToken
|
|
|
|
|
}
|
|
|
|
|
`)
|
|
|
|
|
|
2023-10-30 07:29:50 +00:00
|
|
|
function MainPanel() {
|
|
|
|
|
const { data: healthInfo } = useHealth()
|
2023-12-10 04:16:31 +00:00
|
|
|
const { data, mutate } = useAuthenticatedGraphQLQuery(meQuery)
|
2023-12-09 17:11:14 +00:00
|
|
|
const [origin, setOrigin] = useState('')
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setOrigin(new URL(window.location.href).origin)
|
|
|
|
|
}, [])
|
2023-10-30 07:29:50 +00:00
|
|
|
|
2023-12-10 04:16:31 +00:00
|
|
|
const { onSubmit: resetUserAuthToken } = useGraphQLForm(
|
|
|
|
|
resetUserAuthTokenDocument,
|
|
|
|
|
{
|
|
|
|
|
onSuccess: () => mutate()
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2023-12-09 16:51:05 +00:00
|
|
|
if (!healthInfo || !data) return
|
2023-10-30 07:29:50 +00:00
|
|
|
|
|
|
|
|
return (
|
2023-12-09 17:11:14 +00:00
|
|
|
<div>
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle>Getting Started</CardTitle>
|
|
|
|
|
</CardHeader>
|
2023-12-10 04:16:31 +00:00
|
|
|
<CardContent className="flex flex-col gap-4">
|
|
|
|
|
<Label>Endpoint URL</Label>
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<Input value={origin} className="max-w-[320px]" />
|
|
|
|
|
<CopyButton value={origin} />
|
2023-12-09 17:11:14 +00:00
|
|
|
</span>
|
|
|
|
|
|
2023-12-10 04:16:31 +00:00
|
|
|
<Label>Token</Label>
|
|
|
|
|
<span className="flex items-center gap-1">
|
|
|
|
|
<Input
|
|
|
|
|
className="max-w-[320px] font-mono text-red-600"
|
|
|
|
|
value={data.me.authToken}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
title="Rotate"
|
|
|
|
|
size="icon"
|
|
|
|
|
variant="hover-destructive"
|
|
|
|
|
onClick={() => resetUserAuthToken()}
|
|
|
|
|
>
|
|
|
|
|
<IconRotate />
|
|
|
|
|
</Button>
|
|
|
|
|
<CopyButton value={data.me.authToken} />
|
2023-12-09 17:11:14 +00:00
|
|
|
</span>
|
|
|
|
|
</CardContent>
|
|
|
|
|
<CardFooter>
|
|
|
|
|
<span>
|
|
|
|
|
Use informations above for IDE extensions / plugins configuration, see{' '}
|
|
|
|
|
<a
|
|
|
|
|
className="underline"
|
|
|
|
|
target="_blank"
|
|
|
|
|
href="https://tabby.tabbyml.com/docs/extensions/configurations#server"
|
|
|
|
|
>
|
|
|
|
|
documentation website
|
|
|
|
|
</a>{' '}
|
|
|
|
|
for details
|
|
|
|
|
</span>
|
|
|
|
|
</CardFooter>
|
2023-10-30 07:29:50 +00:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|