Skip to content

Commit

Permalink
chore: merge profiles-page branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Aug 23, 2024
2 parents fce3bd7 + 87f29a1 commit f4538d3
Show file tree
Hide file tree
Showing 20 changed files with 423 additions and 246 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const Page = () => {
...prev,
referrerProfile: data.referrerProfile,
}))
router.push("choose-pass")
router.push("start-profile")
}
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ const Page = () => {
if (!data.referrerProfile) {
router.replace("claim-pass")
}
if (!data.subscription) {
router.replace("choose-pass")
}
}, [data, router.replace])

if (!data.subscription || !data.referrerProfile) {
if (!data.referrerProfile) {
return <CreateProfileSkeleton />
}

Expand Down
18 changes: 11 additions & 7 deletions src/app/(marketing)/profile/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Image from "next/image"
import { notFound, redirect } from "next/navigation"
import { Profile } from "../_components/Profile"
import { ProfileColorBanner } from "../_components/ProfileColorBanner"
import { ProfileHero } from "../_components/ProfileHero"

const api = env.NEXT_PUBLIC_API

Expand Down Expand Up @@ -97,14 +98,16 @@ const Page = async ({ params: { username } }: { params: { username: string } })
fallback,
}}
>
<Layout
style={
isBgColor ? { ["--banner" as string]: profile.backgroundImageUrl } : {}
}
>
<LayoutHero className="pb-4 md:pb-10">
<Layout>
<LayoutHero className="pb-0">
<Header />
<LayoutBanner className="-bottom-[600px]">
<LayoutBanner
className="-bottom-[100px]"
data-theme="dark"
style={
isBgColor ? { ["--banner" as string]: profile.backgroundImageUrl } : {}
}
>
{isBgColor ? (
<ProfileColorBanner />
) : (
Expand All @@ -123,6 +126,7 @@ const Page = async ({ params: { username } }: { params: { username: string } })
)}
<div className="absolute inset-0 bg-gradient-to-t from-background" />
</LayoutBanner>
<ProfileHero />
</LayoutHero>
<LayoutMain className="top-0">
<Profile />
Expand Down
15 changes: 14 additions & 1 deletion src/app/(marketing)/profile/_components/CardWithGuildLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { CheckMark } from "@/components/CheckMark"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/Avatar"
import { Card } from "@/components/ui/Card"
import { cn } from "@/lib/utils"
import { Guild } from "@guildxyz/types"
import Color from "color"
import { PropsWithChildren } from "react"

