Skip to content

Commit

Permalink
updated vercel functions to javascript code
Browse files Browse the repository at this point in the history
updated install instructions for different platforms
  • Loading branch information
Oba-One committed Sep 1, 2024
1 parent 49f51f0 commit 26f9e30
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 58 deletions.
38 changes: 38 additions & 0 deletions packages/client/api/subscribe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
export default async function handler(req, res) {
if (req.method === "POST") {
const { email } = req.body;

const mailchimpUrl = `https://app.us13.list-manage.com/subscribe/post?u=16db3a1a92dd56e81459cd500&id=c6c12d1a3f&f_id=0021fae1f0`;

const data = new URLSearchParams();
data.append("EMAIL", email);
data.append("b_16db3a1a92dd56e81459cd500_c6c12d1a3f", ""); // hidden input to prevent bot signups

try {
const response = await fetch(mailchimpUrl, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: data.toString(),
});

if (response.ok) {
res
.status(200)
.json({ success: true, message: "Subscription successful!" });
} else {
res
.status(response.status)
.json({ success: false, message: "Subscription failed." });
}
} catch (error) {
res
.status(500)
.json({ success: false, message: "Internal Server Error" });
}
} else {
res.setHeader("Allow", ["POST"]);
res.status(405).end(`Method ${req.method} Not Allowed`);
}
}
28 changes: 28 additions & 0 deletions packages/client/api/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { PrivyClient } = require("@privy-io/server-auth");
// import type { VercelRequest, VercelResponse } from "@vercel/node";

// declare global {
// namespace NodeJS {
// interface ProcessEnv {
// VITE_PRIVY_APP_ID?: string;
// PINATA_API_KEY?: string;
// PINATA_API_SECRET?: string;
// PRIVY_APP_SECRET_ID?: string;
// }
// }
// }

export const config = {
// runtime: "nodejs",
};

const privy = new PrivyClient(
process.env.VITE_PRIVY_APP_ID,
process.env.PRIVY_APP_SECRET_ID
);

export default async function handler(_request, response) {
const users = await privy.getUsers();

response.status(200).json(users);
}
31 changes: 0 additions & 31 deletions packages/client/api/users.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/client/dev-dist/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ define(['./workbox-c982e567'], (function (workbox) { 'use strict';
"revision": "3ca0b8505b4bec776b69afdba2768812"
}, {
"url": "index.html",
"revision": "0.9bt3crbamtg"
"revision": "0.bah1ak7v75o"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/Layout/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface FooterProps {}

export const Footer: React.FC<FooterProps> = () => {
return (
<footer className="footer h-[5rem] border-stone-200 flex flex-col gap-2 py-2 lg:flex-row items-center justify-between lg:gap-4">
<footer className="h-[5rem] flex flex-col gap-2 py-2 lg:flex-row items-center justify-between lg:gap-4">
<div className="">
<p>
Built by <b className="text-[#367D42]">Greenpill Dev Guild</b>
Expand Down
49 changes: 24 additions & 25 deletions packages/client/src/components/Layout/Hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,38 @@ import toast from "react-hot-toast";

type SubscribeState = "idle" | "subscribing" | "subscribed" | "error";

const url =
"https://app.us13.list-manage.com/subscribe/post?u=16db3a1a92dd56e81459cd500&amp;id=c6c12d1a3f&amp;f_id=0021fae1f0";

export const Hero: React.FC = () => {
const { isMobile } = usePWA();
const { isMobile, platform } = usePWA();
const [state, setSubscribeState] = useState<SubscribeState>("idle");

function handleSubscribe(e: React.FormEvent<HTMLFormElement>) {
e.preventDefault();

setSubscribeState("subscribing");

console.log(e.currentTarget);
const formData = new FormData(e.currentTarget);
const email = formData.get("email") as string;

console.log(email);

fetch(url + "&" + formData, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
mode: "cors",
cache: "default",
})
.then((response) => response.json())
.then((data) => {
if (data["result"] !== "success") {
fetch(
import.meta.env.DEV ?
"http://localhost:3000/api/subscribe"
: "/api/subscribe",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ email }),
}
)
.then((response) => {
if (!response.ok) {
// ERROR
console.log(data["msg"]);
console.log(response.status);

throw new Error(data["msg"]);
throw new Error("Network response was not ok.");
} else {
// SUCCESS - Show notification
console.log(data["msg"]);

toast.success("Successfilly subscribed!");

setSubscribeState("subscribed");
Expand All @@ -56,7 +52,7 @@ export const Hero: React.FC = () => {
}

return (
<main className="w-full min-h-[calc(100dvh-9rem)] lg:min-h-[calc(100dvh-6rem)] flex flex-col lg:flex-row lg:justify-center gap-16">
<main className="w-full min-h-[calc(100lvh-9rem)] lg:min-h-[calc(100lvh-6rem)] flex flex-col lg:flex-row lg:justify-center gap-16">
<form
onSubmit={handleSubscribe}
className="flex-1 flex flex-col gap-2 items-center lg:items-start lg:justify-center pt-[10vh] lg:pt-0 text-center lg:text-left"
Expand Down Expand Up @@ -106,8 +102,11 @@ export const Hero: React.FC = () => {
<div className="modal-box">
<h4 className="text-[#367D42]">Install Green Goods</h4>
<p>
To install on your device, tap the 3 dots below and then "Add
to Home Screen".
{platform === "ios" ?
"Tap the share button and then 'Add to Home Screen'."
: platform === "android" ?
"Tap the menu button and then 'Add to Home Screen'."
: "Tap the menu button and then 'Add to Home Screen'."}
</p>
</div>
<form method="dialog" className="modal-backdrop">
Expand Down

1 comment on commit 26f9e30

@vercel
Copy link

@vercel vercel bot commented on 26f9e30 Sep 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.