-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from napse-invest/feature/server
Feature/server
- Loading branch information
Showing
27 changed files
with
1,167 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { request } from 'api/request' | ||
import { AxiosResponse } from 'axios' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
export interface Key { | ||
name: string | ||
prefix: string | ||
permissions: string[] | ||
is_master_key: boolean | ||
revoked: boolean | ||
description: string | ||
} | ||
|
||
export async function getKey( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
id: string | ||
): Promise<AxiosResponse<Key>> { | ||
const response = await request(searchParams, 'GET', `/api/key/${id}/`) | ||
return response as AxiosResponse<Key> | ||
} | ||
export async function listKey( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
space: string | null = null | ||
): Promise<AxiosResponse<Key[]>> { | ||
const response = await request( | ||
searchParams, | ||
'GET', | ||
space ? `/api/key/?space=${space}` : '/api/key/' | ||
) | ||
return response as AxiosResponse<Key[]> | ||
} | ||
|
||
export async function createKey( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
name: string, | ||
description: string | ||
): Promise<AxiosResponse<{ key: string }>> { | ||
const response = await request(searchParams, 'POST', '/api/key/', { | ||
name, | ||
description | ||
}) | ||
return response as AxiosResponse<{ key: string }> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,29 @@ | ||
import { getServer } from '@/lib/localStorage' | ||
import axios from 'axios' | ||
import axios, { AxiosHeaders } from 'axios' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
export function request( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
method: string, | ||
url: string, | ||
...args: any[] | ||
data: Object | null = null, | ||
headers: AxiosHeaders | null = null | ||
) { | ||
const serverID = searchParams.get('server') | ||
if (!serverID) { | ||
throw new Error('No server selected') | ||
} | ||
const serverUrl = getServer(serverID).url | ||
const server = getServer(serverID) | ||
const serverUrl = server.url | ||
const token = server.token | ||
return axios({ | ||
method: method, | ||
url: url, | ||
baseURL: serverUrl, | ||
...args | ||
headers: { | ||
Authorization: 'Api-Key ' + token, | ||
...headers | ||
}, | ||
data: data || {} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { request } from 'api/request' | ||
import { AxiosResponse } from 'axios' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
export interface NapseSpace { | ||
name: string | ||
uuid: string | ||
value: number | ||
fleet_count: number | ||
exchange_account: string | ||
delta?: number | ||
} | ||
|
||
export async function listSpace( | ||
searchParams: ReturnType<typeof useSearchParams> | ||
): Promise<AxiosResponse<NapseSpace[]>> { | ||
const response = await request(searchParams, 'GET', '/api/space/') | ||
return response as AxiosResponse<NapseSpace[]> | ||
} | ||
|
||
export async function getSpace( | ||
searchParams: ReturnType<typeof useSearchParams>, | ||
id: string | ||
): Promise<AxiosResponse<NapseSpace>> { | ||
const response = await request(searchParams, 'GET', `/api/space/${id}/`) | ||
return response as AxiosResponse<NapseSpace> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { CheckIcon, CopyIcon } from '@radix-ui/react-icons' | ||
import * as React from 'react' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { cn } from '@/lib/utils' | ||
|
||
interface CopyButtonProps extends React.HTMLAttributes<HTMLButtonElement> { | ||
value: string | ||
src?: string | ||
} | ||
|
||
export async function copyToClipboardWithMeta(value: string, event?: Event) { | ||
navigator.clipboard.writeText(value) | ||
} | ||
|
||
export default function CopyButton({ | ||
value, | ||
className, | ||
src, | ||
...props | ||
}: CopyButtonProps) { | ||
const [hasCopied, setHasCopied] = React.useState(false) | ||
|
||
React.useEffect(() => { | ||
setTimeout(() => { | ||
setHasCopied(false) | ||
}, 2000) | ||
}, [hasCopied]) | ||
|
||
return ( | ||
<Button | ||
size="icon" | ||
variant="ghost" | ||
className={cn( | ||
'bg-foreground relative z-10 h-6 w-6 text-zinc-50', | ||
className | ||
)} | ||
onClick={() => { | ||
copyToClipboardWithMeta(value) | ||
setHasCopied(true) | ||
}} | ||
{...props} | ||
> | ||
<span className="sr-only">Copy</span> | ||
{hasCopied ? ( | ||
<CheckIcon className="h-3 w-3" /> | ||
) : ( | ||
<CopyIcon className="h-3 w-3" /> | ||
)} | ||
</Button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Button } from '@/components/ui/button' | ||
import { Settings } from 'lucide-react' | ||
import { useRouter } from 'next/router' | ||
|
||
export function SettingsButton(): JSX.Element { | ||
const router = useRouter() | ||
|
||
return ( | ||
<Button | ||
variant="outline" | ||
size="icon" | ||
onClick={() => { | ||
router.push('/settings').catch((err) => { | ||
console.error(err) | ||
}) | ||
}} | ||
> | ||
<Settings className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all " /> | ||
</Button> | ||
) | ||
} |
Oops, something went wrong.