feat: resource-group-management
This commit is contained in:
1 parent
5d30306ad7
commit
d518efb843
2 files changed
+23
-4
No files matched your search
@@ -7,11 +7,13 @@ import { useTranslation } from "@/shared/lib/useTranslation";
|
||||
interface CustomDomainPanelProps {
|
||||
domain: string;
|
||||
setDomain: (domain: string) => void;
|
||||
onValidationChange?: (isValid: boolean) => void;
|
||||
}
|
||||
|
||||
const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
||||
domain,
|
||||
setDomain,
|
||||
onValidationChange,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [validationError, setValidationError] = useState<string | undefined>();
|
||||
@@ -24,7 +26,7 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
||||
|
||||
// Basic domain format validation ,like www.example.com
|
||||
const domainRegex =
|
||||
/(?=.{1,255}$)(?:(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,}/;
|
||||
/^(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})$/;
|
||||
if (!domainRegex.test(value)) {
|
||||
return t("Please enter a valid domain");
|
||||
}
|
||||
@@ -34,6 +36,17 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
||||
const handleBlur = () => {
|
||||
const error = validateDomain(domain);
|
||||
setValidationError(error);
|
||||
// 通知父组件校验状态
|
||||
onValidationChange?.(!error);
|
||||
};
|
||||
|
||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value;
|
||||
setDomain(value);
|
||||
// 实时校验
|
||||
const error = validateDomain(value);
|
||||
setValidationError(error);
|
||||
onValidationChange?.(!error);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -48,7 +61,7 @@ const CustomDomainPanel: React.FC<CustomDomainPanelProps> = ({
|
||||
label={t("Domain")}
|
||||
placeholder={t("Enter your full domain name (e.g., www.example.com)")}
|
||||
value={domain}
|
||||
onChange={(e) => setDomain(e.target.value)}
|
||||
onChange={handleChange}
|
||||
onBlur={handleBlur}
|
||||
isInvalid={!!validationError}
|
||||
errorMessage={validationError}
|
||||
|
||||
@@ -36,6 +36,8 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
||||
const { t } = useTranslation();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [domain, setDomain] = useState(config.domain || "");
|
||||
const [isValidDomain, setIsValidDomain] = useState(false);
|
||||
|
||||
const handleActivate = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
@@ -54,7 +56,11 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
||||
<ModalContent>
|
||||
<ModalHeader>{t("Set Custom Domain")}</ModalHeader>
|
||||
<ModalBody className="flex flex-col gap-4">
|
||||
<CustomDomainPanel domain={domain} setDomain={setDomain} />
|
||||
<CustomDomainPanel
|
||||
domain={domain}
|
||||
setDomain={setDomain}
|
||||
onValidationChange={setIsValidDomain}
|
||||
/>
|
||||
<DNSRecordsPanel
|
||||
cnameTarget={`${config.subdomain || ""}${process.env.NEXT_PUBLIC_DOMAIN_HOST || ""}`}
|
||||
apexATarget={config.cname_a_ip}
|
||||
@@ -67,7 +73,7 @@ const DomainActivationPanel: React.FC<DomainActivationPanelProps> = ({
|
||||
</h3>
|
||||
<Button
|
||||
color="primary"
|
||||
isDisabled={!domain}
|
||||
isDisabled={!domain || !isValidDomain}
|
||||
isLoading={isLoading}
|
||||
onPress={handleActivate}
|
||||
size="sm"
|
||||
|
||||
Reference in new issue
Block a user