Skip to content

Commit

Permalink
Merge pull request #167 from JumboCode/sburchfield33-johnny-t06-mailc…
Browse files Browse the repository at this point in the history
…himp

Sburchfield33 johnny t06 mailchimp
  • Loading branch information
johnny-t06 authored Apr 25, 2024
2 parents 2638552 + c8bf6f7 commit c66c226
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/unit-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ jobs:
GOOGLE_BASEFOLDER: ${{ secrets.GOOGLE_BASEFOLDER }}
GOOGLE_CLIENT_EMAIL: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
GOOGLE_PRIVATE_KEY: ${{ secrets.GOOGLE_PRIVATE_KEY }}
MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }}
MAILCHIMP_AUDIENCE_ID: ${{ secrets.MAILCHIMP_AUDIENCE_ID }}
161 changes: 159 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@fortawesome/react-fontawesome": "^0.2.0",
"@hookform/error-message": "^2.0.1",
"@hookform/resolvers": "^3.3.2",
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@material-tailwind/react": "^2.0.5",
"@next-auth/prisma-adapter": "^1.0.4",
"@prisma/client": "^5.5.2",
Expand All @@ -40,6 +41,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@types/mailchimp__mailchimp_marketing": "^3.0.20",
"@types/node": "18.0.0",
"@types/react": "18.0.14",
"@types/react-datepicker": "^6.0.1",
Expand Down
7 changes: 7 additions & 0 deletions src/app/api/emails/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { NextRequest, NextResponse } from "next/server";
import { Email, EmailResponse } from "./route.schema";
import { unknownErrorResponse } from "../route.schema";
import { prisma } from "@server/db/client";
import { mailchimp } from "@server/service";
import { env } from "@env/server.mjs";

export const POST = async (request: NextRequest) => {
try {
Expand Down Expand Up @@ -56,6 +58,11 @@ export const POST = async (request: NextRequest) => {
},
});

await mailchimp.lists.addListMember(env.MAILCHIMP_AUDIENCE_ID, {
email_address: body.email,
status: "subscribed",
});

return NextResponse.json(
EmailResponse.parse({
code: "SUCCESS",
Expand Down
2 changes: 2 additions & 0 deletions src/env/schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const serverSchema = z.object({
// https://github.com/orgs/vercel/discussions/219
// Parsing \n inserts \\n
GOOGLE_PRIVATE_KEY: z.string().transform((key) => key.replace(/\\n/g, "\n")),
MAILCHIMP_API_KEY: z.string(),
MAILCHIMP_AUDIENCE_ID: z.string(),
});

/**
Expand Down
8 changes: 8 additions & 0 deletions src/server/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { google } from "googleapis";
import { env } from "@env/server.mjs";
import mailchimp from "@mailchimp/mailchimp_marketing";

export const driveV3 = google.drive({
version: "v3",
Expand All @@ -11,3 +12,10 @@ export const driveV3 = google.drive({
scopes: ["https://www.googleapis.com/auth/drive"],
}),
});

mailchimp.setConfig({
apiKey: env.MAILCHIMP_API_KEY,
server: env.MAILCHIMP_API_KEY.split("-")[1],
});

export { mailchimp };

0 comments on commit c66c226

Please sign in to comment.