feat: prototype of referral system in console #142
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.
Summary
This PR spikes out a referral system that stores data in Cloudflare's D1. It allows anonymous or logged-in users to create referral codes associated with their email addresses, and records the referral code a user used to sign up for an account. It does not implement the discounts and other rewards associated with the referral system - these are expected to be handled manually in the first released version and implemented as automated systems later, so are a non-goal of this PR.
Referral System Design
We use Cloudflare's D1 database for simplicity, since we already deploy this application via Cloudflare Pages. Two tables are used:
users
andreferrals
.users
is used to store refcodes for users (identified by email address).referrals
is used to record the refcode used by a user (identified by email address) during signup. Separate tables are used to avoid mutating rows in the database - a simple, immutable system is generally easier to maintain and reason about and while immutability of database tables isn't a hard requirement, it is a property this design strives to maintain.Operational Notes
In order to use D1 in development, the app must be run using
@cloudflare/next-on-pages
. Thepages:dev
script already used this. Unfortunately, this does not support hot-reloading, so we've addedpages:build
to that step to ensure the latest code is always used whenpages:dev
is run.Developers who are NOT working on the referrals system should continue to use the
dev
script rather than thepages:dev
script as it provides a better user experience.We also introduce a set of scripts prefixed with
referrals:db:local
that make it relatively simple to maintain a local D1 database for development.User Experience
We are working with a UX designer toward professional designs and user experience - the UI and UX as currently implemented are temporary and do not need feedback yet.
TODOs