Files
xLog/src/components/site/EditButton.tsx
T

42 lines
1009 B
TypeScript

"use client"
import { useEffect, useState } from "react"
import { UniLink } from "~/components/ui/UniLink"
import { useUserRole } from "~/hooks/useUserRole"
import { SITE_URL } from "~/lib/env"
import { useTranslation } from "~/lib/i18n/client"
import { NoteType } from "~/lib/types"
export const EditButton = ({
handle,
noteId,
type,
}: {
handle?: string
noteId?: number
type?: NoteType
}) => {
const { t } = useTranslation("common")
const [showEdit, setShowEdit] = useState(false)
const userRole = useUserRole(handle)
useEffect(() => {
if (userRole.isSuccess && userRole.data) {
setShowEdit(true)
}
}, [userRole.isSuccess, userRole.data])
return (
<>
{showEdit && (
<UniLink
className="xlog-post-editor inline-flex items-center"
href={`${SITE_URL}/dashboard/${handle}/editor?id=${noteId}&type=${type}`}
>
<i className="icon-[mingcute--edit-line] mx-1" /> {t("Edit")}
</UniLink>
)}
</>
)
}