mirror of
https://github.com/cloudreve/frontend.git
synced 2025-12-26 04:02:47 +00:00
73 lines
2.2 KiB
TypeScript
73 lines
2.2 KiB
TypeScript
import { DialogContent, Link } from "@mui/material";
|
|
import { useCallback, useState } from "react";
|
|
import { Trans, useTranslation } from "react-i18next";
|
|
import { getWopiDiscovery } from "../../../../api/api.ts";
|
|
import { ViewerGroup } from "../../../../api/explorer.ts";
|
|
import { useAppDispatch } from "../../../../redux/hooks.ts";
|
|
import { DenseFilledTextField } from "../../../Common/StyledComponents.tsx";
|
|
import DraggableDialog from "../../../Dialogs/DraggableDialog.tsx";
|
|
import SettingForm from "../../../Pages/Setting/SettingForm.tsx";
|
|
import { Code } from "../../Common/Code.tsx";
|
|
import { NoMarginHelperText } from "../../Settings/Settings.tsx";
|
|
|
|
export interface ImportWopiDialogProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
onImported: (v: ViewerGroup) => void;
|
|
}
|
|
|
|
const ImportWopiDialog = ({ open, onClose, onImported }: ImportWopiDialogProps) => {
|
|
const { t } = useTranslation("dashboard");
|
|
const dispatch = useAppDispatch();
|
|
const [endpoint, setEndpoint] = useState("");
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const onSubmit = useCallback(() => {
|
|
setLoading(true);
|
|
dispatch(
|
|
getWopiDiscovery({
|
|
endpoint,
|
|
}),
|
|
)
|
|
.then((res) => {
|
|
onImported(res);
|
|
onClose();
|
|
})
|
|
.finally(() => {
|
|
setLoading(false);
|
|
});
|
|
}, [endpoint, onClose, onImported]);
|
|
|
|
return (
|
|
<DraggableDialog
|
|
title={t("settings.importWopi")}
|
|
showActions
|
|
showCancel
|
|
onAccept={onSubmit}
|
|
disabled={endpoint == ""}
|
|
loading={loading}
|
|
dialogProps={{
|
|
fullWidth: true,
|
|
maxWidth: "md",
|
|
open,
|
|
onClose,
|
|
}}
|
|
>
|
|
<DialogContent>
|
|
<SettingForm lgWidth={12} title={t("settings.wopiEndpoint")}>
|
|
<DenseFilledTextField value={endpoint} fullWidth onChange={(e) => setEndpoint(e.target.value)} />
|
|
<NoMarginHelperText>
|
|
<Trans
|
|
ns="dashboard"
|
|
i18nKey="settings.wopiDes"
|
|
components={[<Code />, <Link href="https://docs.cloudreve.org/usage/wopi" target="_blank" />]}
|
|
/>
|
|
</NoMarginHelperText>
|
|
</SettingForm>
|
|
</DialogContent>
|
|
</DraggableDialog>
|
|
);
|
|
};
|
|
|
|
export default ImportWopiDialog;
|