import { Button, createDisclosure, Flex, FormControl, FormLabel, Heading, HStack, Input, Modal, ModalBody, ModalCloseButton, ModalContent, ModalFooter, ModalHeader, ModalOverlay, Spacer, Text, Textarea, VStack, } from "@hope-ui/solid" import { createSignal, Show } from "solid-js" import { useFetch, useT } from "~/hooks" import { SSHPublicKey } from "~/types/sshkey" import { PEmptyResp, PPageResp } from "~/types" import { handleResp, r } from "~/utils" import { cols, PublicKey, PublicKeyCol } from "./PublicKey" import { createStore } from "solid-js/store" export interface PublicKeysProps { isMine: boolean userId: number } export interface SSHKeyAddReq { title: string key: string } export const PublicKeys = (props: PublicKeysProps) => { const t = useT() const [keys, setKeys] = createSignal([]) const [loading, get] = props.isMine ? useFetch((): PPageResp => r.get(`/me/sshkey/list`)) : useFetch( (): PPageResp => r.get(`/admin/user/sshkey/list?uid=${props.userId}`), ) const [addReq, setAddReq] = createStore({ title: "", key: "", }) const [addLoading, add] = useFetch( (): PEmptyResp => r.post(`/me/sshkey/add`, addReq), ) const { isOpen, onOpen, onClose } = createDisclosure() const refresh = async () => { const resp = await get() handleResp(resp, (data) => { setKeys(data.content) }) } refresh() const itemProps = (col: PublicKeyCol) => { return { fontWeight: "bold", fontSize: "$sm", color: "$neutral11", textAlign: col.textAlign as any, } } return ( {t(`users.ssh_keys.heading`)} {t(`users.ssh_keys.add_heading`)} {t(`users.ssh_keys.title`)} setAddReq("title", e.currentTarget.value)} /> {t(`users.ssh_keys.key`)}