Skip to content

Commit

Permalink
feature(unlock-app): Refactored UI for attendee list (#13204)
Browse files Browse the repository at this point in the history
* support for multiple locks on the filter when showing attendee list

* updated filters handling

* more progress
  • Loading branch information
julien51 committed Jan 15, 2024
1 parent 5add818 commit 5aca488
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 126 deletions.
2 changes: 1 addition & 1 deletion packages/ui/lib/components/Collapse/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const Collapse = ({
</div>
</Button>
</div>
<div className="w-full">{content}</div>
{content}
</div>
{isOpen && <div className="p-4">{children}</div>}
</Card>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/lib/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const Select = <T extends unknown>({
</div>
</div>
</Listbox.Button>
<Listbox.Options className="absolute z-10 w-full mt-1 overflow-scroll bg-white border border-gray-400 rounded-xl max-h-[300px] outline-none">
<Listbox.Options className="absolute z-10 mt-1 overflow-scroll bg-white border border-gray-400 rounded-xl max-h-[300px] outline-none">
{options?.map((option: Option) => {
const hasAnyAppend = options?.some((option) => option.append)
const hasAnyPrepend = options?.some(
Expand Down
112 changes: 112 additions & 0 deletions unlock-app/src/components/content/event/attendees/AttendeeInfo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { Button, Detail } from '@unlock-protocol/ui'
import { useEffect, useState } from 'react'
import { ExpireAndRefundModal } from '~/components/interface/ExpireAndRefundModal'
import useEns from '~/hooks/useEns'
import { addressMinify } from '~/utils/strings'
import { BiCopy as CopyIcon } from 'react-icons/bi'
import useClipboard from 'react-use-clipboard'
import { ToastHelper } from '~/components/helpers/toast.helper'
import { Metadata } from '@unlock-protocol/core'

interface AttendeeInfoProps {
network: number
lockAddress: string
owner: string
token: string
metadata: Metadata
}

export const AttendeeInfo = ({
network,
lockAddress,
owner,
token,
metadata,
}: AttendeeInfoProps) => {
const [expireAndRefundOpen, setExpireAndRefundOpen] = useState(false)

const addressToEns = useEns(owner)
const resolvedAddress =
addressToEns === owner ? addressMinify(owner) : addressToEns
const addressToCopy = addressToEns === owner ? owner : addressToEns

const [isCopied, setCopied] = useClipboard(addressToCopy, {
successDuration: 2000,
})

useEffect(() => {
if (!isCopied) return
ToastHelper.success('Address copied')
}, [isCopied])

return (
<>
<ExpireAndRefundModal
network={network}
isOpen={expireAndRefundOpen}
setIsOpen={setExpireAndRefundOpen}
lockAddress={lockAddress}
keyOwner={owner}
tokenId={token}
/>

<div className="flex md:flex-row flex-col gap-4 space-between w-full">
<Detail label="#" valueSize="medium" className="w-8">
{token}
</Detail>

<Detail label="Full Name" valueSize="medium" className="grow w-24">
{metadata.fullname}
</Detail>

<Detail label="Email" valueSize="medium" className="grow w-32">
{metadata.email}
</Detail>

<Detail label="Wallet" valueSize="medium" className="grow">
<div className="flex self-start gap-2">
<div>{resolvedAddress}</div>
<div className="mt-auto">
<Button
variant="borderless"
onClick={setCopied}
aria-label="copy"
>
<CopyIcon size={20} />
</Button>
</div>
</div>
</Detail>

{/* {isManager && (
<div className="w-full col-span-3 gap-3 mx-auto md:mx-0 md:ml-auto md:col-span-2 md:w-auto">
{!refundDisabled && (
<Button
size="small"
variant="outlined-primary"
disabled={refundDisabled}
aria-label="refund"
onClick={() => {
if (refundDisabled) return
setExpireAndRefundOpen(true)
}}
>
Cancel
</Button>
)}
{canExtendKey && (
<Button
variant="outlined-primary"
size="small"
onClick={() => setExtendKeysOpen(true)}
className="mt-1"
>
Extend
</Button>
)}
</div>
)} */}
</div>
</>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { NotManagerBanner } from '~/components/interface/locks/Settings'
import { AirdropKeysDrawer } from '~/components/interface/members/airdrop/AirdropDrawer'
import { useEventOrganizer } from '~/hooks/useEventOrganizer'
import { Event, PaywallConfigType } from '@unlock-protocol/core'
import { MemberCard } from '~/components/interface/locks/Manage/elements/MemberCard'
import { AttendeeInfo } from './AttendeeInfo'

interface AttendeesProps {
event: Event
Expand All @@ -27,6 +29,11 @@ export const Attendees = ({ checkoutConfig }: AttendeesProps) => {
const [airdropKeys, setAirdropKeys] = useState(false)
const [loading, setLoading] = useState(false)
const router = useRouter()
const [lockAddress, setLockAddress] = useState(
checkoutConfig.config.locks
? Object.keys(checkoutConfig.config.locks)[0]
: null
)

const { data: isOrganizer, isLoading: isLoadingLockManager } =
useEventOrganizer({
Expand All @@ -43,15 +50,10 @@ export const Attendees = ({ checkoutConfig }: AttendeesProps) => {
const [page, setPage] = useState(1)

// Placeholders
const lockAddress = checkoutConfig.config.locks
? Object.keys(checkoutConfig.config.locks)[0]
: null
const lockNetwork = lockAddress
? checkoutConfig.config.locks[lockAddress].network
: null

console.log(lockAddress)

if (showNotManagerBanner) {
return <NotManagerBanner />
}
Expand Down Expand Up @@ -88,7 +90,11 @@ export const Attendees = ({ checkoutConfig }: AttendeesProps) => {
setIsOpen={setAirdropKeys}
/>
<FilterBar
hideFilter={true}
locks={checkoutConfig.config.locks}
lockAddress={lockAddress}
filters={filters}
setLockAddress={setLockAddress}
setFilters={setFilters}
setLoading={setLoading}
setPage={setPage}
Expand All @@ -101,7 +107,58 @@ export const Attendees = ({ checkoutConfig }: AttendeesProps) => {
loading={loading}
setPage={setPage}
page={page}
onAirdropKeys={() => setAirdropKeys(!airdropKeys)}
MemberCard={({
token,
owner,
expiration,
version,
metadata,
lockAddress,
network,
expirationDuration,
lockSettings,
}) => {
console.log(metadata)
return (
<MemberCard
token={token}
owner={owner}
expiration={expiration}
showExpiration={false}
version={version}
metadata={metadata}
lockAddress={lockAddress!}
network={network}
expirationDuration={expirationDuration}
lockSettings={lockSettings}
MemberInfo={() => (
<AttendeeInfo
network={network}
lockAddress={lockAddress}
owner={owner}
token={token}
metadata={metadata}
/>
)}
fieldsToShow={[
{
name: 'email',
label: 'Email',
},
{
name: 'fullname',
label: 'Full name',
},
]}
/>
)
}}
NoMemberNoFilter={() => {
return <p>No ticket minted from this contract yet!</p>
}}
NoMemberWithFilter={() => {
return <p>No ticket matches your filter.</p>
}}
/>
</div>
</div>
Expand Down
Loading

0 comments on commit 5aca488

Please sign in to comment.