2023-07-23 15:08:43 +00:00
|
|
|
import { gql } from 'graphql-tag'
|
2022-12-19 22:27:52 +00:00
|
|
|
import Link from 'next/link'
|
|
|
|
import { useRouter } from 'next/router'
|
2024-03-20 00:37:31 +00:00
|
|
|
import { getGetServerSideProps } from '@/api/ssrApollo'
|
|
|
|
import { CopyInput, Select, DatePicker } from '@/components/form'
|
|
|
|
import { CenterLayout } from '@/components/layout'
|
|
|
|
import { useMe } from '@/components/me'
|
2023-07-23 15:08:43 +00:00
|
|
|
import { useQuery } from '@apollo/client'
|
2024-03-20 00:37:31 +00:00
|
|
|
import PageLoading from '@/components/page-loading'
|
|
|
|
import { WHENS } from '@/lib/constants'
|
2023-07-24 22:50:12 +00:00
|
|
|
import dynamic from 'next/dynamic'
|
2024-03-20 00:37:31 +00:00
|
|
|
import { numWithUnits } from '@/lib/format'
|
|
|
|
import { whenToFrom } from '@/lib/time'
|
2024-03-23 03:47:21 +00:00
|
|
|
import { WhenComposedChartSkeleton } from '@/components/charts-skeletons'
|
2023-07-24 22:50:12 +00:00
|
|
|
|
2024-03-20 00:37:31 +00:00
|
|
|
const WhenComposedChart = dynamic(() => import('@/components/charts').then(mod => mod.WhenComposedChart), {
|
2024-03-23 03:47:21 +00:00
|
|
|
loading: () => <WhenComposedChartSkeleton />
|
2023-07-24 22:50:12 +00:00
|
|
|
})
|
2022-12-19 22:27:52 +00:00
|
|
|
|
2023-07-23 15:08:43 +00:00
|
|
|
const REFERRALS = gql`
|
2023-11-09 00:15:36 +00:00
|
|
|
query Referrals($when: String!, $from: String, $to: String)
|
2023-07-23 15:08:43 +00:00
|
|
|
{
|
2023-11-09 00:15:36 +00:00
|
|
|
referrals(when: $when, from: $from, to: $to) {
|
2024-07-11 00:23:05 +00:00
|
|
|
time
|
|
|
|
data {
|
|
|
|
name
|
|
|
|
value
|
2022-12-19 22:27:52 +00:00
|
|
|
}
|
2023-07-23 15:08:43 +00:00
|
|
|
}
|
|
|
|
}`
|
2022-12-19 22:27:52 +00:00
|
|
|
|
2023-08-28 17:52:15 +00:00
|
|
|
export const getServerSideProps = getGetServerSideProps({ query: REFERRALS, authRequired: true })
|
2023-07-23 15:08:43 +00:00
|
|
|
|
|
|
|
export default function Referrals ({ ssrData }) {
|
2022-12-19 22:27:52 +00:00
|
|
|
const router = useRouter()
|
2024-09-12 18:05:11 +00:00
|
|
|
const { me } = useMe()
|
2023-07-23 15:08:43 +00:00
|
|
|
|
2023-11-09 00:15:36 +00:00
|
|
|
const select = async values => {
|
|
|
|
const { when, ...query } = values
|
|
|
|
|
|
|
|
if (when !== 'custom') { delete query.from; delete query.to }
|
|
|
|
if (query.from && !query.to) return
|
|
|
|
|
|
|
|
await router.push({
|
|
|
|
pathname: `/referrals/${when}`,
|
|
|
|
query
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const { data } = useQuery(REFERRALS, { variables: { when: router.query.when, from: router.query.from, to: router.query.to } })
|
2023-07-23 15:08:43 +00:00
|
|
|
if (!data && !ssrData) return <PageLoading />
|
|
|
|
|
2024-07-11 00:23:05 +00:00
|
|
|
const { referrals } = data || ssrData
|
|
|
|
const totalSats = referrals.reduce(
|
|
|
|
(total, a) => total + a.data?.filter(d => d.name.endsWith('sats')).reduce(
|
|
|
|
(acc, d) => acc + d.value,
|
|
|
|
0),
|
|
|
|
0)
|
2023-07-23 15:08:43 +00:00
|
|
|
|
2023-11-09 00:15:36 +00:00
|
|
|
const when = router.query.when
|
|
|
|
|
2022-12-19 22:27:52 +00:00
|
|
|
return (
|
2023-07-23 15:08:43 +00:00
|
|
|
<CenterLayout footerLinks>
|
2023-11-09 00:15:36 +00:00
|
|
|
<div className='fw-bold text-muted text-center pt-5 pb-3 d-flex align-items-center justify-content-center flex-wrap'>
|
|
|
|
<h4 className='fw-bold text-muted text-center d-flex align-items-center justify-content-center'>
|
2024-07-11 00:23:05 +00:00
|
|
|
{numWithUnits(totalSats, { abbreviate: false })} in the last
|
2023-11-09 00:15:36 +00:00
|
|
|
<Select
|
|
|
|
groupClassName='mb-0 mx-2'
|
|
|
|
className='w-auto'
|
|
|
|
name='when'
|
|
|
|
size='sm'
|
|
|
|
items={WHENS}
|
|
|
|
value={router.query.when || 'day'}
|
|
|
|
noForm
|
|
|
|
onChange={(formik, e) => {
|
2023-11-14 16:23:44 +00:00
|
|
|
const range = e.target.value === 'custom' ? { from: whenToFrom(when), to: Date.now() } : {}
|
2023-11-09 00:15:36 +00:00
|
|
|
select({ when: e.target.value, ...range })
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</h4>
|
|
|
|
{when === 'custom' &&
|
|
|
|
<DatePicker
|
|
|
|
noForm
|
|
|
|
fromName='from'
|
|
|
|
toName='to'
|
2024-05-12 01:32:44 +00:00
|
|
|
className='p-0 px-2'
|
2023-11-09 00:15:36 +00:00
|
|
|
onChange={(formik, [from, to], e) => {
|
2023-11-14 16:23:44 +00:00
|
|
|
select({ when, from: from.getTime(), to: to.getTime() })
|
2023-11-09 00:15:36 +00:00
|
|
|
}}
|
|
|
|
from={router.query.from}
|
|
|
|
to={router.query.to}
|
|
|
|
when={router.query.when}
|
|
|
|
/>}
|
|
|
|
</div>
|
2024-07-11 00:23:05 +00:00
|
|
|
<WhenComposedChart
|
|
|
|
data={referrals}
|
|
|
|
areaNames={['referral sats', 'one day referral sats']}
|
|
|
|
barNames={['referrals', 'one day referrals']}
|
|
|
|
barAxis='right'
|
|
|
|
barStackId={1}
|
|
|
|
/>
|
2022-12-19 22:27:52 +00:00
|
|
|
|
|
|
|
<div
|
|
|
|
className='text-small pt-5 px-3 d-flex w-100 align-items-center'
|
|
|
|
>
|
2023-07-24 18:35:05 +00:00
|
|
|
<div className='nav-item text-muted pe-2' style={{ 'white-space': 'nowrap' }}>referral link:</div>
|
2022-12-19 22:27:52 +00:00
|
|
|
<CopyInput
|
|
|
|
size='sm'
|
|
|
|
groupClassName='mb-0 w-100'
|
|
|
|
readOnly
|
|
|
|
noForm
|
2024-04-08 22:54:39 +00:00
|
|
|
placeholder={`${process.env.NEXT_PUBLIC_URL}/r/${me.name}`}
|
2022-12-19 22:27:52 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<ul className='py-3 text-muted'>
|
2024-07-11 00:23:05 +00:00
|
|
|
<li>earn 10% of a stacker's <Link href='/rewards'>rewards</Link> in perpetuity if they sign up from your referral links</li>
|
2024-07-11 16:55:19 +00:00
|
|
|
<li>in addition, earn 10% of a stacker's <Link href='/rewards'>rewards</Link> for the day if they follow your referral links the most that day</li>
|
2024-07-11 00:23:05 +00:00
|
|
|
<li>nearly all sn links are referral links:
|
2022-12-19 22:27:52 +00:00
|
|
|
<ul>
|
2024-07-11 00:23:05 +00:00
|
|
|
<li>your profile link is an implicit referral link</li>
|
|
|
|
<li>all links to post and comments are implicit referral links attributed to the OP</li>
|
|
|
|
<li>links to territories are implicit referral links attributed to the territory founder</li>
|
2022-12-19 22:27:52 +00:00
|
|
|
</ul>
|
|
|
|
</li>
|
2024-07-11 00:23:05 +00:00
|
|
|
<li>appending /r/{me.name} to any SN link makes it a ref link to {me.name}</li>
|
2023-07-23 15:08:43 +00:00
|
|
|
<li><Link href='/invites'>invite links</Link> are also implicitly referral links</li>
|
2022-12-19 22:27:52 +00:00
|
|
|
</ul>
|
2023-07-23 15:08:43 +00:00
|
|
|
</CenterLayout>
|
2022-12-19 22:27:52 +00:00
|
|
|
)
|
|
|
|
}
|