From 3d86e68a9fc7e7b52d9ffc193ae45d931ca3bc6b Mon Sep 17 00:00:00 2001 From: Nicholas Charriere Date: Sat, 27 Jul 2024 16:06:58 -0700 Subject: [PATCH] Add optional email + send from API to avoid CORS --- packages/api/server/http.mts | 17 +++++++++++++++++ packages/web/src/components/feedback-dialog.tsx | 16 +++++++++++++--- packages/web/src/lib/server.ts | 17 +++++++++++++++++ packages/web/src/lib/utils.ts | 15 --------------- 4 files changed, 47 insertions(+), 18 deletions(-) diff --git a/packages/api/server/http.mts b/packages/api/server/http.mts index 795ae3da..59f7ce93 100644 --- a/packages/api/server/http.mts +++ b/packages/api/server/http.mts @@ -272,6 +272,23 @@ router.delete('/secrets/:name', cors(), async (req, res) => { return res.json({ result: updated }); }); +router.options('/feedback', cors()); +router.post('/feedback', cors(), async (req, res) => { + const { feedback, email } = req.body; + // Every time you modify the appscript here, you'll need to update the URL below + // @TODO: once we have an env variable setup, we can use that here. + const url = + 'https://script.google.com/macros/s/AKfycbxPrg8z47SkJnHyoZBYqNtkcH8hBe12f-f2UJJ3PcIHmKdbMMuJuPoOemEB1ib8a_IKCg/exec'; + + const result = await fetch(url, { + method: 'POST', + body: JSON.stringify({ feedback, email }), + headers: { 'Content-Type': 'text/plain;charset=utf-8' }, + }); + + return res.json({ success: result.ok }); +}); + type NpmSearchResult = { package: { name: string; diff --git a/packages/web/src/components/feedback-dialog.tsx b/packages/web/src/components/feedback-dialog.tsx index e7dbb582..c2d274d4 100644 --- a/packages/web/src/components/feedback-dialog.tsx +++ b/packages/web/src/components/feedback-dialog.tsx @@ -1,7 +1,8 @@ import { useState } from 'react'; -import { sendFeedback } from '@/lib/utils'; +import { sendFeedback } from '@/lib/server'; import { toast } from 'sonner'; import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; import { Dialog, DialogContent, @@ -19,6 +20,8 @@ export default function FeedbackDialog({ onOpenChange: (open: boolean) => void; }) { const [feedback, setFeedback] = useState(''); + const [email, setEmail] = useState(''); + return ( @@ -27,7 +30,7 @@ export default function FeedbackDialog({

- We're always looking to improve Srcbook, and your feedback is invaluable. + We're always looking to improve Srcbook and your feedback is invaluable.
You can open a public{' '} setFeedback(e.target.value)} /> + setEmail(e.target.value)} + />