import { Alert, AlertTitle, Box, Button, Typography } from "@mui/material"; import React, { memo, useCallback, useContext, useMemo, useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { AppError, Code, Response } from "../../../api/request.ts"; import { useAppDispatch, useAppSelector } from "../../../redux/hooks.ts"; import { navigateToPath, retrySharePassword, unlockVault } from "../../../redux/thunks/filemanager.ts"; import { Filesystem } from "../../../util/uri.ts"; import { FilledTextField, SecondaryButton } from "../../Common/StyledComponents.tsx"; import ArrowLeft from "../../Icons/ArrowLeft.tsx"; import LinkDismiss from "../../Icons/LinkDismiss.tsx"; import LockClosed from "../../Icons/LockClosed.tsx"; import { FmIndexContext } from "../FmIndexContext.tsx"; interface ExplorerErrorProps { error?: Response; [key: string]: any; } const RetryPassword = () => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const fmIndex = useContext(FmIndexContext); const [password, setPassword] = useState(""); return ( e.stopPropagation()} onMouseDown={(e) => e.stopPropagation()}> setPassword(e.target.value)} label={t("application:share.enterPassword")} /> ); }; const RetryVaultUnlock = () => { const { t } = useTranslation(); const dispatch = useAppDispatch(); const fmIndex = useContext(FmIndexContext); const [password, setPassword] = useState(""); const [error, setError] = useState(undefined); const [loading, setLoading] = useState(false); const unlock = useCallback(async () => { setLoading(true); setError(undefined); try { await dispatch(unlockVault(fmIndex, password)); } catch (e) { setError(e instanceof Error ? e.message : undefined); } finally { setLoading(false); } }, [dispatch, fmIndex, password]); return ( e.stopPropagation()} onMouseDown={(e) => e.stopPropagation()}> {t("application:vault.lockedTitle")} setPassword(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter" && password != "") { unlock(); } }} label={t("application:vault.enterPassword")} /> ); }; const ExplorerError = memo( React.forwardRef(({ error, ...rest }: ExplorerErrorProps, ref) => { const dispatch = useAppDispatch(); const navigate = useNavigate(); const fmIndex = useContext(FmIndexContext); const fs = useAppSelector((state) => state.fileManager[fmIndex].current_fs); const previousPath = useAppSelector((state) => state.fileManager[fmIndex].previous_path); const { t } = useTranslation("application"); const appErr = useMemo(() => { if (error) { return new AppError(error); } return undefined; }, [error]); const navigateBack = useCallback(() => { previousPath && dispatch(navigateToPath(fmIndex, previousPath)); }, [dispatch, fmIndex, previousPath]); const signIn = useCallback(() => { navigate("/session?redirect=" + encodeURIComponent(window.location.pathname + window.location.search)); }, [navigate]); const innerError = () => { switch (error?.code) { case Code.AnonymouseAccessDenied: return ( {t("application:fileManager.anonymousAccessDenied")} {t("application:login.signIn")} ); case Code.IncorrectPassword: return ; case Code.VaultLocked: return ; // @ts-ignore case Code.NodeFound: if (fs == Filesystem.share) { return ( {t("application:share.shareNotExist")} ); } default: return ( {t("application:fileManager.listError")} {appErr && appErr.message} {error?.correlation_id && ( {t("common:requestID", { id: error.correlation_id })} )} ); } }; return ( {innerError()} ); }), ); export default ExplorerError;