forked from CaliCastle/cali.so
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement newsletter confirm page
- Loading branch information
1 parent
c4ae2ff
commit 9e99377
Showing
15 changed files
with
806 additions
and
26 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
import { useReward } from 'react-rewards' | ||
|
||
export function SubbedCelebration() { | ||
const { reward } = useReward('subbed-celebration', 'confetti', { | ||
position: 'absolute', | ||
elementCount: 160, | ||
spread: 80, | ||
elementSize: 8, | ||
lifetime: 400, | ||
}) | ||
|
||
React.useEffect(() => { | ||
setTimeout(() => reward(), 500) | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []) | ||
|
||
return <div className="pb-16"></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { eq } from 'drizzle-orm' | ||
import { redirect } from 'next/navigation' | ||
|
||
import { Container } from '~/components/ui/Container' | ||
import { db } from '~/db' | ||
import { subscribers } from '~/db/schema' | ||
|
||
import { SubbedCelebration } from './SubbedCelebration' | ||
|
||
export default async function ConfirmPage({ | ||
params, | ||
}: { | ||
params: { token: string } | ||
}) { | ||
const [subscriber] = await db | ||
.select() | ||
.from(subscribers) | ||
.where(eq(subscribers.token, params.token)) | ||
|
||
if (!subscriber || subscriber.subscribedAt) { | ||
redirect('/') | ||
} | ||
|
||
await db | ||
.update(subscribers) | ||
.set({ subscribedAt: new Date() }) | ||
.where(eq(subscribers.id, subscriber.id)) | ||
|
||
return ( | ||
<Container className="mt-16 sm:mt-32"> | ||
<header className="relative mx-auto flex w-full max-w-2xl items-center justify-center"> | ||
<h1 | ||
className="w-full text-center text-4xl font-bold tracking-tight text-zinc-800 dark:text-zinc-100 sm:text-5xl" | ||
id="subbed-celebration" | ||
> | ||
🥳 感谢你的订阅 🎉 | ||
</h1> | ||
<p className="mt-6 text-base text-zinc-600 dark:text-zinc-400"></p> | ||
</header> | ||
<SubbedCelebration /> | ||
</Container> | ||
) | ||
} |
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,13 @@ | ||
import { connect } from '@planetscale/database' | ||
import { drizzle } from 'drizzle-orm/planetscale-serverless' | ||
|
||
import { env } from '~/env.mjs' | ||
|
||
// create the connection | ||
const connection = connect({ | ||
host: env.DATABASE_HOST, | ||
username: env.DATABASE_USERNAME, | ||
password: env.DATABASE_PASSWORD, | ||
}) | ||
|
||
export const db = drizzle(connection) |
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,5 @@ | ||
CREATE TABLE `subscribers` ( | ||
`cuid` text PRIMARY KEY NOT NULL, | ||
`email` varchar(120), | ||
`token` varchar(50), | ||
`subscribed_at` datetime); |
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,2 @@ | ||
ALTER TABLE `subscribers` RENAME COLUMN `cuid` TO `id`; | ||
ALTER TABLE `subscribers` MODIFY COLUMN `id` serial AUTO_INCREMENT NOT NULL; |
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,50 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "mysql", | ||
"id": "3758b424-2adb-4fc1-aff6-8409ceea1931", | ||
"prevId": "00000000-0000-0000-0000-000000000000", | ||
"tables": { | ||
"subscribers": { | ||
"name": "subscribers", | ||
"columns": { | ||
"cuid": { | ||
"name": "cuid", | ||
"type": "text", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"email": { | ||
"name": "email", | ||
"type": "varchar(120)", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"token": { | ||
"name": "token", | ||
"type": "varchar(50)", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"subscribed_at": { | ||
"name": "subscribed_at", | ||
"type": "datetime", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {} | ||
} | ||
}, | ||
"schemas": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
} | ||
} |
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,52 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "mysql", | ||
"id": "11f232f1-7994-4e6a-b58c-7b4587981bdc", | ||
"prevId": "3758b424-2adb-4fc1-aff6-8409ceea1931", | ||
"tables": { | ||
"subscribers": { | ||
"name": "subscribers", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": true | ||
}, | ||
"email": { | ||
"name": "email", | ||
"type": "varchar(120)", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"token": { | ||
"name": "token", | ||
"type": "varchar(50)", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"subscribed_at": { | ||
"name": "subscribed_at", | ||
"type": "datetime", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {} | ||
} | ||
}, | ||
"schemas": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": { | ||
"\"subscribers\".\"cuid\"": "\"subscribers\".\"id\"" | ||
} | ||
} | ||
} |
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,20 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "mysql", | ||
"entries": [ | ||
{ | ||
"idx": 0, | ||
"version": "5", | ||
"when": 1685604945558, | ||
"tag": "0000_sweet_king_cobra", | ||
"breakpoints": false | ||
}, | ||
{ | ||
"idx": 1, | ||
"version": "5", | ||
"when": 1685606673974, | ||
"tag": "0001_worried_crystal", | ||
"breakpoints": false | ||
} | ||
] | ||
} |
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,8 @@ | ||
import { datetime, mysqlTable, serial, varchar } from 'drizzle-orm/mysql-core' | ||
|
||
export const subscribers = mysqlTable('subscribers', { | ||
id: serial('id').primaryKey(), | ||
email: varchar('email', { length: 120 }), | ||
token: varchar('token', { length: 50 }), | ||
subscribedAt: datetime('subscribed_at'), | ||
}) |
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,9 @@ | ||
import * as dotenv from 'dotenv' | ||
import type { Config } from 'drizzle-kit' | ||
dotenv.config() | ||
|
||
export default { | ||
schema: './db/schema.ts', | ||
out: './db/migrations', | ||
connectionString: process.env.DATABASE_URL, | ||
} satisfies Config |
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.