export const CardWithGuildLabel = ({
guild,
children,
}: PropsWithChildren<{ guild: Guild }>) => {
const color = guild.theme.color && Color(guild.theme.color)

return (
<Card
className="relative flex border-4 bg-accent sm:border-2"
Expand All @@ -27,7 +31,16 @@ export const CardWithGuildLabel = ({
/>
<AvatarFallback />
</Avatar>
<div className="-mt-0.5 truncate font-bold font-display text-white max-sm:text-sm sm:max-w-12">
<div
className={cn(
"-mt-0.5 truncate font-bold font-display max-sm:text-sm sm:max-w-12",
color
? color.isDark()
? "text-white"
: "text-black"
: "text-foreground"
)}
>
{guild.name}
</div>
<CheckMark className="sm:hidden" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const ContributionCardView = ({
<div className="flex items-center gap-2 text-muted-foreground">
<Users weight="bold" className="min-w-min" />
<p className="line-clamp-1 text-sm">
Only {((role.memberCount / guild.memberCount) * 100).toFixed(1)}% of
members have this role
Only {((role.memberCount / guild.memberCount || 0) * 100).toFixed(1)}%
of members have this role
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const EditContributions = () => {
</DialogHeader>
<DialogBody className="gap-7">
<div className="flex flex-col gap-3">
{guilds?.length === 0 && (
{guilds && guilds.length === 0 && (
<Card className="flex gap-2 border border-destructive-subtle p-4 text-destructive-subtle">
<WarningCircle size={32} weight="fill" />
<h3 className="font-medium">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/Avatar"
import { Button } from "@/components/ui/Button"
import { Card } from "@/components/ui/Card"
import {
Dialog,
DialogBody,
Expand All @@ -28,17 +27,17 @@ import { useDisclosure } from "@/hooks/useDisclosure"
import { cn } from "@/lib/utils"
import { Schemas, schemas } from "@guildxyz/types"
import { zodResolver } from "@hookform/resolvers/zod"
import { Pencil, User } from "@phosphor-icons/react"
import { User } from "@phosphor-icons/react"
import useDropzone from "hooks/useDropzone"
import usePinata from "hooks/usePinata"
import { useState } from "react"
import { PropsWithChildren, useState } from "react"
import { FormProvider, useForm } from "react-hook-form"
import { useDeleteProfile } from "../../_hooks/useDeleteProfile"
import { useProfile } from "../../_hooks/useProfile"
import { useUpdateProfile } from "../../_hooks/useUpdateProfile"
import { EditProfileBanner } from "./EditProfileBanner"

export const EditProfile = () => {
export const EditProfile = ({ children }: PropsWithChildren<any>) => {
const { data: profile } = useProfile()
const form = useForm<Schemas["Profile"]>({
resolver: zodResolver(schemas.ProfileUpdateSchema),
Expand Down Expand Up @@ -92,14 +91,7 @@ export const EditProfile = () => {

return (
<Dialog onOpenChange={disclosure.setValue} open={disclosure.isOpen}>
<DialogTrigger asChild>
<Card className="absolute top-0 right-0 rounded-xl">
<Button variant="solid">
<Pencil weight="bold" />
Edit profile
</Button>
</Card>
</DialogTrigger>
<DialogTrigger asChild>{children}</DialogTrigger>
<FormProvider {...form}>
<DialogContent size="lg" className="bg-background" scrollBody>
<DialogHeader>
Expand Down
64 changes: 7 additions & 57 deletions src/app/(marketing)/profile/_components/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
"use client"

import { CheckMark } from "@/components/CheckMark"
import { useWeb3ConnectionManager } from "@/components/Web3ConnectionManager/hooks/useWeb3ConnectionManager"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/Avatar"
import { AvatarGroup } from "@/components/ui/AvatarGroup"
import { Card } from "@/components/ui/Card"
import { Separator } from "@/components/ui/Separator"
import { Skeleton } from "@/components/ui/Skeleton"
import { cn } from "@/lib/utils"
import { Info } from "@phosphor-icons/react"
import { PropsWithChildren } from "react"
Expand All @@ -17,65 +11,19 @@ import { RecentActivity } from "../_components/RecentActivity"
import { useContributions } from "../_hooks/useContributions"
import { useProfile } from "../_hooks/useProfile"
import { useReferredUsers } from "../_hooks/useReferredUsers"
import { EditProfile } from "./EditProfile/EditProfile"
import { ProfileSkeleton } from "./ProfileSkeleton"
import { ProfileMainSkeleton } from "./ProfileSkeleton"

export const Profile = () => {
const { data: profile } = useProfile()
const { data: contributions } = useContributions()
const { data: referredUsers } = useReferredUsers()
const { isWeb3Connected } = useWeb3ConnectionManager()

if (!profile || !contributions || !referredUsers) return <ProfileSkeleton />
if (!profile || !contributions || !referredUsers) return <ProfileMainSkeleton />

return (
<>
<div className="relative mb-12 flex flex-col items-center pt-12 md:mb-20 md:pt-14">
<ProfileOwnerGuard>
<EditProfile />
</ProfileOwnerGuard>
<div className="relative mb-6 flex items-center justify-center">
<Avatar className="size-40 md:size-48">
<AvatarImage
src={profile.profileImageUrl ?? ""}
alt="profile"
width={192}
height={192}
/>
<AvatarFallback>
<Skeleton className="size-full" />
</AvatarFallback>
</Avatar>
</div>
<h1 className="break-all text-center font-extrabold text-3xl leading-tight tracking-tight md:text-4xl">
{profile.name}
<CheckMark className="ml-2 inline size-6 fill-yellow-500 align-baseline" />
</h1>
<div className="font-medium text-muted-foreground">@{profile.username}</div>
<p className="mt-4 max-w-md text-pretty text-center text-lg text-muted-foreground md:mt-6">
{profile.bio}
</p>
<div className="mt-8 grid grid-cols-[repeat(3,auto)] gap-x-6 gap-y-4 sm:grid-cols-[repeat(5,auto)]">
<div className="flex flex-col items-center leading-tight">
<div className="font-bold md:text-lg">{referredUsers.length}</div>
<div className="text-muted-foreground">Guildmates</div>
</div>
<Separator orientation="vertical" className="h-10 md:h-12" />
<div className="flex flex-col items-center leading-tight">
<div className="font-bold md:text-lg">0</div>
<div className="text-muted-foreground">Followers</div>
</div>
<Separator orientation="vertical" className="hidden h-12 sm:block" />
<div className="col-span-3 flex items-center gap-2 place-self-center sm:col-span-1">
<AvatarGroup imageUrls={["", ""]} count={8} />
<div className="text-muted-foreground leading-tight">
Followed by <span className="font-bold">Hoho</span>,<br />
<span className="font-bold">Hihi</span> and 22 others
</div>
</div>
</div>
</div>
<div className="mb-3 flex items-center justify-between">
<div className="mb-3 flex items-center justify-between" data-theme="dark">
<SectionTitle>Top contributions</SectionTitle>
<ProfileOwnerGuard>
<EditContributions />
Expand All @@ -95,7 +43,7 @@ export const Profile = () => {
</div>
</Card>
)}
{contributions.map((contribution) => (
{contributions.slice(0, 3).map((contribution) => (
<ContributionCard contribution={contribution} key={contribution.id} />
))}
</div>
Expand All @@ -116,5 +64,7 @@ const SectionTitle = ({
className,
children,
}: PropsWithChildren<{ className?: string }>) => (
<h2 className={cn("font-bold sm:text-lg", className)}>{children}</h2>
<h2 className={cn("font-bold text-foreground sm:text-lg", className)}>
{children}
</h2>
)
86 changes: 86 additions & 0 deletions src/app/(marketing)/profile/_components/ProfileHero.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"use client"

import { CheckMark } from "@/components/CheckMark"
import { LayoutContainer } from "@/components/Layout"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/Avatar"
import { AvatarGroup } from "@/components/ui/AvatarGroup"
import { Button } from "@/components/ui/Button"
import { Card } from "@/components/ui/Card"
import { Separator } from "@/components/ui/Separator"
import { Skeleton } from "@/components/ui/Skeleton"
import { Pencil } from "@phosphor-icons/react"
import { ProfileOwnerGuard } from "../_components/ProfileOwnerGuard"
import { useProfile } from "../_hooks/useProfile"
import { useReferredUsers } from "../_hooks/useReferredUsers"
import { EditProfile } from "./EditProfile/EditProfile"
import { ProfileHeroSkeleton } from "./ProfileSkeleton"

export const ProfileHero = () => {
const { data: profile } = useProfile()
const { data: referredUsers } = useReferredUsers()

if (!profile || !referredUsers) return <ProfileHeroSkeleton />

return (
<LayoutContainer>
<div
className="relative flex flex-col items-center py-10 text-foreground md:py-20"
data-theme="dark"
>
<ProfileOwnerGuard>
<EditProfile>
<Card className="absolute top-3 right-0 rounded-xl md:top-8">
<Button
variant="solid"
className="max-sm:h-8 max-sm:px-3 max-sm:text-sm"
>
<Pencil weight="bold" />
Edit profile
</Button>
</Card>
</EditProfile>
</ProfileOwnerGuard>
<div className="relative mb-6 flex items-center justify-center">
<Avatar className="size-40 md:size-48">
<AvatarImage
src={profile.profileImageUrl ?? ""}
alt="profile"
width={192}
height={192}
/>
<AvatarFallback>
<Skeleton className="size-full" />
</AvatarFallback>
</Avatar>
</div>
<h1 className="break-all text-center font-extrabold text-3xl leading-tight tracking-tight md:text-4xl">
{profile.name}
<CheckMark className="ml-2 inline size-6 fill-yellow-500 align-baseline" />
</h1>
<div className="font-medium text-muted-foreground">@{profile.username}</div>
<p className="mt-4 max-w-md text-pretty text-center text-lg text-muted-foreground md:mt-6">
{profile.bio}
</p>
<div className="mt-8 grid grid-cols-[repeat(3,auto)] gap-x-6 gap-y-4 sm:grid-cols-[repeat(5,auto)]">
<div className="flex flex-col items-center leading-tight">
<div className="font-bold md:text-lg">{referredUsers.length}</div>
<div className="text-muted-foreground">Guildmates</div>
</div>
<Separator orientation="vertical" className="h-10 md:h-12" />
<div className="flex flex-col items-center leading-tight">
<div className="font-bold md:text-lg">0</div>
<div className="text-muted-foreground">Followers</div>
</div>
<Separator orientation="vertical" className="hidden h-12 sm:block" />
<div className="col-span-3 flex items-center gap-2 place-self-center sm:col-span-1">
<AvatarGroup imageUrls={["", ""]} count={8} />
<div className="text-muted-foreground leading-tight">
Followed by <span className="font-bold">Hoho</span>,<br />
<span className="font-bold">Hihi</span> and 22 others
</div>
</div>
</div>
</div>
</LayoutContainer>
)
}
Loading

0 comments on commit f4538d3

Please sign in to comment.