mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-02-05 21:20:07 +00:00
improve: replace long line of words with clipboard button (#95)
* improve: replace long line of words with clipboard button * change module path
This commit is contained in:
45
src/components/copy-button.tsx
Normal file
45
src/components/copy-button.tsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { ButtonProps } from "@/components/ui/button"
|
||||||
|
import { copyToClipboard } from "@/lib/utils"
|
||||||
|
import { forwardRef } from "react"
|
||||||
|
import { useState } from "react"
|
||||||
|
import { useTranslation } from "react-i18next"
|
||||||
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
import { IconButton } from "./xui/icon-button"
|
||||||
|
|
||||||
|
interface CopyButtonProps extends ButtonProps {
|
||||||
|
text?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>((props, ref) => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
const [copy, setCopy] = useState(false)
|
||||||
|
|
||||||
|
const switchState = async (text?: string) => {
|
||||||
|
if (!text) {
|
||||||
|
toast("Warning", {
|
||||||
|
description: t("EmptyText"),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!copy) {
|
||||||
|
setCopy(true)
|
||||||
|
await copyToClipboard(text)
|
||||||
|
setTimeout(() => {
|
||||||
|
setCopy(false)
|
||||||
|
}, 2 * 1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
{...props}
|
||||||
|
ref={ref}
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
icon={copy ? "check" : "clipboard"}
|
||||||
|
onClick={() => switchState(props.text)}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
})
|
||||||
@@ -23,7 +23,7 @@ export const NoteMenu = forwardRef<HTMLButtonElement, NoteMenuProps>((props, ref
|
|||||||
const switchState = async (text?: string) => {
|
const switchState = async (text?: string) => {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
toast("Warning", {
|
toast("Warning", {
|
||||||
description: "You didn't have any note.",
|
description: t("EmptyNote"),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -176,5 +176,7 @@
|
|||||||
"OnlineUser": "Online User",
|
"OnlineUser": "Online User",
|
||||||
"Total": "Total",
|
"Total": "Total",
|
||||||
"ConfirmBlock": "Confirm Block",
|
"ConfirmBlock": "Confirm Block",
|
||||||
"RejectPassword": "Reject Password Login"
|
"RejectPassword": "Reject Password Login",
|
||||||
|
"EmptyText": "Text is empty",
|
||||||
|
"EmptyNote": "You didn't have any note."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { deleteAlertRules } from "@/api/alert-rule"
|
|||||||
import { swrFetcher } from "@/api/api"
|
import { swrFetcher } from "@/api/api"
|
||||||
import { ActionButtonGroup } from "@/components/action-button-group"
|
import { ActionButtonGroup } from "@/components/action-button-group"
|
||||||
import { AlertRuleCard } from "@/components/alert-rule"
|
import { AlertRuleCard } from "@/components/alert-rule"
|
||||||
|
import { CopyButton } from "@/components/copy-button"
|
||||||
import { HeaderButtonGroup } from "@/components/header-button-group"
|
import { HeaderButtonGroup } from "@/components/header-button-group"
|
||||||
import { NotificationTab } from "@/components/notification-tab"
|
import { NotificationTab } from "@/components/notification-tab"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
@@ -87,11 +88,7 @@ export default function AlertRulePage() {
|
|||||||
header: t("Rules"),
|
header: t("Rules"),
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original
|
const s = row.original
|
||||||
return (
|
return <CopyButton text={JSON.stringify(s.rules)} />
|
||||||
<div className="max-w-48 whitespace-normal break-words">
|
|
||||||
{JSON.stringify(s.rules)}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { swrFetcher } from "@/api/api"
|
import { swrFetcher } from "@/api/api"
|
||||||
import { deleteCron, runCron } from "@/api/cron"
|
import { deleteCron, runCron } from "@/api/cron"
|
||||||
import { ActionButtonGroup } from "@/components/action-button-group"
|
import { ActionButtonGroup } from "@/components/action-button-group"
|
||||||
|
import { CopyButton } from "@/components/copy-button"
|
||||||
import { CronCard } from "@/components/cron"
|
import { CronCard } from "@/components/cron"
|
||||||
import { HeaderButtonGroup } from "@/components/header-button-group"
|
import { HeaderButtonGroup } from "@/components/header-button-group"
|
||||||
import { Checkbox } from "@/components/ui/checkbox"
|
import { Checkbox } from "@/components/ui/checkbox"
|
||||||
@@ -86,7 +87,7 @@ export default function CronPage() {
|
|||||||
accessorKey: "command",
|
accessorKey: "command",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original
|
const s = row.original
|
||||||
return <div className="max-w-48 whitespace-normal break-words">{s.command}</div>
|
return <CopyButton text={s.command} />
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { swrFetcher } from "@/api/api"
|
import { swrFetcher } from "@/api/api"
|
||||||
import { deleteNotification } from "@/api/notification"
|
import { deleteNotification } from "@/api/notification"
|
||||||
import { ActionButtonGroup } from "@/components/action-button-group"
|
import { ActionButtonGroup } from "@/components/action-button-group"
|
||||||
|
import { CopyButton } from "@/components/copy-button"
|
||||||
import { HeaderButtonGroup } from "@/components/header-button-group"
|
import { HeaderButtonGroup } from "@/components/header-button-group"
|
||||||
import { NotificationTab } from "@/components/notification-tab"
|
import { NotificationTab } from "@/components/notification-tab"
|
||||||
import { NotifierCard } from "@/components/notifier"
|
import { NotifierCard } from "@/components/notifier"
|
||||||
@@ -93,7 +94,7 @@ export default function NotificationPage() {
|
|||||||
accessorFn: (row) => row.url,
|
accessorFn: (row) => row.url,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const s = row.original
|
const s = row.original
|
||||||
return <div className="max-w-64 whitespace-normal break-words">{s.url}</div>
|
return <CopyButton text={s.url} />
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { swrFetcher } from "@/api/api"
|
import { swrFetcher } from "@/api/api"
|
||||||
import { deleteServer, forceUpdateServer } from "@/api/server"
|
import { deleteServer, forceUpdateServer } from "@/api/server"
|
||||||
import { ActionButtonGroup } from "@/components/action-button-group"
|
import { ActionButtonGroup } from "@/components/action-button-group"
|
||||||
|
import { CopyButton } from "@/components/copy-button"
|
||||||
import { HeaderButtonGroup } from "@/components/header-button-group"
|
import { HeaderButtonGroup } from "@/components/header-button-group"
|
||||||
import { InstallCommandsMenu } from "@/components/install-commands"
|
import { InstallCommandsMenu } from "@/components/install-commands"
|
||||||
import { NoteMenu } from "@/components/note-menu"
|
import { NoteMenu } from "@/components/note-menu"
|
||||||
@@ -121,6 +122,14 @@ export default function ServerPage() {
|
|||||||
return <NoteMenu note={{ private: s.note, public: s.public_note }} />
|
return <NoteMenu note={{ private: s.note, public: s.public_note }} />
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "uuid",
|
||||||
|
header: "UUID",
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const s = row.original
|
||||||
|
return <CopyButton text={s.uuid} />
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
header: t("Actions"),
|
header: t("Actions"),
|
||||||
|
|||||||
Reference in New Issue
Block a user