feat: operators setting
This commit is contained in:
@@ -1,117 +1,87 @@
|
||||
import { useEffect, useState } from "react"
|
||||
import {
|
||||
offset,
|
||||
flip,
|
||||
shift,
|
||||
autoUpdate,
|
||||
useFloating,
|
||||
useInteractions,
|
||||
useHover,
|
||||
useFocus,
|
||||
useRole,
|
||||
useDismiss,
|
||||
} from "@floating-ui/react-dom-interactions"
|
||||
import { Avatar } from "~/components/ui/Avatar"
|
||||
import dayjs, { formatToISO } from "~/lib/date"
|
||||
import { FollowingButton } from "~/components/common/FollowingButton"
|
||||
import { FollowingCount } from "~/components/common/FollowingCount"
|
||||
import * as siteModel from "~/models/site.model"
|
||||
import type { Profile } from "~/lib/types"
|
||||
import clsx from "clsx"
|
||||
|
||||
export const CharacterCard: React.FC<{
|
||||
siteId?: string
|
||||
children: JSX.Element
|
||||
}> = ({ siteId, children }) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const { x, y, reference, floating, strategy, context } = useFloating({
|
||||
placement: "bottom-start",
|
||||
open,
|
||||
onOpenChange: setOpen,
|
||||
middleware: [offset(5), flip(), shift({ padding: 8 })],
|
||||
whileElementsMounted: autoUpdate,
|
||||
})
|
||||
|
||||
const { getReferenceProps, getFloatingProps } = useInteractions([
|
||||
useHover(context, { delay: { close: 200, open: 200 } }),
|
||||
useFocus(context),
|
||||
useRole(context, { role: "tooltip" }),
|
||||
useDismiss(context),
|
||||
])
|
||||
|
||||
const [buttonLoading, setButtonLoading] = useState(false)
|
||||
address?: string
|
||||
open?: boolean
|
||||
setButtonLoading?: (loading: boolean) => void
|
||||
hideFollowButton?: boolean
|
||||
style?: "flat" | "normal"
|
||||
}> = ({ siteId, address, open, setButtonLoading, hideFollowButton, style }) => {
|
||||
const [firstOpen, setFirstOpen] = useState("")
|
||||
const [site, setSite] = useState<Profile>()
|
||||
|
||||
useEffect(() => {
|
||||
if (open && siteId && (firstOpen !== siteId || !site)) {
|
||||
setFirstOpen(siteId)
|
||||
siteModel.getSite(siteId).then((site) => setSite(site))
|
||||
if (open && (firstOpen !== (siteId || address) || !site)) {
|
||||
if (siteId || address) {
|
||||
setFirstOpen(siteId || address || "")
|
||||
if (siteId) {
|
||||
siteModel.getSite(siteId).then((site) => setSite(site))
|
||||
} else if (address) {
|
||||
siteModel.getUserSites(address).then((sites) => setSite(sites?.[0]))
|
||||
}
|
||||
} else {
|
||||
setSite(undefined)
|
||||
}
|
||||
}
|
||||
}, [open, firstOpen, siteId, site])
|
||||
}, [open, firstOpen, siteId, address, site])
|
||||
|
||||
return (
|
||||
<span {...getReferenceProps({ ref: reference, ...children.props })}>
|
||||
{children}
|
||||
{(open || buttonLoading) && (
|
||||
<span
|
||||
{...getFloatingProps({
|
||||
ref: floating,
|
||||
className:
|
||||
"border-gray-100 rounded-lg p-4 bg-white z-10 space-y-2 text-sm w-80 shadow-xl block",
|
||||
style: {
|
||||
position: strategy,
|
||||
top: y ?? "",
|
||||
left: x ?? "",
|
||||
},
|
||||
})}
|
||||
>
|
||||
{site ? (
|
||||
<>
|
||||
<span className="flex items-center justify-between">
|
||||
<Avatar
|
||||
images={site?.avatars || []}
|
||||
name={site?.name}
|
||||
size={45}
|
||||
/>
|
||||
<FollowingButton
|
||||
siteId={siteId}
|
||||
size="sm"
|
||||
loadingStatusChange={(status) => setButtonLoading(status)}
|
||||
/>
|
||||
</span>
|
||||
<span className="block">
|
||||
<span className="font-bold text-base">{site?.name}</span>
|
||||
<span className="ml-1 text-gray-600">@{siteId}</span>
|
||||
</span>
|
||||
{site?.description && (
|
||||
<span
|
||||
className="block text-gray-600"
|
||||
dangerouslySetInnerHTML={{ __html: site?.description || "" }}
|
||||
></span>
|
||||
)}
|
||||
<span className="block">
|
||||
<FollowingCount siteId={siteId} disableList={true} />
|
||||
</span>
|
||||
{site?.date_created && (
|
||||
<span className="block text-gray-500">
|
||||
Joined{" "}
|
||||
<time dateTime={formatToISO(site.date_created)}>
|
||||
{dayjs
|
||||
.duration(
|
||||
dayjs(site.date_created).diff(dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize()}{" "}
|
||||
ago
|
||||
</time>
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
"Loading..."
|
||||
<span
|
||||
className={clsx(
|
||||
"border-gray-100 rounded-lg space-y-2 text-sm block",
|
||||
style === "flat" ? "" : "p-4 bg-white shadow-xl",
|
||||
)}
|
||||
>
|
||||
{site ? (
|
||||
<>
|
||||
<span className="flex items-center justify-between">
|
||||
<Avatar images={site?.avatars || []} name={site?.name} size={45} />
|
||||
{!hideFollowButton && (
|
||||
<FollowingButton
|
||||
siteId={site.username}
|
||||
size="sm"
|
||||
loadingStatusChange={(status) => setButtonLoading?.(status)}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
<span className="block">
|
||||
<span className="font-bold text-base">{site?.name}</span>
|
||||
<span className="ml-1 text-gray-600">@{site.username}</span>
|
||||
</span>
|
||||
{site?.description && (
|
||||
<span
|
||||
className="block text-gray-600"
|
||||
dangerouslySetInnerHTML={{ __html: site?.description || "" }}
|
||||
></span>
|
||||
)}
|
||||
</span>
|
||||
<span className="block">
|
||||
<FollowingCount siteId={site.username} disableList={true} />
|
||||
</span>
|
||||
{site?.date_created && (
|
||||
<span className="block text-gray-500">
|
||||
Joined{" "}
|
||||
<time dateTime={formatToISO(site.date_created)}>
|
||||
{dayjs
|
||||
.duration(
|
||||
dayjs(site.date_created).diff(dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize()}{" "}
|
||||
ago
|
||||
</time>
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
"Loading..."
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { useState } from "react"
|
||||
import {
|
||||
offset,
|
||||
flip,
|
||||
shift,
|
||||
autoUpdate,
|
||||
useFloating,
|
||||
useInteractions,
|
||||
useHover,
|
||||
useFocus,
|
||||
useRole,
|
||||
useDismiss,
|
||||
} from "@floating-ui/react-dom-interactions"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
|
||||
export const CharacterFloatCard: React.FC<{
|
||||
siteId?: string
|
||||
children: JSX.Element
|
||||
}> = ({ siteId, children }) => {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const { x, y, reference, floating, strategy, context } = useFloating({
|
||||
placement: "bottom-start",
|
||||
open,
|
||||
onOpenChange: setOpen,
|
||||
middleware: [offset(5), flip(), shift({ padding: 8 })],
|
||||
whileElementsMounted: autoUpdate,
|
||||
})
|
||||
|
||||
const { getReferenceProps, getFloatingProps } = useInteractions([
|
||||
useHover(context, { delay: { close: 200, open: 200 } }),
|
||||
useFocus(context),
|
||||
useRole(context, { role: "tooltip" }),
|
||||
useDismiss(context),
|
||||
])
|
||||
|
||||
const [buttonLoading, setButtonLoading] = useState(false)
|
||||
|
||||
return (
|
||||
<span {...getReferenceProps({ ref: reference, ...children.props })}>
|
||||
{children}
|
||||
{
|
||||
<span
|
||||
{...getFloatingProps({
|
||||
ref: floating,
|
||||
className:
|
||||
"z-10 block w-80" + (open || buttonLoading ? "" : " hidden"),
|
||||
style: {
|
||||
position: strategy,
|
||||
top: y ?? "",
|
||||
left: x ?? "",
|
||||
},
|
||||
})}
|
||||
>
|
||||
<CharacterCard
|
||||
siteId={siteId}
|
||||
open={open}
|
||||
setButtonLoading={setButtonLoading}
|
||||
/>
|
||||
</span>
|
||||
}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { CSB_SCAN } from "~/lib/env"
|
||||
import { Avatar } from "../ui/Avatar"
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
|
||||
export const CharacterList: React.FC<{
|
||||
open: boolean
|
||||
@@ -42,7 +42,7 @@ export const CharacterList: React.FC<{
|
||||
})}
|
||||
className="flex items-center space-x-2 text-sm"
|
||||
>
|
||||
<CharacterCard siteId={sub?.character?.handle}>
|
||||
<CharacterFloatCard siteId={sub?.character?.handle}>
|
||||
<Avatar
|
||||
className="align-middle border-2 border-white"
|
||||
images={sub.character?.metadata?.content?.avatars || []}
|
||||
@@ -52,7 +52,7 @@ export const CharacterList: React.FC<{
|
||||
}
|
||||
size={40}
|
||||
/>
|
||||
</CharacterCard>
|
||||
</CharacterFloatCard>
|
||||
<span>{sub.character?.metadata?.content?.name}</span>
|
||||
<span className="text-zinc-400 truncate max-w-xs">
|
||||
@{sub.character?.handle}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { Button } from "~/components/ui/Button"
|
||||
import { Reactions } from "~/components/common/Reactions"
|
||||
import { useState } from "react"
|
||||
import { CommentInput } from "~/components/common/CommentInput"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
|
||||
export const CommentItem: React.FC<{
|
||||
comment: NoteEntity & {
|
||||
@@ -28,7 +28,7 @@ export const CommentItem: React.FC<{
|
||||
>
|
||||
<div className="flex group">
|
||||
<div>
|
||||
<CharacterCard siteId={comment?.character?.handle}>
|
||||
<CharacterFloatCard siteId={comment?.character?.handle}>
|
||||
<div>
|
||||
<UniLink
|
||||
href={
|
||||
@@ -46,7 +46,7 @@ export const CommentItem: React.FC<{
|
||||
/>
|
||||
</UniLink>
|
||||
</div>
|
||||
</CharacterCard>
|
||||
</CharacterFloatCard>
|
||||
</div>
|
||||
<div className="flex-1 flex flex-col rounded-lg">
|
||||
<div className="mb-1 text-sm">
|
||||
|
||||
@@ -21,6 +21,10 @@ export const SettingsLayout: React.FC<{
|
||||
},
|
||||
{ text: "Domains", href: `/dashboard/${subdomain}/settings/domains` },
|
||||
{ text: "Custom CSS", href: `/dashboard/${subdomain}/settings/css` },
|
||||
{
|
||||
text: "Operators",
|
||||
href: `/dashboard/${subdomain}/settings/operator`,
|
||||
},
|
||||
{
|
||||
text: "Export data",
|
||||
href: `https://export.crossbell.io/?handle=${subdomain}`,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React from "react"
|
||||
import { CharacterCard } from "../common/CharacterCard"
|
||||
import { CharacterFloatCard } from "../common/CharacterFloatCard"
|
||||
import { UniLink } from "./UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
|
||||
@@ -8,7 +8,7 @@ export const Mention: React.FC<{
|
||||
}> = ({ id }) => {
|
||||
const siteId = id?.replace(/^user-content-/, "")
|
||||
return (
|
||||
<CharacterCard siteId={siteId}>
|
||||
<CharacterFloatCard siteId={siteId}>
|
||||
<UniLink
|
||||
href={getSiteLink({
|
||||
subdomain: siteId,
|
||||
@@ -17,6 +17,6 @@ export const Mention: React.FC<{
|
||||
>
|
||||
@{siteId}
|
||||
</UniLink>
|
||||
</CharacterCard>
|
||||
</CharacterFloatCard>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { nanoid } from "nanoid"
|
||||
import unidata from "~/queries/unidata.server"
|
||||
import { toGateway } from "~/lib/ipfs-parser"
|
||||
import type Unidata from "unidata.js"
|
||||
import type { Profiles as UniProfiles } from "unidata.js"
|
||||
import { createClient } from "@urql/core"
|
||||
import axios from "axios"
|
||||
import { indexer } from "~/queries/crossbell"
|
||||
@@ -65,16 +66,22 @@ export const getUserSites = async (
|
||||
if (!address) {
|
||||
return null
|
||||
}
|
||||
const profiles = await (customUnidata || unidata).profiles.get({
|
||||
source: "Crossbell Profile",
|
||||
identity: address,
|
||||
platform: "Ethereum",
|
||||
filter: {
|
||||
primary: true,
|
||||
},
|
||||
})
|
||||
|
||||
const sites: Profile[] = profiles.list?.map((profile) => {
|
||||
let profiles: UniProfiles
|
||||
try {
|
||||
profiles = await (customUnidata || unidata).profiles.get({
|
||||
source: "Crossbell Profile",
|
||||
identity: address,
|
||||
platform: "Ethereum",
|
||||
filter: {
|
||||
primary: true,
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
return null
|
||||
}
|
||||
|
||||
const sites: Profile[] = profiles?.list?.map((profile) => {
|
||||
expandSite(profile)
|
||||
return profile
|
||||
})
|
||||
@@ -430,3 +437,50 @@ export async function getNotifications(input: { siteCId: string }) {
|
||||
return b.createdAt > a.createdAt ? 1 : -1
|
||||
})
|
||||
}
|
||||
|
||||
export async function addOperator(
|
||||
input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.operator && input.characterId) {
|
||||
return contract?.addOperator(input.characterId, input.operator)
|
||||
}
|
||||
}
|
||||
|
||||
export async function getOperators(
|
||||
input: {
|
||||
characterId?: number
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.characterId) {
|
||||
return contract?.getOperators(input.characterId)
|
||||
}
|
||||
}
|
||||
|
||||
export async function isOperators(
|
||||
input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.characterId) {
|
||||
return contract?.isOperator(input.characterId, input.operator)
|
||||
}
|
||||
}
|
||||
|
||||
export async function removeOperator(
|
||||
input: {
|
||||
characterId: number
|
||||
operator: string
|
||||
},
|
||||
contract?: Contract,
|
||||
) {
|
||||
if (input.characterId) {
|
||||
return contract?.removeOperator(input.characterId, input.operator)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { DashboardMain } from "~/components/dashboard/DashboardMain"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { getSiteLink } from "~/lib/helpers"
|
||||
import { useGetNotifications, useGetSite } from "~/queries/site"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
import { Avatar } from "~/components/ui/Avatar"
|
||||
import dayjs from "~/lib/date"
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
@@ -98,7 +98,7 @@ export default function SubdomainIndex() {
|
||||
</div>
|
||||
)}
|
||||
<div>
|
||||
<CharacterCard siteId={character?.handle}>
|
||||
<CharacterFloatCard siteId={character?.handle}>
|
||||
<div>
|
||||
<UniLink
|
||||
href={
|
||||
@@ -118,7 +118,7 @@ export default function SubdomainIndex() {
|
||||
/>
|
||||
</UniLink>
|
||||
</div>
|
||||
</CharacterCard>
|
||||
</CharacterFloatCard>
|
||||
</div>
|
||||
<div className="flex-1 flex flex-col rounded-lg">
|
||||
<div className="mb-1 text-sm">
|
||||
|
||||
@@ -0,0 +1,194 @@
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { Input } from "~/components/ui/Input"
|
||||
import { useEffect, useState } from "react"
|
||||
import toast from "react-hot-toast"
|
||||
import { SettingsLayout } from "~/components/dashboard/SettingsLayout"
|
||||
import { useRouter } from "next/router"
|
||||
import { DashboardLayout } from "~/components/dashboard/DashboardLayout"
|
||||
import {
|
||||
useGetSite,
|
||||
useGetOperators,
|
||||
useAddOperator,
|
||||
useRemoveOperator,
|
||||
} from "~/queries/site"
|
||||
import { Dialog } from "@headlessui/react"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
|
||||
type RemoveItem = (operator: string) => void
|
||||
|
||||
const SortableNavigationItem: React.FC<{
|
||||
item: string
|
||||
removeItem: RemoveItem
|
||||
isLoading: boolean
|
||||
}> = ({ item, removeItem, isLoading }) => {
|
||||
return (
|
||||
<div className="flex space-x-5 border-b p-5 bg-zinc-50 last:border-0 items-center">
|
||||
<div className="text-sm space-y-4">
|
||||
<div>Address: {item}</div>
|
||||
<div>Character:</div>
|
||||
<CharacterCard
|
||||
address={item}
|
||||
open={true}
|
||||
hideFollowButton={true}
|
||||
style="flat"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-end relative -top-[5px]">
|
||||
<Button
|
||||
onClick={() => removeItem(item)}
|
||||
variantColor="red"
|
||||
isLoading={isLoading}
|
||||
>
|
||||
Remove
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default function SiteSettingsNavigationPage() {
|
||||
const router = useRouter()
|
||||
|
||||
const subdomain = router.query.subdomain as string
|
||||
|
||||
const addOperator = useAddOperator()
|
||||
const removeOperator = useRemoveOperator()
|
||||
const site = useGetSite(subdomain)
|
||||
const operators = useGetOperators({
|
||||
characterId: +(site.data?.metadata?.proof || 0),
|
||||
})
|
||||
|
||||
const [items, setItems] = useState<string[]>([])
|
||||
|
||||
const newEmptyItem = () => {
|
||||
setIsOpen(true)
|
||||
setAddress("")
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (addOperator.isSuccess) {
|
||||
toast.success("Operator added")
|
||||
} else if (addOperator.isError) {
|
||||
toast.error("Failed to add operator")
|
||||
}
|
||||
setIsOpen(false)
|
||||
}, [addOperator.isSuccess, addOperator.isError])
|
||||
|
||||
useEffect(() => {
|
||||
if (removeOperator.isSuccess) {
|
||||
toast.success("Operator removed")
|
||||
} else if (removeOperator.isError) {
|
||||
toast.error("Failed to remove operator")
|
||||
}
|
||||
}, [removeOperator.isSuccess, removeOperator.isError])
|
||||
|
||||
const removeItem: RemoveItem = (operator) => {
|
||||
removeOperator.mutate({
|
||||
characterId: +(site.data?.metadata?.proof || 0),
|
||||
operator: operator,
|
||||
})
|
||||
}
|
||||
const addItem = () => {
|
||||
if (address) {
|
||||
addOperator.mutate({
|
||||
characterId: +(site.data?.metadata?.proof || 0),
|
||||
operator: address,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
setItems(operators.data || [])
|
||||
}, [operators.data])
|
||||
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [address, setAddress] = useState("")
|
||||
|
||||
return (
|
||||
<DashboardLayout title="Navigation">
|
||||
<SettingsLayout title="Site Settings" type="site">
|
||||
<Dialog
|
||||
open={isOpen}
|
||||
onClose={() => setIsOpen(false)}
|
||||
className="fixed z-10 inset-0 overflow-y-auto"
|
||||
>
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<Dialog.Overlay className="fixed inset-0 bg-black opacity-30" />
|
||||
|
||||
<div className="relative bg-white rounded-lg max-w-md w-full mx-auto">
|
||||
<Dialog.Title className="px-5 h-12 flex items-center border-b">
|
||||
New operator
|
||||
</Dialog.Title>
|
||||
|
||||
<div className="p-5">
|
||||
<Input
|
||||
className="w-full"
|
||||
label="Operator Address"
|
||||
required
|
||||
onChange={(e) => {
|
||||
setAddress(e.target.value)
|
||||
}}
|
||||
/>
|
||||
<div className="form-label mt-5">Operator Character Check</div>
|
||||
<div>
|
||||
<CharacterCard
|
||||
address={address}
|
||||
open={true}
|
||||
hideFollowButton={true}
|
||||
style="flat"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="h-16 border-t flex items-center px-5">
|
||||
<Button
|
||||
isLoading={addOperator.isLoading}
|
||||
isDisabled={!address}
|
||||
onClick={addItem}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
<div className="p-5 text-zinc-500 bg-orange-50 mb-5 rounded-lg text-xs space-y-2">
|
||||
<p className="text-zinc-800 text-sm font-bold">⚠️ Warning:</p>
|
||||
<p>
|
||||
<span className="text-zinc-800">
|
||||
Operators have permissions to enter your dashboard and post
|
||||
contents on your site.
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<div className="bg-zinc-50 rounded-lg overflow-hidden">
|
||||
{items.length === 0 && (
|
||||
<div className="text-center text-zinc-500 p-5">
|
||||
No operators yet
|
||||
</div>
|
||||
)}
|
||||
{items.map((item, index) => {
|
||||
return (
|
||||
<SortableNavigationItem
|
||||
key={index}
|
||||
item={item}
|
||||
removeItem={removeItem}
|
||||
isLoading={removeOperator.isLoading}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
<style jsx global>{`
|
||||
.sortable-ghost {
|
||||
opacity: 0.4;
|
||||
}
|
||||
`}</style>
|
||||
</div>
|
||||
<div className="border-t pt-5 mt-10 space-x-3 flex items-center">
|
||||
<Button onClick={newEmptyItem}>Add</Button>
|
||||
</div>
|
||||
</div>
|
||||
</SettingsLayout>
|
||||
</DashboardLayout>
|
||||
)
|
||||
}
|
||||
+3
-3
@@ -19,7 +19,7 @@ import { dehydrate, QueryClient } from "@tanstack/react-query"
|
||||
import { prefetchGetSites } from "~/queries/site.server"
|
||||
import { useGetSites } from "~/queries/site"
|
||||
import showcase from "../../showcase.json"
|
||||
import { CharacterCard } from "~/components/common/CharacterCard"
|
||||
import { CharacterFloatCard } from "~/components/common/CharacterFloatCard"
|
||||
import { useGetUserSites, useSubscribeToSites } from "~/queries/site"
|
||||
import { SITE_URL } from "~/lib/env"
|
||||
import { BoltIcon } from "@heroicons/react/24/outline"
|
||||
@@ -279,7 +279,7 @@ export default function Home({ region }: { region: string | null }) {
|
||||
className="inline-flex align-middle w-full"
|
||||
>
|
||||
<span className="w-14 h-14">
|
||||
<CharacterCard siteId={site.handle}>
|
||||
<CharacterFloatCard siteId={site.handle}>
|
||||
<span className="w-full h-full">
|
||||
<Image
|
||||
className="rounded-full"
|
||||
@@ -292,7 +292,7 @@ export default function Home({ region }: { region: string | null }) {
|
||||
height="56"
|
||||
></Image>
|
||||
</span>
|
||||
</CharacterCard>
|
||||
</CharacterFloatCard>
|
||||
</span>
|
||||
<span className="ml-3 min-w-0 flex-1 justify-center inline-flex flex-col">
|
||||
<span className="truncate w-full inline-block font-medium">
|
||||
|
||||
@@ -181,3 +181,77 @@ export const useGetNotifications = (data: { siteCId?: string }) => {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const useGetOperators = (
|
||||
data: Parameters<typeof siteModel.getOperators>[0],
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["getOperators", data], async () => {
|
||||
if (!data.characterId) {
|
||||
return null
|
||||
}
|
||||
return (await siteModel.getOperators(data, contract))?.data?.filter(
|
||||
(operator) => operator !== "0x0000000000000000000000000000000000000000",
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export const useIsOperators = (
|
||||
data: Parameters<typeof siteModel.isOperators>[0],
|
||||
) => {
|
||||
const contract = useContract()
|
||||
return useQuery(["isOperators", data], async () => {
|
||||
return siteModel.isOperators(data, contract)
|
||||
})
|
||||
}
|
||||
|
||||
export function useAddOperator() {
|
||||
const contract = useContract()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation(
|
||||
async (input: Parameters<typeof siteModel.addOperator>[0]) => {
|
||||
return siteModel.addOperator(input, contract)
|
||||
},
|
||||
{
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries([
|
||||
"getOperators",
|
||||
{
|
||||
characterId: variables.characterId,
|
||||
},
|
||||
])
|
||||
queryClient.invalidateQueries(["isOperators", variables])
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
export function useRemoveOperator() {
|
||||
const contract = useContract()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation(
|
||||
async (input: Partial<Parameters<typeof siteModel.removeOperator>[0]>) => {
|
||||
if (!input.operator || !input.characterId) {
|
||||
return null
|
||||
}
|
||||
return siteModel.removeOperator(
|
||||
{
|
||||
operator: input.operator,
|
||||
characterId: input.characterId,
|
||||
},
|
||||
contract,
|
||||
)
|
||||
},
|
||||
{
|
||||
onSuccess: (data, variables) => {
|
||||
queryClient.invalidateQueries([
|
||||
"getOperators",
|
||||
{
|
||||
characterId: variables.characterId,
|
||||
},
|
||||
])
|
||||
queryClient.invalidateQueries(["isOperators", variables])
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user