2025-11-21 09:30:30 +08:00
|
|
|
import React, { useEffect, useState } from "react";
|
2025-10-17 21:32:28 +08:00
|
|
|
import { Save } from "lucide-react";
|
2025-10-17 18:38:49 +08:00
|
|
|
import { useTranslation } from "react-i18next";
|
2025-11-21 09:30:30 +08:00
|
|
|
import { FullScreenPanel } from "@/components/common/FullScreenPanel";
|
2025-10-17 21:32:28 +08:00
|
|
|
import { Button } from "@/components/ui/button";
|
2025-11-21 09:30:30 +08:00
|
|
|
import JsonEditor from "@/components/JsonEditor";
|
2025-10-17 18:38:49 +08:00
|
|
|
|
|
|
|
|
interface CodexCommonConfigModalProps {
|
|
|
|
|
isOpen: boolean;
|
|
|
|
|
onClose: () => void;
|
|
|
|
|
value: string;
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
error?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* CodexCommonConfigModal - Common Codex configuration editor modal
|
|
|
|
|
* Allows editing of common TOML configuration shared across providers
|
|
|
|
|
*/
|
|
|
|
|
export const CodexCommonConfigModal: React.FC<CodexCommonConfigModalProps> = ({
|
|
|
|
|
isOpen,
|
|
|
|
|
onClose,
|
|
|
|
|
value,
|
|
|
|
|
onChange,
|
|
|
|
|
error,
|
|
|
|
|
}) => {
|
|
|
|
|
const { t } = useTranslation();
|
2025-11-21 09:30:30 +08:00
|
|
|
const [isDarkMode, setIsDarkMode] = useState(false);
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-21 09:30:30 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-21 09:30:30 +08:00
|
|
|
const observer = new MutationObserver(() => {
|
|
|
|
|
setIsDarkMode(document.documentElement.classList.contains("dark"));
|
|
|
|
|
});
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-21 09:30:30 +08:00
|
|
|
observer.observe(document.documentElement, {
|
|
|
|
|
attributes: true,
|
|
|
|
|
attributeFilter: ["class"],
|
|
|
|
|
});
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-21 09:30:30 +08:00
|
|
|
return () => observer.disconnect();
|
|
|
|
|
}, []);
|
2025-10-17 18:38:49 +08:00
|
|
|
|
2025-11-21 09:30:30 +08:00
|
|
|
return (
|
|
|
|
|
<FullScreenPanel
|
|
|
|
|
isOpen={isOpen}
|
|
|
|
|
title={t("codexConfig.editCommonConfigTitle")}
|
|
|
|
|
onClose={onClose}
|
|
|
|
|
footer={
|
|
|
|
|
<>
|
2025-10-17 21:32:28 +08:00
|
|
|
<Button type="button" variant="outline" onClick={onClose}>
|
2025-10-17 18:38:49 +08:00
|
|
|
{t("common.cancel")}
|
2025-10-17 21:32:28 +08:00
|
|
|
</Button>
|
|
|
|
|
<Button type="button" onClick={onClose} className="gap-2">
|
2025-10-17 18:38:49 +08:00
|
|
|
<Save className="w-4 h-4" />
|
|
|
|
|
{t("common.save")}
|
2025-10-17 21:32:28 +08:00
|
|
|
</Button>
|
2025-11-21 09:30:30 +08:00
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<p className="text-sm text-muted-foreground">
|
|
|
|
|
{t("codexConfig.commonConfigHint")}
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
<JsonEditor
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
placeholder={`# Common Codex config
|
|
|
|
|
|
|
|
|
|
# Add your common TOML configuration here`}
|
|
|
|
|
darkMode={isDarkMode}
|
|
|
|
|
rows={16}
|
|
|
|
|
showValidation={false}
|
|
|
|
|
language="javascript"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{error && (
|
|
|
|
|
<p className="text-sm text-red-500 dark:text-red-400">{error}</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</FullScreenPanel>
|
2025-10-17 18:38:49 +08:00
|
|
|
);
|
|
|
|
|
};
|