From 9b85cfcb6928a9bcef4882ebe3576de3e2c0e517 Mon Sep 17 00:00:00 2001 From: Amanda Date: Sat, 25 Nov 2023 15:18:09 +0000 Subject: [PATCH 1/4] create non-linked card and modal placeholder --- pages/account/onboarding/index.js | 42 ++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/pages/account/onboarding/index.js b/pages/account/onboarding/index.js index 3c5542cd941..6f6e1c8b3ef 100644 --- a/pages/account/onboarding/index.js +++ b/pages/account/onboarding/index.js @@ -2,6 +2,7 @@ import { authOptions } from "../../api/auth/[...nextauth]"; import { getServerSession } from "next-auth/next"; import { useRouter } from "next/router"; import { useSession } from "next-auth/react"; +import { useState } from "react"; import { FaGithub, FaLink, @@ -10,6 +11,7 @@ import { FaTent, FaCertificate, FaArrowUpRightFromSquare, + FaTriangleExclamation, } from "react-icons/fa6"; import logger from "@config/logger"; @@ -19,6 +21,7 @@ import { getUserApi } from "pages/api/profiles/[username]"; import { PROJECT_NAME } from "@constants/index"; import Card from "@components/Card"; import Button from "@components/Button"; +import Modal from "@components/Modal"; import Navigation from "@components/account/manage/Navigation"; import ProgressBar from "@components/statistics/ProgressBar"; import Alert from "@components/Alert"; @@ -46,6 +49,7 @@ export async function getServerSideProps(context) { "testimonials", "events", "repos", + "delete" ]; let progress = { percentage: 0, @@ -82,6 +86,7 @@ export default function Onboarding({ profile, progress }) { router.push("/api/stripe"); } } + const [showModal, setShowModal] = useState(false); const cards = [ { @@ -144,6 +149,16 @@ export default function Onboarding({ profile, progress }) { }, isEdit: profile.milestones && profile.milestones.length > 0, }, + { + icon: FaTriangleExclamation, + title: "Delete Account", + description: "Delete your account", + button: { + name: "Delete Account", + href:"/account/manage/milestones" + }, + click: true, + }, ]; const alerts = { @@ -198,17 +213,36 @@ export default function Onboarding({ profile, progress }) { > {cards.map((card) => (
  • + {card.click ? +
    +
    + +

    {card.title}

    +
    +

    {card.description}

    + + + + Hello Modal! + + +
    + :

    {card.title}

    {card.description}

    - {card.isEdit && } - {!card.isEdit && ( - - )} + {card.isEdit ? + : + }
    +}
  • ))} From 3cb69bfee4239f0d2dfeaca5e40d1923ea340f4b Mon Sep 17 00:00:00 2001 From: Amanda Date: Mon, 27 Nov 2023 14:12:12 +0000 Subject: [PATCH 2/4] modal adjustments, add delete and go back --- pages/account/onboarding/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pages/account/onboarding/index.js b/pages/account/onboarding/index.js index 6f6e1c8b3ef..8f67d155ab6 100644 --- a/pages/account/onboarding/index.js +++ b/pages/account/onboarding/index.js @@ -155,7 +155,6 @@ export default function Onboarding({ profile, progress }) { description: "Delete your account", button: { name: "Delete Account", - href:"/account/manage/milestones" }, click: true, }, @@ -220,14 +219,20 @@ export default function Onboarding({ profile, progress }) {

    {card.title}

    {card.description}

    - + - Hello Modal! + {/* TODO: on click, show a indicator deltion is happening - success message after */} +
    + + +
    +

    Warning! This cannot be reversed once you click Delete.

    From 01a32b830b0fcb143a27927f307e672462e20640 Mon Sep 17 00:00:00 2001 From: Amanda <97615019+amandamartin-dev@users.noreply.github.com> Date: Mon, 27 Nov 2023 14:57:41 +0000 Subject: [PATCH 3/4] delete many links by username --- pages/account/onboarding/index.js | 18 +++++-- .../api/account/manage/delete/[[...data]].js | 49 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 pages/api/account/manage/delete/[[...data]].js diff --git a/pages/account/onboarding/index.js b/pages/account/onboarding/index.js index 8f67d155ab6..c6727d19a91 100644 --- a/pages/account/onboarding/index.js +++ b/pages/account/onboarding/index.js @@ -14,6 +14,7 @@ import { FaTriangleExclamation, } from "react-icons/fa6"; +import { clientEnv } from "@config/schemas/clientSchema"; import logger from "@config/logger"; import PageHead from "@components/PageHead"; import Page from "@components/Page"; @@ -66,11 +67,11 @@ export async function getServerSideProps(context) { ).toFixed(0); return { - props: { profile, progress }, + props: { profile, progress, BASE_URL: clientEnv.NEXT_PUBLIC_BASE_URL }, }; } -export default function Onboarding({ profile, progress }) { +export default function Onboarding({ profile, progress, BASE_URL }) { const router = useRouter(); const { data: session } = useSession(); if (typeof window !== "undefined" && window.localStorage) { @@ -164,6 +165,17 @@ export default function Onboarding({ profile, progress }) { premium: "You are now a premium user!", cancel: "You cancelled your subscription.", }; + + //TODO move this? + const deleteLinks = async () => { + await fetch(`${BASE_URL}/api/account/manage/delete/${profile.username}`, { + method: "DELETE", + headers: { + "Content-Type": "application/json", + }, + }); + } + return ( <> {/* TODO: on click, show a indicator deltion is happening - success message after */}
    - diff --git a/pages/api/account/manage/delete/[[...data]].js b/pages/api/account/manage/delete/[[...data]].js new file mode 100644 index 00000000000..d0ce5d21d88 --- /dev/null +++ b/pages/api/account/manage/delete/[[...data]].js @@ -0,0 +1,49 @@ +import { authOptions } from "../../../auth/[...nextauth]"; +import { getServerSession } from "next-auth/next"; + +import connectMongo from "@config/mongo"; +import logger from "@config/logger"; +import { Link } from "@models/index"; + +export default async function handler(req, res) { + const session = await getServerSession(req, res, authOptions); + const username = session.username; + + if (!["DELETE"].includes(req.method)) { + return res.status(400).json({ + error: "Invalid request: DELETE required", + }); + } + + const { data } = req.query; + const context = { req, res }; + + let link = {}; + + if (req.method === "DELETE") { + link = await deleteLinkApi(context, username, data[0]); + } + + if (link.error) { + return res.status(400).json({ message: link.error }); + } + + return res.status(200).json(link); +} + + + export async function deleteLinkApi(context, username) { + await connectMongo(); + const log = logger.child({ username }); + + // delete link + try { + await Link.deleteMany({ username: username }); + } catch (e) { + const error = `failed to delete links from profile for username: ${username}`; + log.error(e, error); + return { error }; + } + + return JSON.parse(JSON.stringify({})); + } \ No newline at end of file From 9f78f3d7be9e2800fc94dbbff610a6cfe4f11da8 Mon Sep 17 00:00:00 2001 From: Amanda Date: Fri, 19 Jan 2024 16:54:47 +0000 Subject: [PATCH 4/4] delete json profile if exists --- .../api/account/manage/delete/[[...data]].js | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/pages/api/account/manage/delete/[[...data]].js b/pages/api/account/manage/delete/[[...data]].js index d0ce5d21d88..75779fb6175 100644 --- a/pages/api/account/manage/delete/[[...data]].js +++ b/pages/api/account/manage/delete/[[...data]].js @@ -2,8 +2,9 @@ import { authOptions } from "../../../auth/[...nextauth]"; import { getServerSession } from "next-auth/next"; import connectMongo from "@config/mongo"; -import logger from "@config/logger"; +//import logger from "@config/logger"; import { Link } from "@models/index"; +import fs from 'fs'; export default async function handler(req, res) { const session = await getServerSession(req, res, authOptions); @@ -34,16 +35,37 @@ export default async function handler(req, res) { export async function deleteLinkApi(context, username) { await connectMongo(); - const log = logger.child({ username }); + // const log = logger.child({ username }); // delete link try { await Link.deleteMany({ username: username }); } catch (e) { const error = `failed to delete links from profile for username: ${username}`; - log.error(e, error); + //log.error(e, error); + return { error }; + } + checkJsonProfile(username) + return JSON.parse(JSON.stringify({})); + } + + //check for json version, delete if exists + async function checkJsonProfile(username){ + if(fs.existsSync(`./data/${username}.json`)){ + try { + + console.log("found file" + username) + fs.unlinkSync(`./data/${username}.json`) + + } catch (e) { + const error = `failed to delete json profile for username: ${username}`; + //log.error(e, error); return { error }; } return JSON.parse(JSON.stringify({})); + }else{ + console.log(`no json profile`) + return JSON.parse(JSON.stringify({})); + } } \ No newline at end of file