feat: remove new site page
This commit is contained in:
@@ -4,7 +4,11 @@ import { Avatar } from "~/components/ui/Avatar"
|
||||
import { Input } from "~/components/ui/Input"
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
|
||||
import {
|
||||
useAccountState,
|
||||
useConnectModal,
|
||||
useWalletMintNewCharacterModal,
|
||||
} from "@crossbell/connect-kit"
|
||||
import { useState, useEffect } from "react"
|
||||
import { useCommentPage } from "~/queries/page"
|
||||
import { useRouter } from "next/router"
|
||||
@@ -22,6 +26,7 @@ export const CommentInput: React.FC<{
|
||||
const commentPage = useCommentPage()
|
||||
const router = useRouter()
|
||||
const [viewer, setViewer] = useState<Profile | null>(null)
|
||||
const walletMintNewCharacterModal = useWalletMintNewCharacterModal()
|
||||
|
||||
useEffect(() => {
|
||||
if (userSites.isSuccess && userSites.data?.length) {
|
||||
@@ -39,7 +44,7 @@ export const CommentInput: React.FC<{
|
||||
if (!account) {
|
||||
openConnectModal?.()
|
||||
} else if (userSites.isSuccess && !userSites.data?.length) {
|
||||
router.push(`/dashboard/new-site`)
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (pageId) {
|
||||
commentPage.mutate({
|
||||
pageId: pageId,
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
useUnsubscribeFromSite,
|
||||
useAccountSites,
|
||||
} from "~/queries/site"
|
||||
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
|
||||
import {
|
||||
useAccountState,
|
||||
useConnectModal,
|
||||
useWalletMintNewCharacterModal,
|
||||
} from "@crossbell/connect-kit"
|
||||
import clsx from "clsx"
|
||||
import { Profile } from "~/lib/types"
|
||||
|
||||
@@ -28,14 +32,15 @@ export const FollowingButton: React.FC<{
|
||||
const userSite = useAccountSites()
|
||||
const router = useRouter()
|
||||
const characterId = site?.metadata?.proof ? Number(site.metadata.proof) : null
|
||||
const walletMintNewCharacterModal = useWalletMintNewCharacterModal()
|
||||
|
||||
const handleClickSubscribe = async (e: any) => {
|
||||
e.preventDefault()
|
||||
if (!account) {
|
||||
setFollowProgress(true)
|
||||
openConnectModal?.()
|
||||
} else if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
} else if (!userSite.data?.length) {
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (characterId) {
|
||||
if (subscription.data) {
|
||||
unsubscribeFromSite.mutate({
|
||||
@@ -62,7 +67,7 @@ export const FollowingButton: React.FC<{
|
||||
userSite.isSuccess
|
||||
) {
|
||||
if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
walletMintNewCharacterModal.show()
|
||||
}
|
||||
if (!subscription.data) {
|
||||
subscribeToSite.mutate({ characterId })
|
||||
|
||||
@@ -9,7 +9,11 @@ import {
|
||||
useCheckMint,
|
||||
} from "~/queries/page"
|
||||
import { useAccountSites } from "~/queries/site"
|
||||
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
|
||||
import {
|
||||
useAccountState,
|
||||
useConnectModal,
|
||||
useWalletMintNewCharacterModal,
|
||||
} from "@crossbell/connect-kit"
|
||||
import { useState, useEffect, useRef } from "react"
|
||||
import { Button } from "../ui/Button"
|
||||
import { useRouter } from "next/router"
|
||||
@@ -33,7 +37,7 @@ export const Reactions: React.FC<{
|
||||
const unlikePage = useUnlikePage()
|
||||
const mintPage = useMintPage()
|
||||
|
||||
const isConnected = useAccountState((s) => !!s.computed.account)
|
||||
const isConnected = useAccountState((s) => !!s.computed.account) // TODO is logged in
|
||||
const { show: openConnectModal } = useConnectModal()
|
||||
const [likeProgress, setLikeProgress] = useState(false)
|
||||
const [mintProgress, setMintProgress] = useState(false)
|
||||
@@ -45,6 +49,7 @@ export const Reactions: React.FC<{
|
||||
const [isMintListOpen, setIsMintListOpen] = useState(false)
|
||||
const likeRef = useRef<HTMLButtonElement>(null)
|
||||
const mintRef = useRef<HTMLButtonElement>(null)
|
||||
const walletMintNewCharacterModal = useWalletMintNewCharacterModal()
|
||||
|
||||
const likes = useGetLikes({
|
||||
pageId: pageId,
|
||||
@@ -62,8 +67,8 @@ export const Reactions: React.FC<{
|
||||
if (!isConnected) {
|
||||
setLikeProgress(true)
|
||||
openConnectModal?.()
|
||||
} else if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
} else if (!userSite.data?.length) {
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (pageId) {
|
||||
if (isLike.data?.count) {
|
||||
setIsLikeOpen(true)
|
||||
@@ -97,8 +102,6 @@ export const Reactions: React.FC<{
|
||||
if (!isConnected) {
|
||||
setMintProgress(true)
|
||||
openConnectModal?.()
|
||||
} else if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
} else if (pageId) {
|
||||
if (isMint.data?.count) {
|
||||
setIsMintOpen(true)
|
||||
@@ -143,9 +146,8 @@ export const Reactions: React.FC<{
|
||||
userSite.isSuccess
|
||||
) {
|
||||
if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
}
|
||||
if (!isMint.data.count) {
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (!isMint.data.count) {
|
||||
mintPage.mutate(parsePageId(pageId))
|
||||
}
|
||||
setMintProgress(false)
|
||||
@@ -171,9 +173,8 @@ export const Reactions: React.FC<{
|
||||
userSite.isSuccess
|
||||
) {
|
||||
if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
}
|
||||
if (!isLike.data.count) {
|
||||
walletMintNewCharacterModal.show()
|
||||
} else if (!isLike.data.count) {
|
||||
likePage.mutate(parsePageId(pageId))
|
||||
}
|
||||
setLikeProgress(false)
|
||||
|
||||
@@ -1,94 +0,0 @@
|
||||
import { Popover } from "@headlessui/react"
|
||||
import Link from "next/link"
|
||||
import { useEffect, useMemo } from "react"
|
||||
import { getUserContentsUrl } from "~/lib/user-contents"
|
||||
import { Avatar } from "../ui/Avatar"
|
||||
import type { Profile } from "unidata.js"
|
||||
|
||||
type Props = {
|
||||
subdomain: string
|
||||
subscriptions: Profile[]
|
||||
viewer?: { address?: string }
|
||||
}
|
||||
|
||||
export const SiteSwitcher: React.FC<Props> = ({
|
||||
subdomain,
|
||||
subscriptions,
|
||||
viewer,
|
||||
}) => {
|
||||
const activeSubscription = subscriptions.find((s) => s.username === subdomain)
|
||||
|
||||
return (
|
||||
<div className="px-3 pt-3 pb-2 text-sm">
|
||||
<Popover className="relative">
|
||||
<Popover.Button className="h-8 px-2 justify-between flex w-full rounded-lg hover:bg-gray-200 hover:bg-opacity-50 transition-colors items-center">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Avatar
|
||||
images={[getUserContentsUrl(activeSubscription?.avatars?.[0])]}
|
||||
name={activeSubscription?.name}
|
||||
size={22}
|
||||
/>
|
||||
<span className="truncate">{activeSubscription?.name}</span>
|
||||
</div>
|
||||
<span className="w-5 h-5 text-zinc-400 rounded-full bg-zinc-100 inline-flex items-center justify-center">
|
||||
<svg className="w-4 h-4" viewBox="0 0 14 14">
|
||||
<g
|
||||
stroke="none"
|
||||
strokeWidth="1"
|
||||
fill="currentColor"
|
||||
fillRule="evenodd"
|
||||
>
|
||||
<path d="M7.00,9.48 C7.08,9.48 7.16,9.46 7.24,9.43 C7.31,9.40 7.38,9.35 7.44,9.29 L11.16,5.48 C11.27,5.37 11.32,5.24 11.32,5.08 C11.32,4.98 11.30,4.88 11.25,4.79 C11.20,4.70 11.13,4.64 11.04,4.59 C10.96,4.54 10.86,4.51 10.76,4.51 C10.60,4.51 10.46,4.57 10.34,4.68 L6.76,8.36 L7.24,8.36 L3.65,4.68 C3.53,4.57 3.39,4.51 3.24,4.51 C3.13,4.51 3.03,4.54 2.95,4.59 C2.86,4.64 2.80,4.70 2.75,4.79 C2.70,4.88 2.67,4.98 2.67,5.08 C2.67,5.16 2.68,5.23 2.71,5.30 C2.74,5.37 2.78,5.43 2.83,5.48 L6.55,9.29 C6.69,9.42 6.83,9.48 7.00,9.48 Z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
</span>
|
||||
</Popover.Button>
|
||||
<Popover.Panel className="absolute left-0 z-10 pt-1">
|
||||
<div className="min-w-[280px] rounded-lg shadow-modal bg-white">
|
||||
{viewer && (
|
||||
<div className="px-4 py-2 border-b text-sm text-zinc-500">
|
||||
{viewer.address?.slice(0, 6)}...{viewer.address?.slice(-4)}
|
||||
</div>
|
||||
)}
|
||||
<div className="p-2">
|
||||
{subscriptions?.map((subscription) => {
|
||||
return (
|
||||
<Link
|
||||
key={subscription.username}
|
||||
href={`/dashboard/${subscription.username}`}
|
||||
className="flex px-2 h-8 rounded-lg items-center justify-between hover:bg-zinc-100"
|
||||
>
|
||||
<span className="truncate w-8/12">{subscription.name}</span>
|
||||
{activeSubscription?.username === subscription.username && (
|
||||
<span className="text-accent">
|
||||
<svg
|
||||
className="w-5 h-5"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</span>
|
||||
)}
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
<div className="border-t py-2 px-2">
|
||||
<Link href={`/dashboard/new-site`}>
|
||||
<a className="rounded-lg text-sm text-zinc-500 flex px-2 h-8 items-center hover:bg-zinc-100">
|
||||
Create a new site
|
||||
</a>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</Popover.Panel>
|
||||
</Popover>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -9,7 +9,7 @@ export default function Dashboard() {
|
||||
useEffect(() => {
|
||||
if (userSites.isSuccess) {
|
||||
if (!userSites.data?.length) {
|
||||
router.push(`/dashboard/new-site`)
|
||||
router.push(`/`)
|
||||
} else {
|
||||
router.push(`/dashboard/${userSites.data[0].username}`)
|
||||
}
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
import { useRouter } from "next/router"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import toast from "react-hot-toast"
|
||||
import { SEOHead } from "~/components/common/SEOHead"
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { Input } from "~/components/ui/Input"
|
||||
import { APP_NAME, OUR_DOMAIN } from "~/lib/env"
|
||||
import { useCreateSite } from "~/queries/site"
|
||||
import { UniLink } from "~/components/ui/UniLink"
|
||||
import { useAccountSites } from "~/queries/site"
|
||||
import { getSite } from "~/models/site.model"
|
||||
import { useAccountState } from "@crossbell/connect-kit"
|
||||
import { useAccountBalance } from "~/hooks/use-account-balance"
|
||||
|
||||
export default function NewSitePage() {
|
||||
const router = useRouter()
|
||||
const createSite = useCreateSite()
|
||||
const account = useAccountState((s) => s.computed.account)
|
||||
const isConnected = !!account
|
||||
const { balance } = useAccountBalance()
|
||||
const [balanceFormatted, setBalanceFormatted] = useState<string>("")
|
||||
|
||||
const [InsufficientBalance, setInsufficientBalance] = useState<boolean>(true)
|
||||
|
||||
const userSites = useAccountSites()
|
||||
|
||||
useEffect(() => {
|
||||
if (userSites.isSuccess) {
|
||||
if (userSites.data?.length) {
|
||||
router.push(`/dashboard/${userSites.data[0].username}`)
|
||||
}
|
||||
}
|
||||
}, [userSites, router])
|
||||
|
||||
useEffect(() => {
|
||||
if (balance) {
|
||||
setBalanceFormatted(balance.formatted)
|
||||
if (
|
||||
BigInt(balance.value.toString()) >
|
||||
BigInt("1" + "0".repeat(balance.decimals - 2))
|
||||
) {
|
||||
setInsufficientBalance(false)
|
||||
} else {
|
||||
setInsufficientBalance(true)
|
||||
}
|
||||
}
|
||||
}, [balance])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isConnected) {
|
||||
router.push("/")
|
||||
}
|
||||
}, [isConnected, router])
|
||||
|
||||
const form = useForm({
|
||||
defaultValues: {
|
||||
name: "",
|
||||
subdomain: "",
|
||||
},
|
||||
})
|
||||
|
||||
const checkIfHandleExists = async (handle: string) => {
|
||||
try {
|
||||
const owner = await getSite(handle)
|
||||
|
||||
if (owner) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} catch (e: any) {
|
||||
console.error(`Error: ${e.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const [checkLoading, setCheckLoading] = useState<boolean>(false)
|
||||
const handleSubmit = form.handleSubmit(async (values) => {
|
||||
setCheckLoading(true)
|
||||
if (!/^[a-z0-9\-\_]*$/.test(values.subdomain)) {
|
||||
toast.error(
|
||||
"Handle must be alphanumeric and contain only dashes and underscores.",
|
||||
)
|
||||
setCheckLoading(false)
|
||||
return
|
||||
}
|
||||
if (!(values.subdomain.length >= 3 && values.subdomain.length <= 31)) {
|
||||
toast.error("Handle must be between 3 and 31 characters long.")
|
||||
setCheckLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
if (await checkIfHandleExists(values.subdomain)) {
|
||||
toast.error("Handle already exists.")
|
||||
setCheckLoading(false)
|
||||
return
|
||||
}
|
||||
createSite.mutate(values)
|
||||
setCheckLoading(false)
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (createSite.isSuccess) {
|
||||
if (createSite.data?.code === 0) {
|
||||
router.push(`/dashboard/${createSite.variables?.subdomain}`)
|
||||
} else {
|
||||
toast.error("Failed to create site" + ": " + createSite.data?.message)
|
||||
}
|
||||
} else if (createSite.isError) {
|
||||
toast.error("Failed to create site")
|
||||
}
|
||||
}, [createSite, router])
|
||||
|
||||
return (
|
||||
<>
|
||||
<SEOHead title="New Site" siteName={APP_NAME} />
|
||||
<div>
|
||||
<header className="px-5 text-sm md:px-14 flex justify-between items-start py-10">
|
||||
<button onClick={() => router.back()}>
|
||||
<a className="flex space-x-1 items-center">
|
||||
<svg
|
||||
className="w-4 h-4"
|
||||
fill="currentColor"
|
||||
viewBox="0 0 20 20"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
fillRule="evenodd"
|
||||
d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z"
|
||||
clipRule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
<span>Back</span>
|
||||
</a>
|
||||
</button>
|
||||
<div>
|
||||
<div className="text-zinc-400">Logged in as:</div>
|
||||
<div>
|
||||
{account?.type === "email" ? account.email : account?.address}
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
<div className="max-w-sm mx-auto mt-20">
|
||||
<h2 className="text-3xl mb-8 text-center">Create a new site</h2>
|
||||
<p className="mb-8 text-gray-500">
|
||||
After creating your own site, you can start writing your blog and
|
||||
interacting with other bloggers.
|
||||
</p>
|
||||
{InsufficientBalance ? (
|
||||
<p className="mb-8 text-red-400">
|
||||
Your $CSB balance ({balanceFormatted}) may not be sufficient,
|
||||
please go to{" "}
|
||||
<UniLink
|
||||
href="https://faucet.crossbell.io/"
|
||||
className="font-bold text-red-500"
|
||||
>
|
||||
Crossbell faucet
|
||||
</UniLink>{" "}
|
||||
to get some free $CSB.
|
||||
</p>
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<form className="space-y-5" onSubmit={handleSubmit}>
|
||||
<div>
|
||||
<Input
|
||||
id="name"
|
||||
label="Site Name"
|
||||
isBlock
|
||||
required
|
||||
maxLength={30}
|
||||
{...form.register("name", {})}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Input
|
||||
id="subdomain"
|
||||
label="Subdomain"
|
||||
isBlock
|
||||
required
|
||||
addon={`.${OUR_DOMAIN}`}
|
||||
minLength={3}
|
||||
maxLength={26}
|
||||
{...form.register("subdomain", {})}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Button
|
||||
type="submit"
|
||||
isBlock
|
||||
isLoading={checkLoading || createSite.isLoading}
|
||||
>
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
+13
-7
@@ -6,7 +6,11 @@ import { UniLink } from "~/components/ui/UniLink"
|
||||
import { BlockchainIcon } from "~/components/icons/BlockchainIcon"
|
||||
import { LaughIcon } from "~/components/icons/LaughIcon"
|
||||
import { Button } from "~/components/ui/Button"
|
||||
import { useAccountState, useConnectModal } from "@crossbell/connect-kit"
|
||||
import {
|
||||
useAccountState,
|
||||
useConnectModal,
|
||||
useWalletMintNewCharacterModal,
|
||||
} from "@crossbell/connect-kit"
|
||||
import { useRefCallback } from "@crossbell/util-hooks"
|
||||
import { useRouter } from "next/router"
|
||||
import { GITHUB_LINK, APP_NAME, CSB_SCAN, OUR_DOMAIN } from "~/lib/env"
|
||||
@@ -221,6 +225,7 @@ export default function Home() {
|
||||
const [followProgress, setFollowProgress] = useState<boolean>(false)
|
||||
const userSite = useAccountSites()
|
||||
const subscribeToSites = useSubscribeToSites()
|
||||
const walletMintNewCharacterModal = useWalletMintNewCharacterModal()
|
||||
|
||||
const doSubscribeToSites = useRefCallback(() => {
|
||||
subscribeToSites.mutate({
|
||||
@@ -237,7 +242,7 @@ export default function Home() {
|
||||
setFollowProgress(true)
|
||||
openConnectModal?.()
|
||||
} else if (!userSite.data?.[0]) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
walletMintNewCharacterModal.show()
|
||||
} else {
|
||||
doSubscribeToSites()
|
||||
}
|
||||
@@ -252,9 +257,10 @@ export default function Home() {
|
||||
userSite.isSuccess
|
||||
) {
|
||||
if (!userSite.data) {
|
||||
router.push(`${SITE_URL}/dashboard/new-site`)
|
||||
walletMintNewCharacterModal.show()
|
||||
} else {
|
||||
doSubscribeToSites()
|
||||
}
|
||||
doSubscribeToSites()
|
||||
setFollowProgress(false)
|
||||
}
|
||||
}, [
|
||||
@@ -310,7 +316,7 @@ export default function Home() {
|
||||
<span>Dashboard</span>
|
||||
</>
|
||||
) : (
|
||||
"Get started free"
|
||||
"Get my xLog in 5 minutes"
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -508,11 +514,11 @@ export default function Home() {
|
||||
href="/dashboard"
|
||||
className="text-accent inline-flex items-center space-x-2"
|
||||
>
|
||||
<Button size="xl">Get started free</Button>
|
||||
<Button size="xl">Get my xLog in 5 minutes</Button>
|
||||
</UniLink>
|
||||
) : (
|
||||
<Button onClick={tryNow} size="xl">
|
||||
Get started free
|
||||
Get my xLog in 5 minutes
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user