From e82895351d476419fdecff08e45600c3cb4c5667 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Mon, 12 Feb 2024 18:18:25 +0000 Subject: [PATCH 1/4] Published the tickets POST route --- next.config.js | 18 +++++++++++++++++- src/pages/api/tickets/index.ts | 20 ++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/next.config.js b/next.config.js index 4a6bb16f..771f71d2 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,5 @@ /** @type {import('next').NextConfig} */ +const websiteUrl = process.env.NODE_ENV === 'production' ? "https://encoach.com" : "http://localhost:3000"; const nextConfig = { reactStrictMode: true, output: "standalone", @@ -8,7 +9,7 @@ const nextConfig = { source: "/api/packages", headers: [ {key: "Access-Control-Allow-Credentials", value: "false"}, - {key: "Access-Control-Allow-Origin", value: "https://encoach.com"}, + {key: "Access-Control-Allow-Origin", value: websiteUrl}, { key: "Access-Control-Allow-Methods", value: "GET", @@ -19,6 +20,21 @@ const nextConfig = { }, ], }, + { + source: "/api/tickets", + headers: [ + {key: "Access-Control-Allow-Credentials", value: "false"}, + {key: "Access-Control-Allow-Origin", value: websiteUrl}, + { + key: "Access-Control-Allow-Methods", + value: "POST,OPTIONS", + }, + { + key: "Access-Control-Allow-Headers", + value: "Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date", + }, + ], + }, ]; }, }; diff --git a/src/pages/api/tickets/index.ts b/src/pages/api/tickets/index.ts index 009ed4b9..04f0b6b7 100644 --- a/src/pages/api/tickets/index.ts +++ b/src/pages/api/tickets/index.ts @@ -20,13 +20,25 @@ const db = getFirestore(app); export default withIronSessionApiRoute(handler, sessionOptions); async function handler(req: NextApiRequest, res: NextApiResponse) { + // due to integration with the homepage the POST request should be public + if (req.method === "POST") { + await post(req, res); + return; + } + + // specific logic for the preflight request + if (req.method === "OPTIONS") { + res.status(200).end(); + return; + } if (!req.session.user) { res.status(401).json({ ok: false }); return; } - if (req.method === "GET") await get(req, res); - if (req.method === "POST") await post(req, res); + if (req.method === "GET") { + await get(req, res); + } } async function get(req: NextApiRequest, res: NextApiResponse) { @@ -36,7 +48,7 @@ async function get(req: NextApiRequest, res: NextApiResponse) { snapshot.docs.map((doc) => ({ id: doc.id, ...doc.data(), - })), + })) ); } @@ -61,7 +73,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) { description: body.description, }, [body.reporter.email], - `Ticket ${id}: ${body.subject}`, + `Ticket ${id}: ${body.subject}` ); } catch (e) { console.log(e); From 17ec004a5955bb92fcbf944e2ef2eefe6aa48600 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Mon, 12 Feb 2024 21:45:37 +0000 Subject: [PATCH 2/4] Added checkbox for accepted terms --- src/hooks/useAcceptedTerms.tsx | 32 +++++++++++++++++++++ src/pages/(register)/RegisterCorporate.tsx | 6 +++- src/pages/(register)/RegisterIndividual.tsx | 9 ++++-- 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/hooks/useAcceptedTerms.tsx diff --git a/src/hooks/useAcceptedTerms.tsx b/src/hooks/useAcceptedTerms.tsx new file mode 100644 index 00000000..c77c0067 --- /dev/null +++ b/src/hooks/useAcceptedTerms.tsx @@ -0,0 +1,32 @@ +import React from "react"; +import Link from "next/link"; +import Checkbox from "@/components/Low/Checkbox"; + +const useAcceptedTerms = () => { + const [acceptedTerms, setAcceptedTerms] = React.useState(false); + + const renderCheckbox = () => ( + + I agree to the + + {" "} + Terms and Conditions + {" "} + and + + {" "} + Privacy Policy + + + ); + + return { acceptedTerms, renderCheckbox }; +}; + +export default useAcceptedTerms; \ No newline at end of file diff --git a/src/pages/(register)/RegisterCorporate.tsx b/src/pages/(register)/RegisterCorporate.tsx index 46d6a54b..1992e667 100644 --- a/src/pages/(register)/RegisterCorporate.tsx +++ b/src/pages/(register)/RegisterCorporate.tsx @@ -10,6 +10,7 @@ import { toast } from "react-toastify"; import { KeyedMutator } from "swr"; import Select from "react-select"; import moment from "moment"; +import useAcceptedTerms from "@/hooks/useAcceptedTerms"; interface Props { isLoading: boolean; @@ -40,6 +41,7 @@ export default function RegisterCorporate({ const [companyName, setCompanyName] = useState(""); const [companyUsers, setCompanyUsers] = useState(0); const [subscriptionDuration, setSubscriptionDuration] = useState(1); + const {acceptedTerms, renderCheckbox} = useAcceptedTerms(); const { users } = useUsers(); @@ -257,7 +259,9 @@ export default function RegisterCorporate({ /> - +
+ {renderCheckbox()} +