From 146b8576f4004e7cb3689748a1a0c58372a4f936 Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Thu, 19 Oct 2023 00:20:28 -0400 Subject: [PATCH] cleared up old code --- components/Modal/User/BillingPortal.tsx | 46 ---- components/Modal/User/ChangePassword.tsx | 115 ---------- components/Modal/User/PrivacySettings.tsx | 248 ---------------------- components/Modal/User/ProfileSettings.tsx | 195 ----------------- components/Modal/User/index.tsx | 107 ---------- components/ModalManagement.tsx | 12 -- lib/api/controllers/links/postLink.ts | 2 +- store/modals.ts | 7 - 8 files changed, 1 insertion(+), 731 deletions(-) delete mode 100644 components/Modal/User/BillingPortal.tsx delete mode 100644 components/Modal/User/ChangePassword.tsx delete mode 100644 components/Modal/User/PrivacySettings.tsx delete mode 100644 components/Modal/User/ProfileSettings.tsx delete mode 100644 components/Modal/User/index.tsx diff --git a/components/Modal/User/BillingPortal.tsx b/components/Modal/User/BillingPortal.tsx deleted file mode 100644 index 214bfca..0000000 --- a/components/Modal/User/BillingPortal.tsx +++ /dev/null @@ -1,46 +0,0 @@ -import { useState } from "react"; -import SubmitButton from "@/components/SubmitButton"; -import { toast } from "react-hot-toast"; -import { useRouter } from "next/router"; -import { faArrowUpRightFromSquare } from "@fortawesome/free-solid-svg-icons"; - -export default function PaymentPortal() { - const [submitLoader, setSubmitLoader] = useState(false); - const router = useRouter(); - - const submit = () => { - setSubmitLoader(true); - const load = toast.loading("Redirecting to billing portal..."); - - router.push(process.env.NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL as string); - }; - - return ( -
-
-

- To manage/cancel your subsciption, visit the billing portal. -

- - - -

- If you still need help or encountered any issues, feel free to reach - out to us at:{" "} - - support@linkwarden.app - -

-
-
- ); -} diff --git a/components/Modal/User/ChangePassword.tsx b/components/Modal/User/ChangePassword.tsx deleted file mode 100644 index 552463c..0000000 --- a/components/Modal/User/ChangePassword.tsx +++ /dev/null @@ -1,115 +0,0 @@ -import { Dispatch, SetStateAction, useEffect, useState } from "react"; -import { AccountSettings } from "@/types/global"; -import useAccountStore from "@/store/account"; -import { signOut, useSession } from "next-auth/react"; -import { faPenToSquare } from "@fortawesome/free-regular-svg-icons"; -import SubmitButton from "@/components/SubmitButton"; -import { toast } from "react-hot-toast"; -import TextInput from "@/components/TextInput"; - -type Props = { - togglePasswordFormModal: Function; - setUser: Dispatch>; - user: AccountSettings; -}; - -export default function ChangePassword({ - togglePasswordFormModal, - setUser, - user, -}: Props) { - const [newPassword, setNewPassword1] = useState(""); - const [newPassword2, setNewPassword2] = useState(""); - - const [submitLoader, setSubmitLoader] = useState(false); - - const { account, updateAccount } = useAccountStore(); - const { update, data } = useSession(); - - useEffect(() => { - if ( - !(newPassword == "" || newPassword2 == "") && - newPassword === newPassword2 - ) { - setUser({ ...user, newPassword }); - } - }, [newPassword, newPassword2]); - - const submit = async () => { - if (newPassword == "" || newPassword2 == "") { - toast.error("Please fill all the fields."); - } - - if (newPassword !== newPassword2) - return toast.error("Passwords do not match."); - else if (newPassword.length < 8) - return toast.error("Passwords must be at least 8 characters."); - - setSubmitLoader(true); - - const load = toast.loading("Applying..."); - - const response = await updateAccount({ - ...user, - }); - - toast.dismiss(load); - - if (response.ok) { - toast.success("Settings Applied!"); - - if (user.email !== account.email) { - update({ - id: data?.user.id, - }); - - signOut(); - } else if ( - user.username !== account.username || - user.name !== account.name - ) - update({ - id: data?.user.id, - }); - - setUser({ ...user, newPassword: undefined }); - togglePasswordFormModal(); - } else toast.error(response.data as string); - - setSubmitLoader(false); - }; - - return ( -
-
-

New Password

- - setNewPassword1(e.target.value)} - placeholder="••••••••••••••" - type="password" - /> - -

- Confirm New Password -

- - setNewPassword2(e.target.value)} - placeholder="••••••••••••••" - type="password" - /> - - -
-
- ); -} diff --git a/components/Modal/User/PrivacySettings.tsx b/components/Modal/User/PrivacySettings.tsx deleted file mode 100644 index ce61782..0000000 --- a/components/Modal/User/PrivacySettings.tsx +++ /dev/null @@ -1,248 +0,0 @@ -import { Dispatch, SetStateAction, useEffect, useState } from "react"; -import Checkbox from "../../Checkbox"; -import useAccountStore from "@/store/account"; -import { - AccountSettings, - MigrationFormat, - MigrationRequest, -} from "@/types/global"; -import { signOut, useSession } from "next-auth/react"; -import { faPenToSquare } from "@fortawesome/free-regular-svg-icons"; -import SubmitButton from "../../SubmitButton"; -import { toast } from "react-hot-toast"; -import Link from "next/link"; -import ClickAwayHandler from "@/components/ClickAwayHandler"; - -type Props = { - toggleSettingsModal: Function; - setUser: Dispatch>; - user: AccountSettings; -}; - -export default function PrivacySettings({ - toggleSettingsModal, - setUser, - user, -}: Props) { - const { update, data } = useSession(); - const { account, updateAccount } = useAccountStore(); - - const [importDropdown, setImportDropdown] = useState(false); - const [submitLoader, setSubmitLoader] = useState(false); - - const [whitelistedUsersTextbox, setWhiteListedUsersTextbox] = useState( - user.whitelistedUsers.join(", ") - ); - - useEffect(() => { - setUser({ - ...user, - whitelistedUsers: stringToArray(whitelistedUsersTextbox), - }); - }, [whitelistedUsersTextbox]); - - useEffect(() => { - setUser({ ...user, newPassword: undefined }); - }, []); - - const stringToArray = (str: string) => { - const stringWithoutSpaces = str.replace(/\s+/g, ""); - - const wordsArray = stringWithoutSpaces.split(","); - - return wordsArray; - }; - - const importBookmarks = async (e: any, format: MigrationFormat) => { - const file: File = e.target.files[0]; - - if (file) { - var reader = new FileReader(); - reader.readAsText(file, "UTF-8"); - reader.onload = async function (e) { - const load = toast.loading("Importing..."); - - const request: string = e.target?.result as string; - - const body: MigrationRequest = { - format, - data: request, - }; - - const response = await fetch("/api/migration", { - method: "POST", - body: JSON.stringify(body), - }); - - const data = await response.json(); - - toast.dismiss(load); - - toast.success("Imported the Bookmarks! Reloading the page..."); - - setImportDropdown(false); - - setTimeout(() => { - location.reload(); - }, 2000); - }; - reader.onerror = function (e) { - console.log("Error:", e); - }; - } - }; - - const submit = async () => { - setSubmitLoader(true); - - const load = toast.loading("Applying..."); - - const response = await updateAccount({ - ...user, - }); - - toast.dismiss(load); - - if (response.ok) { - toast.success("Settings Applied!"); - - if (user.email !== account.email) { - update({ - id: data?.user.id, - }); - - signOut(); - } else if ( - user.username !== account.username || - user.name !== account.name - ) - update({ - id: data?.user.id, - }); - - setUser({ ...user, newPassword: undefined }); - toggleSettingsModal(); - } else toast.error(response.data as string); - setSubmitLoader(false); - }; - - return ( -
-
-

- Profile Visibility -

- - setUser({ ...user, isPrivate: !user.isPrivate })} - /> - -

- This will limit who can find and add you to other Collections. -

- - {user.isPrivate && ( -
-

- Whitelisted Users -

-

- Please provide the Username of the users you wish to grant - visibility to your profile. Separated by comma. -

-