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.
- Loading branch information
1 parent
d5c1e85
commit 1fbfa96
Showing
13 changed files
with
333 additions
and
330 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,44 @@ | ||
'use server' | ||
|
||
import { z } from 'zod' | ||
|
||
import { env } from '~/env.mjs' | ||
import { withValidate } from '~/lib/validation' | ||
|
||
export const subscribeToNewsletter = withValidate( | ||
z.object({ | ||
email: z.string().email({ message: '邮箱地址不正确' }).nonempty(), | ||
}), | ||
async ({ email }) => { | ||
const url = [ | ||
'https://api.convertkit.com/v3', | ||
'forms', | ||
'5108903', // formId | ||
'subscribe', | ||
].join('/') | ||
|
||
const headers = new Headers({ | ||
'Content-Type': 'application/json; charset=utf-8', | ||
}) | ||
|
||
const res = await fetch(url, { | ||
method: 'POST', | ||
headers, | ||
cache: 'no-cache', | ||
body: JSON.stringify({ | ||
api_key: env.CONVERTKIT_API_KEY, | ||
email, | ||
tags: [ | ||
// cali.so newsletter tag | ||
3817600, | ||
// Chinese newsletter tag | ||
3817754, | ||
], | ||
}), | ||
}) | ||
|
||
if (!res.ok) { | ||
throw new Error('Failed to subscribe') | ||
} | ||
} | ||
) |
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 |
---|---|---|
@@ -1,16 +1,3 @@ | ||
type MdxFrontMatter = { | ||
title: string | ||
publishedAt: string | ||
tags: string[] | ||
image?: string | ||
summary?: string | ||
} | ||
type MDXComponent = { | ||
default: React.FC | ||
meta: MdxFrontMatter | ||
} | ||
|
||
declare module '*.mdx' { | ||
export default MDXComponent | ||
export const meta: MdxFrontMatter | ||
type NewsletterFormData = { | ||
email: string | ||
} |
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 was deleted.
Oops, something went wrong.
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,10 @@ | ||
import { type ZodSchema } from 'zod' | ||
|
||
export function withValidate<TData>( | ||
schema: ZodSchema<TData>, | ||
action: (data: TData) => void | ||
) { | ||
return (formData: FormData) => { | ||
return action(schema.parse(Object.fromEntries(formData.entries()))) | ||
} | ||
} |
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.