stacker.news/pages/referrals/[when].js

86 lines
2.7 KiB
JavaScript
Raw Normal View History

import { gql } from 'graphql-tag'
2022-12-19 22:27:52 +00:00
import Link from 'next/link'
import { useRouter } from 'next/router'
import { getGetServerSideProps } from '../../api/ssrApollo'
import { CopyInput, Form, Select } from '../../components/form'
import { CenterLayout } from '../../components/layout'
2022-12-19 22:27:52 +00:00
import { useMe } from '../../components/me'
import { WhenComposedChart } from '../../components/when-charts'
import { useQuery } from '@apollo/client'
import PageLoading from '../../components/page-loading'
import { WHENS } from '../../lib/constants'
2022-12-19 22:27:52 +00:00
const REFERRALS = gql`
query Referrals($when: String!)
{
referrals(when: $when) {
totalSats
totalReferrals
stats {
time
data {
name
value
2022-12-19 22:27:52 +00:00
}
}
}
}`
2022-12-19 22:27:52 +00:00
export const getServerSideProps = getGetServerSideProps(REFERRALS)
export default function Referrals ({ ssrData }) {
2022-12-19 22:27:52 +00:00
const router = useRouter()
const me = useMe()
const { data } = useQuery(REFERRALS, { variables: { when: router.query.when } })
if (!data && !ssrData) return <PageLoading />
2023-07-24 18:35:05 +00:00
const { referrals: { totalSats, totalReferrals, stats } } = data || ssrData
2022-12-19 22:27:52 +00:00
return (
<CenterLayout footerLinks>
2022-12-19 22:27:52 +00:00
<Form
initial={{
when: router.query.when
}}
>
2023-07-24 18:35:05 +00:00
<h4 className='fw-bold text-muted text-center pt-5 pb-3 d-flex align-items-center justify-content-center'>
2022-12-19 22:27:52 +00:00
{totalReferrals} referrals & {totalSats} sats in the last
<Select
2023-07-24 18:35:05 +00:00
groupClassName='mb-0 ms-2'
2022-12-19 22:27:52 +00:00
className='w-auto'
name='when'
size='sm'
items={WHENS}
2022-12-19 22:27:52 +00:00
onChange={(formik, e) => router.push(`/referrals/${e.target.value}`)}
/>
</h4>
</Form>
<WhenComposedChart data={stats} lineNames={['sats']} barNames={['referrals']} />
<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
placeholder={`https://stacker.news/r/${me.name}`}
/>
</div>
<ul className='py-3 text-muted'>
<li>{`appending /r/${me.name} to any SN link makes it a ref link`}
<ul>
<li>e.g. https://stacker.news/items/1/r/{me.name}</li>
</ul>
</li>
<li>earn 21% of boost and job fees spent by referred stackers</li>
2023-06-19 18:21:55 +00:00
<li>earn 2.1% of all zaps received by referred stackers</li>
<li><Link href='/invites'>invite links</Link> are also implicitly referral links</li>
2022-12-19 22:27:52 +00:00
</ul>
</CenterLayout>
2022-12-19 22:27:52 +00:00
)
}