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"; import useInitialData from "@/hooks/useInitialData"; 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.