import { useAtom } from "jotai"; import { AnimatePresence, motion } from "motion/react"; import { BiCheckCircle, BiCopy, BiLeftArrowAlt, BiLink, BiPlus, BiPlusCircle, BiTrash, BiX, } from "react-icons/bi"; import Logo from "../assets/logo.svg"; import LogoAlternative from "../assets/fully_alternative_logo.svg"; import { AdminUpdateRequest, ClassUpdateRequest, getClassProfile, } from "../trash/req_mgr"; import { API_BASE_URL } from "../App"; import { useEffect, useRef, useState } from "react"; import { DengiButton, DengiEditable, DengiYesOrNoDialog, LoadingSpinner, TextPreloader, } from "../trash/trash-components"; import { b64e, copyDXLink, randomString } from "../trash/helpers"; import { AvailableAdminSymbols } from "../trash/dengi"; export default function AdminProfilePage({ classIDAtom, adminAtom, setsetRoute, routeAtom, pickmeModeAtom, }) { const [pickmeMode, _] = useAtom(pickmeModeAtom); const [_route, setRoute] = useAtom(routeAtom); const [adminId, _setAdminId] = useAtom(adminAtom); const [classId, _setClassId] = useAtom(classIDAtom); const [error, setError] = useState(""); const [classData, setClassData] = useState(false); const [adminsData, setAdminsData] = useState(false); const [dataId, setDataId] = useState(0); if (classId === "") { setsetRoute(setRoute, "/"); } useEffect(() => { let cancelled = false; (async () => { const a = (await getClassProfile(API_BASE_URL, adminId)) || false; if (!cancelled && a[0] === 1) { if (a[1]["class"]) { setClassData(a[1]["class"]); setAdminsData(a[1]["admins"]); } else { setError(a[1]); } } else { setError(a[1]); } })(); return () => { cancelled = true; }; }, [adminId, dataId]); return ( <>
управление классом {error && typeof error == "string" && ( {error} )} { setDataId(dataId + 1); }, setAdminsData, setClassFr: (v) => { setClassData((prev) => ({ ...prev, userclassname: v })); }, }} /> ); } export function ClassProfileEditor({ classId, classFr, pickmeMode, loaded, adminId, adminsData, setClassFr, update, setAdminsData, }) { return (
classId {classId}
название { e.setIdle(true); let r = await ClassUpdateRequest(API_BASE_URL, adminId, { action: "update_name", value: e.value.trim(), }); if (r[1] == true) setClassFr(e.value.trim()); e.setIdle(false); }} />
админы {adminsData && adminsData.map((i) => ( { setAdminsData((prev) => prev.map((a) => a.adminId === i.adminId ? { ...a, adminName: v } : a, ), ); }, }} /> ))} {!loaded && ( )}
имя id уров.
{loaded && }
); } function CreateAdmin({ editorAdminId, update }) { const [creating, setCreating] = useState(false); const [adminId, setAdminId] = useState(""); const [adminName, setAdminName] = useState(""); const [locked, setLocked] = useState(false); const form = useRef(null); return ( <>
{creating && ( { e.preventDefault(); if (locked || adminId.length < 5) return; setLocked(true); const c = await ClassUpdateRequest( API_BASE_URL, editorAdminId, { action: "create_admin", value: `${adminId};${b64e(adminName)}`, }, ); if (c[1] == true) { update(); setCreating(false); } setLocked(false); }} > setAdminName(e.target.value.trimStart())} /> { let val = e.target.value; let nval = ""; val.split("").forEach((i) => { if (AvailableAdminSymbols.includes(i)) { nval = nval + i; } }); e.target.value = nval; setAdminId(nval); }} /> )} { setCreating(!creating); setAdminName(""); setAdminId(randomString(8, AvailableAdminSymbols)); }} >
); } function AdminProfileRow({ adminId, editorAdminId, adminName, classId, pickmeMode, setAdminFrId, adminLevel, update, }) { return ( { e.setIdle(true); const r = await AdminUpdateRequest(API_BASE_URL, editorAdminId, { action: "change_name", value: e.value.trim(), person: adminId, }); if (r[1] == true) setAdminFrId(e.value); e.setIdle(false); }} /> {adminLevel} ); } const RemoveAdminButton = ({ adminId, editorAdminId, adminName, update, disabled, }) => { const [showDiag, setShowDiag] = useState(false); const [deleting, setDeleting] = useState(false); return ( <> вы точно хотите удалить админа {adminName}?

), yesBtn: "да", noBtn: "нет", yesIcon: , noIcon: , bgDissmis: true, yesBtnStyle: "bg-red-500! text-white! md:hover:bg-red-600!", }} onAnswer={async (answ) => { setShowDiag(false); if (answ) { setDeleting(true); const c = await ClassUpdateRequest(API_BASE_URL, editorAdminId, { action: "delete_admin", value: adminId, }); if (c[1] == true) { update(); setDeleting(false); } } }} /> { if (deleting) return; setShowDiag(true); }} > {deleting ? : } ); }; const CopyClassLink = ({ classId }) => { const [linkCopied, setLinkCopied] = useState(false); return ( { copyDXLink(classId).then((a) => { if (a) { setLinkCopied(true); setTimeout(() => { setLinkCopied(false); }, 2000); } }); }} > {linkCopied ? "скопировано" : "коп ссылку"} ); }; const CopyAdminLink = ({ classId, adminId }) => { const [showDiag, setShowDiag] = useState(false); const [seenDiag, setSeenDiag] = useState(false); const [linkCopied, setLinkCopied] = useState(false); const copy = () => { copyDXLink(classId, adminId).then((a) => { if (a) { setLinkCopied(true); setTimeout(() => { setLinkCopied(false); }, 2000); } }); }; return ( <> любой, кто получит ссылку,{" "} будет иметь доступ к админке.
вы желаете продолжить?

), yesBtn: "да", noBtn: "нет", yesIcon: , noIcon: , bgDissmis: true, yesBtnStyle: "bg-orange-500! text-white! md:hover:bg-orange-600!", }} onAnswer={(answ) => { if (answ) { setSeenDiag(true); copy(); } setShowDiag(false); }} /> (seenDiag ? copy() : setShowDiag(true))}> {linkCopied ? : } ); }; const CoolBg = ({ pickmeMode }) => { return ( <>
); }; const Header = ({ setsetRoute, setRoute, pickmeMode }) => { return (
{ setsetRoute(setRoute, "/app"); }} onContextMenu={(e) => { e.preventDefault(); }} className={ "rounded-full " + (pickmeMode ? "lg:hover:bg-pink-400" : "lg:hover:bg-white lg:hover:fill-black") + " lg:hover:scale-105 transition cursor-pointer" } /> logo
); };