mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 05:45:04 +03:00
* fix(i18n): preserve remaining Vietnamese localization * chore(quality): rebaseline file-size cap for 9 dashboard components (i18n wiring) Restoring the Vietnamese localization on 9 dashboard components (useTranslations wiring + t()/tc() call-site swaps for previously hardcoded strings) grows each file by a small, irreducible amount. Bumps the frozen file-size-baseline.json caps to match, with a justification entry per the project's own ratchet policy. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * fix(i18n): wire weekday localization + add missing qwen CLI description Two gaps left by this PR's own new contract tests, caught while reconciling the branch against the release tip: - CostOverviewTab.tsx added formatWeekdayLabel() but never called it; the Weekly Usage Pattern chart still showed raw English day abbreviations regardless of locale. Now maps weeklyPattern rows through it before handing them to WeeklyPatternCard. - cliTools.toolDescriptions was missing an entry for "qwen" (a baseUrlSupport:"full" tool) in both en.json and vi.json, failing the PR's own cli-catalog-display-contract.test.ts. Covered by the PR's existing tests/unit/dashboard-localization-contract.test.ts and tests/unit/cli-catalog-display-contract.test.ts (both now pass). Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> * i18n(vi): backfill the 4 proxySubscription keys #7299 added to en.json #7299 (proxy subscriptions) merged while this branch was rebasing, adding settings.proxySubscriptionsTab and settings.proxySubscription.error.{LOCAL_CORE_ENDPOINT_INVALID, NEEDS_CORE_NOT_CONFIGURED,NO_USABLE_NODES} to en.json. This PR's own i18n-vi-completeness contract asserts full en↔vi key parity, so the merge of the current release tip surfaced them as missing. Adds the Vietnamese translations, keeping the SS/VMess/Trojan/VLESS/SOCKS5 technical terms verbatim. Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> --------- Co-authored-by: nguyenha935 <208228297+nguyenha935@users.noreply.github.com> Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com> Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com> Co-authored-by: nguyenha935 <nguyenha935@users.noreply.github.com>
268 lines
7.2 KiB
TypeScript
268 lines
7.2 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, useId } from "react";
|
|
import { useTranslations } from "next-intl";
|
|
import { cn } from "@/shared/utils/cn";
|
|
import Button, { type ButtonVariant } from "./Button";
|
|
|
|
// #6265 — preset for content-heavy modals: caps height on the OUTERMOST dialog
|
|
// wrapper only (single scroll owner) and keeps the inner body plain (no
|
|
// independent max-h/overflow), avoiding a double height cap that clips content.
|
|
export const TALL_MODAL_PROPS = {
|
|
className: "max-h-[90vh] overflow-y-auto",
|
|
bodyClassName: "p-6",
|
|
};
|
|
|
|
interface ModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
title?: React.ReactNode;
|
|
children?: React.ReactNode;
|
|
footer?: React.ReactNode;
|
|
size?: "sm" | "md" | "lg" | "xl" | "full";
|
|
closeOnOverlay?: boolean;
|
|
showCloseButton?: boolean;
|
|
className?: string;
|
|
bodyClassName?: string;
|
|
compactHeader?: boolean;
|
|
maxWidth?: string;
|
|
}
|
|
|
|
interface ConfirmModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
onConfirm: () => void | Promise<void>;
|
|
title?: React.ReactNode;
|
|
message: React.ReactNode;
|
|
confirmText?: React.ReactNode;
|
|
cancelText?: React.ReactNode;
|
|
variant?: ButtonVariant;
|
|
loading?: boolean;
|
|
}
|
|
|
|
export default function Modal({
|
|
isOpen,
|
|
onClose,
|
|
title,
|
|
children,
|
|
footer,
|
|
size = "md",
|
|
closeOnOverlay = true,
|
|
showCloseButton = true,
|
|
className,
|
|
bodyClassName,
|
|
compactHeader = false,
|
|
}: ModalProps) {
|
|
const t = useTranslations("common");
|
|
const titleId = useId();
|
|
const dialogRef = useRef(null);
|
|
|
|
const sizes = {
|
|
sm: "max-w-sm",
|
|
md: "max-w-md",
|
|
lg: "max-w-lg",
|
|
xl: "max-w-xl",
|
|
full: "max-w-4xl",
|
|
};
|
|
|
|
// Lock body scroll when modal is open
|
|
useEffect(() => {
|
|
if (isOpen) {
|
|
document.body.style.overflow = "hidden";
|
|
} else {
|
|
document.body.style.overflow = "";
|
|
}
|
|
return () => {
|
|
document.body.style.overflow = "";
|
|
};
|
|
}, [isOpen]);
|
|
|
|
// Handle escape key
|
|
useEffect(() => {
|
|
const handleEscape = (e) => {
|
|
if (e.key === "Escape" && isOpen) {
|
|
onClose();
|
|
}
|
|
};
|
|
document.addEventListener("keydown", handleEscape);
|
|
return () => document.removeEventListener("keydown", handleEscape);
|
|
}, [isOpen, onClose]);
|
|
|
|
// Focus trap
|
|
useEffect(() => {
|
|
if (!isOpen || !dialogRef.current) return;
|
|
|
|
const dialog = dialogRef.current;
|
|
const focusableSelector =
|
|
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
|
|
|
|
// Focus first focusable element
|
|
const firstFocusable = dialog.querySelector(focusableSelector);
|
|
if (firstFocusable) {
|
|
setTimeout(() => firstFocusable.focus(), 50);
|
|
}
|
|
|
|
const handleTab = (e) => {
|
|
if (e.key !== "Tab") return;
|
|
|
|
const focusable = [...dialog.querySelectorAll(focusableSelector)];
|
|
if (focusable.length === 0) return;
|
|
|
|
const first = focusable[0];
|
|
const last = focusable[focusable.length - 1];
|
|
|
|
if (e.shiftKey && document.activeElement === first) {
|
|
e.preventDefault();
|
|
last.focus();
|
|
} else if (!e.shiftKey && document.activeElement === last) {
|
|
e.preventDefault();
|
|
first.focus();
|
|
}
|
|
};
|
|
|
|
dialog.addEventListener("keydown", handleTab);
|
|
return () => dialog.removeEventListener("keydown", handleTab);
|
|
}, [isOpen]);
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
|
{/* Overlay */}
|
|
<div
|
|
className="absolute inset-0 bg-black/30 backdrop-blur-sm"
|
|
onClick={closeOnOverlay ? onClose : undefined}
|
|
aria-hidden="true"
|
|
/>
|
|
|
|
{/* Modal content */}
|
|
<div
|
|
ref={dialogRef}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-labelledby={title ? titleId : undefined}
|
|
className={cn(
|
|
"relative w-full bg-surface",
|
|
"border border-black/10 dark:border-white/10",
|
|
"rounded-card shadow-2xl",
|
|
"animate-in fade-in zoom-in-95 duration-200",
|
|
sizes[size],
|
|
className
|
|
)}
|
|
>
|
|
{/* Header */}
|
|
{(title || showCloseButton) && (
|
|
<div
|
|
className={cn(
|
|
"flex items-center justify-between border-b border-black/5 dark:border-white/5",
|
|
compactHeader ? "px-4 py-2.5" : "p-6"
|
|
)}
|
|
>
|
|
<div className="flex items-center min-w-0">
|
|
<div
|
|
className={cn(
|
|
"flex items-center gap-1.5 mr-3 shrink-0",
|
|
compactHeader ? "" : "gap-2 mr-4"
|
|
)}
|
|
aria-hidden="true"
|
|
>
|
|
<div
|
|
className={cn(
|
|
"rounded-full bg-[#FF5F56]",
|
|
compactHeader ? "w-2.5 h-2.5" : "w-3 h-3"
|
|
)}
|
|
/>
|
|
<div
|
|
className={cn(
|
|
"rounded-full bg-[#FFBD2E]",
|
|
compactHeader ? "w-2.5 h-2.5" : "w-3 h-3"
|
|
)}
|
|
/>
|
|
<div
|
|
className={cn(
|
|
"rounded-full bg-[#27C93F]",
|
|
compactHeader ? "w-2.5 h-2.5" : "w-3 h-3"
|
|
)}
|
|
/>
|
|
</div>
|
|
{title && (
|
|
<h2
|
|
id={titleId}
|
|
className={cn(
|
|
"font-semibold text-text-main truncate min-w-0",
|
|
compactHeader ? "text-sm" : "text-lg"
|
|
)}
|
|
>
|
|
{title}
|
|
</h2>
|
|
)}
|
|
</div>
|
|
{showCloseButton && (
|
|
<button
|
|
onClick={onClose}
|
|
aria-label={t("close")}
|
|
className="p-1.5 rounded-lg text-text-muted hover:bg-black/5 dark:hover:bg-white/5 transition-colors shrink-0"
|
|
>
|
|
<span className="material-symbols-outlined text-[20px]" aria-hidden="true">
|
|
close
|
|
</span>
|
|
</button>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{/* Body */}
|
|
<div className={bodyClassName ?? "p-6 max-h-[calc(80vh-140px)] overflow-y-auto"}>
|
|
{children}
|
|
</div>
|
|
|
|
{/* Footer */}
|
|
{footer && (
|
|
<div className="flex items-center justify-end gap-3 p-6 border-t border-black/5 dark:border-white/5">
|
|
{footer}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Confirm Modal helper
|
|
export function ConfirmModal({
|
|
isOpen,
|
|
onClose,
|
|
onConfirm,
|
|
title,
|
|
message,
|
|
confirmText,
|
|
cancelText,
|
|
variant = "danger",
|
|
loading = false,
|
|
}: ConfirmModalProps) {
|
|
const t = useTranslations("common");
|
|
const resolvedTitle = title ?? t("confirmTitle");
|
|
const resolvedConfirmText = confirmText ?? t("confirmAction");
|
|
const resolvedCancelText = cancelText ?? t("cancel");
|
|
|
|
return (
|
|
<Modal
|
|
isOpen={isOpen}
|
|
onClose={onClose}
|
|
title={resolvedTitle}
|
|
size="sm"
|
|
footer={
|
|
<>
|
|
<Button variant="ghost" onClick={onClose} disabled={loading}>
|
|
{resolvedCancelText}
|
|
</Button>
|
|
<Button variant={variant} onClick={onConfirm} loading={loading}>
|
|
{resolvedConfirmText}
|
|
</Button>
|
|
</>
|
|
}
|
|
>
|
|
<p className="text-text-muted">{message}</p>
|
|
</Modal>
|
|
);
|
|
}
|