-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: prototype of referral system in console #142
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
a5f28c5
wip: referrals
travis f90eda3
feat: shift to just regular route handlers for referral api
travis 2bc5ed2
fix: remove console.log
travis 016ca71
feat: add rewards section to settings page
travis 741eb78
fix: move some styles to the normal tailwind customization system
travis 66e1026
fix: get referral and settings pages looking right
travis 1f6c1fa
fix: move referrals hook
travis ccdefc1
feat: add new pricing table with free trial
travis 64c1f08
feat: add email back to authentication submitted page
travis 177f244
Merge remote-tracking branch 'origin/main' into feat/referral-program
travis a33b008
fix: remove extra handler
travis c180795
feat: move referrals service out
travis 8591b4d
revert package.json to main
travis 972f8b6
revert pnpm-lock from main
travis 7f9a2d1
feat: various improvements
travis f82f7e9
fix: loader size and color
travis e1bc9f6
fix: configure referrals URLs
travis 8a10563
Merge branch 'main' into feat/referral-program
travis b0a59b3
fix: yaml syntax error
travis 5839e8e
Merge remote-tracking branch 'refs/remotes/origin/feat/referral-progr…
travis 02c61c2
chore: add console.log for easier debugging in the preview env
travis cab9fd0
chore: more preview env debugging
travis 6c80086
fix: try to fix preview env
travis 27fe789
fix: I did React wrong
travis fdb6f3f
fix: get referral page working as expected
travis de6e0aa
fix: configure trial pricing table ID in preview
travis c1444c0
fix: deploy scripts and a bugfix in the hooks
travis 47ba373
chore: remove unused code
travis 3be95ed
feat: feature flag settings page referral UI
travis aa53fe1
Update src/app/referrals/page.tsx
travis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
'use client' | ||
|
||
import CopyButton from '@/components/CopyButton' | ||
import DefaultLoader from '@/components/Loader' | ||
import { H1, H3 } from '@/components/Text' | ||
import { RefcodeResult, useReferrals } from '@/lib/referrals/hooks' | ||
import { useEffect } from 'react' | ||
import { KeyedMutator } from 'swr' | ||
|
||
export const runtime = "edge" | ||
|
||
export function RefcodeCreator ({ | ||
accountEmail, | ||
urlQueryEmail, | ||
createRefcode, | ||
mutateRefcode, | ||
setReferrerEmail | ||
}: { | ||
accountEmail: string | ||
urlQueryEmail: string | null | ||
createRefcode: (form: FormData) => Promise<Response> | ||
mutateRefcode: KeyedMutator<RefcodeResult> | ||
setReferrerEmail: (email: string) => void | ||
} | ||
) { | ||
const prefilledEmail = urlQueryEmail || accountEmail | ||
useEffect(function () { | ||
if (prefilledEmail) { | ||
(async () => { | ||
const form = new FormData() | ||
form.append('email', prefilledEmail) | ||
await createRefcode(form) | ||
await mutateRefcode() | ||
})() | ||
} | ||
}, [prefilledEmail]) | ||
return ( | ||
<> | ||
{ | ||
prefilledEmail ? ( | ||
<DefaultLoader className="w-6 h-6 color-hot-red" /> | ||
) : ( | ||
<form onSubmit={async (e) => { | ||
e.preventDefault() | ||
try { | ||
const form = new FormData(e.currentTarget) | ||
const email = form.get('email') | ||
if (email){ | ||
setReferrerEmail(email.toString()) | ||
await createRefcode(form) | ||
} else { | ||
console.log("email was undefined, this is strange!") | ||
} | ||
} finally { | ||
// mutate here to pick up any changes from either create or set | ||
mutateRefcode() | ||
} | ||
}} className=''> | ||
<label className='block mb-2 uppercase text-xs text-hot-red font-epilogue m-1' htmlFor='email'>Your Email</label> | ||
<input | ||
id='email' | ||
name='email' | ||
type='email' | ||
className='text-black py-2 px-2 rounded-xl block mb-4 border border-hot-red w-80' | ||
placeholder='Email' | ||
defaultValue={urlQueryEmail || ''} | ||
required={true} | ||
/> | ||
<button type='submit' className={`inline-block bg-hot-red border border-hot-red hover:bg-white hover:text-hot-red font-epilogue text-white uppercase text-sm px-6 py-2 rounded-full whitespace-nowrap`}> | ||
Create | ||
</button> | ||
</form> | ||
) | ||
} | ||
</> | ||
) | ||
} | ||
|
||
export function RefcodeLink ({ referralLink }: { referralLink: string }) { | ||
return ( | ||
<div className="border border-hot-red rounded-full px-4 py-2 flex flex-row justify-between items-center"> | ||
<div>{referralLink}</div> | ||
<CopyButton text={referralLink} /> | ||
</div> | ||
) | ||
} | ||
|
||
export function ReferralsList () { | ||
const { referrals } = useReferrals() | ||
return ( | ||
(referrals && referrals.length > 0) ? ( | ||
<> | ||
<H3>Referrals</H3> | ||
<div className="divide-solid divide-hot-red py-4"> | ||
{ | ||
/** | ||
* TODO: once we can determine when a user signed up and what plan they signed up for, update | ||
* this UI to differentiate between them with different names and give users a countdown timer | ||
* in the lozenge. | ||
*/ | ||
referrals.map((referral, i) => | ||
<div key={i} className="flex flex-row justify-between items-center py-4"> | ||
<div>Referred Racha</div> | ||
<div className="rounded-full bg-hot-red-light text-hot-red px-4 py-2 font-mono text-sm">In Progress</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
</> | ||
) : ( | ||
<> | ||
<H3>Earn Free Storage and Racha Points!</H3> | ||
<p className='text-hot-red mb-4 max-w-lg'> | ||
Turn your friends into Lite or Business Rachas and receive up to 16 months of Lite or | ||
3 months of Business for free! You can also earn Racha Points. | ||
</p> | ||
</> | ||
) | ||
) | ||
} | ||
|
||
export default function ReferralsPage () { | ||
const { refcodeIsLoading, referralLink, setReferrerEmail, accountEmail, urlQueryEmail, createRefcode, mutateRefcode, } = useReferrals() | ||
return ( | ||
<div className='p-10 bg-racha-fire/50 w-full h-screen'> | ||
<H1>Generate a Referral Code</H1> | ||
<div className='border border-hot-red rounded-2xl bg-white p-5'> | ||
{refcodeIsLoading ? ( | ||
<DefaultLoader className="text-hot-red h-6 w-6" /> | ||
) : ( | ||
<> | ||
<ReferralsList /> | ||
{referralLink ? ( | ||
<RefcodeLink referralLink={referralLink} /> | ||
) : ( | ||
<RefcodeCreator | ||
accountEmail={accountEmail} | ||
urlQueryEmail={urlQueryEmail} | ||
createRefcode={createRefcode} | ||
mutateRefcode={mutateRefcode} | ||
setReferrerEmail={setReferrerEmail} /> | ||
)} | ||
</> | ||
)} | ||
</div> | ||
</div > | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: read it from env.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yea - I'm going to come back to this once we have support for actually giving people credits and displaying them - will move to config once that's done!