mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-19 09:51:55 +08:00
refactor: clean code
This commit is contained in:
parent
369c146eca
commit
f71a519674
@ -51,23 +51,13 @@ const DeployToAliyunALB = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: res.error.errors.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error.errors.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error.errors.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error.errors.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: undefined,
|
||||
resourceType: undefined,
|
||||
loadbalancerId: undefined,
|
||||
listenerId: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error?.errors?.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error?.errors?.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error?.errors?.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
|
@ -27,25 +27,20 @@ const DeployToAliyunCDN = () => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
const formSchema = z.object({
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
<div>
|
||||
@ -55,26 +50,9 @@ const DeployToAliyunCDN = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -51,23 +51,13 @@ const DeployToAliyunCLB = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: res.error.errors.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error.errors.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error.errors.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerPort: res.error.errors.find((e) => e.path[0] === "listenerPort")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: undefined,
|
||||
resourceType: undefined,
|
||||
loadbalancerId: undefined,
|
||||
listenerPort: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error?.errors?.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error?.errors?.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerPort: res.error?.errors?.find((e) => e.path[0] === "listenerPort")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
|
@ -51,23 +51,13 @@ const DeployToAliyunNLB = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: res.error.errors.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error.errors.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error.errors.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error.errors.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: undefined,
|
||||
resourceType: undefined,
|
||||
loadbalancerId: undefined,
|
||||
listenerId: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error?.errors?.find((e) => e.path[0] === "resourceType")?.message,
|
||||
loadbalancerId: res.error?.errors?.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error?.errors?.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
|
@ -17,7 +17,7 @@ const DeployToAliyunOSS = () => {
|
||||
setDeploy({
|
||||
...data,
|
||||
config: {
|
||||
endpoint: "oss-cn-hangzhou.aliyuncs.com",
|
||||
endpoint: "oss.aliyuncs.com",
|
||||
bucket: "",
|
||||
domain: "",
|
||||
},
|
||||
@ -29,43 +29,27 @@ const DeployToAliyunOSS = () => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = bucketSchema.safeParse(data.config?.bucket);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
bucket: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
bucket: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
const formSchema = z.object({
|
||||
endpoint: z.string().min(1, {
|
||||
message: t("domain.deployment.form.aliyun_oss_endpoint.placeholder"),
|
||||
}),
|
||||
bucket: z.string().min(1, {
|
||||
message: t("domain.deployment.form.aliyun_oss_bucket.placeholder"),
|
||||
}),
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
const bucketSchema = z.string().min(1, {
|
||||
message: t("domain.deployment.form.aliyun_oss_bucket.placeholder"),
|
||||
});
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
endpoint: res.error?.errors?.find((e) => e.path[0] === "endpoint")?.message,
|
||||
bucket: res.error?.errors?.find((e) => e.path[0] === "bucket")?.message,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
@ -76,13 +60,9 @@ const DeployToAliyunOSS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.endpoint}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.endpoint = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.endpoint = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -97,26 +77,9 @@ const DeployToAliyunOSS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.bucket}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = bucketSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
bucket: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
bucket: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.bucket = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.bucket = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -131,26 +94,9 @@ const DeployToAliyunOSS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -28,31 +28,30 @@ const DeployToHuaweiCloudCDN = () => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
const formSchema = z.object({
|
||||
region: z.string().min(1, {
|
||||
message: t("domain.deployment.form.huaweicloud_cdn_region.placeholder"),
|
||||
}),
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
<div>
|
||||
<Label>{t("domain.deployment.form.huaweicloud_elb_region.label")}</Label>
|
||||
<Label>{t("domain.deployment.form.huaweicloud_cdn_region.label")}</Label>
|
||||
<Input
|
||||
placeholder={t("domain.deployment.form.huaweicloud_elb_region.placeholder")}
|
||||
placeholder={t("domain.deployment.form.huaweicloud_cdn_region.placeholder")}
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.region}
|
||||
onChange={(e) => {
|
||||
|
@ -35,7 +35,9 @@ const DeployToHuaweiCloudCDN = () => {
|
||||
const formSchema = z
|
||||
.object({
|
||||
region: z.string().min(1, t("domain.deployment.form.huaweicloud_elb_region.placeholder")),
|
||||
resourceType: z.string().min(1, t("domain.deployment.form.huaweicloud_elb_resource_type.placeholder")),
|
||||
resourceType: z.union([z.literal("certificate"), z.literal("loadbalancer"), z.literal("listener")], {
|
||||
message: t("domain.deployment.form.huaweicloud_elb_resource_type.placeholder"),
|
||||
}),
|
||||
certificateId: z.string().optional(),
|
||||
loadbalancerId: z.string().optional(),
|
||||
listenerId: z.string().optional(),
|
||||
@ -55,25 +57,14 @@ const DeployToHuaweiCloudCDN = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: res.error.errors.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error.errors.find((e) => e.path[0] === "resourceType")?.message,
|
||||
certificateId: res.error.errors.find((e) => e.path[0] === "certificateId")?.message,
|
||||
loadbalancerId: res.error.errors.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error.errors.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: undefined,
|
||||
resourceType: undefined,
|
||||
certificateId: undefined,
|
||||
loadbalancerId: undefined,
|
||||
listenerId: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
resourceType: res.error?.errors?.find((e) => e.path[0] === "resourceType")?.message,
|
||||
certificateId: res.error?.errors?.find((e) => e.path[0] === "certificateId")?.message,
|
||||
loadbalancerId: res.error?.errors?.find((e) => e.path[0] === "loadbalancerId")?.message,
|
||||
listenerId: res.error?.errors?.find((e) => e.path[0] === "listenerId")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { useEffect } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { z } from "zod";
|
||||
import { produce } from "immer";
|
||||
|
||||
import { Input } from "@/components/ui/input";
|
||||
@ -9,7 +10,7 @@ import { useDeployEditContext } from "./DeployEdit";
|
||||
const DeployToKubernetesSecret = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { deploy: data, setDeploy, setError } = useDeployEditContext();
|
||||
const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (!data.id) {
|
||||
@ -29,6 +30,32 @@ const DeployToKubernetesSecret = () => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
const formSchema = z.object({
|
||||
namespace: z.string().min(1, {
|
||||
message: t("domain.deployment.form.k8s_namespace.placeholder"),
|
||||
}),
|
||||
secretName: z.string().min(1, {
|
||||
message: t("domain.deployment.form.k8s_secret_name.placeholder"),
|
||||
}),
|
||||
secretDataKeyForCrt: z.string().min(1, {
|
||||
message: t("domain.deployment.form.k8s_secret_data_key_for_crt.placeholder"),
|
||||
}),
|
||||
secretDataKeyForKey: z.string().min(1, {
|
||||
message: t("domain.deployment.form.k8s_secret_data_key_for_key.placeholder"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
namespace: res.error?.errors?.find((e) => e.path[0] === "namespace")?.message,
|
||||
secretName: res.error?.errors?.find((e) => e.path[0] === "secretName")?.message,
|
||||
secretDataKeyForCrt: res.error?.errors?.find((e) => e.path[0] === "secretDataKeyForCrt")?.message,
|
||||
secretDataKeyForKey: res.error?.errors?.find((e) => e.path[0] === "secretDataKeyForKey")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col space-y-8">
|
||||
@ -41,7 +68,7 @@ const DeployToKubernetesSecret = () => {
|
||||
onChange={(e) => {
|
||||
const newData = produce(data, (draft) => {
|
||||
draft.config ??= {};
|
||||
draft.config.namespace = e.target.value;
|
||||
draft.config.namespace = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -57,7 +84,7 @@ const DeployToKubernetesSecret = () => {
|
||||
onChange={(e) => {
|
||||
const newData = produce(data, (draft) => {
|
||||
draft.config ??= {};
|
||||
draft.config.secretName = e.target.value;
|
||||
draft.config.secretName = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -73,7 +100,7 @@ const DeployToKubernetesSecret = () => {
|
||||
onChange={(e) => {
|
||||
const newData = produce(data, (draft) => {
|
||||
draft.config ??= {};
|
||||
draft.config.secretDataKeyForCrt = e.target.value;
|
||||
draft.config.secretDataKeyForCrt = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -89,7 +116,7 @@ const DeployToKubernetesSecret = () => {
|
||||
onChange={(e) => {
|
||||
const newData = produce(data, (draft) => {
|
||||
draft.config ??= {};
|
||||
draft.config.secretDataKeyForKey = e.target.value;
|
||||
draft.config.secretDataKeyForKey = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -87,35 +87,19 @@ const DeployToLocal = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
format: res.error.errors.find((e) => e.path[0] === "format")?.message,
|
||||
certPath: res.error.errors.find((e) => e.path[0] === "certPath")?.message,
|
||||
keyPath: res.error.errors.find((e) => e.path[0] === "keyPath")?.message,
|
||||
pfxPassword: res.error.errors.find((e) => e.path[0] === "pfxPassword")?.message,
|
||||
jksAlias: res.error.errors.find((e) => e.path[0] === "jksAlias")?.message,
|
||||
jksKeypass: res.error.errors.find((e) => e.path[0] === "jksKeypass")?.message,
|
||||
jksStorepass: res.error.errors.find((e) => e.path[0] === "jksStorepass")?.message,
|
||||
shell: res.error.errors.find((e) => e.path[0] === "shell")?.message,
|
||||
preCommand: res.error.errors.find((e) => e.path[0] === "preCommand")?.message,
|
||||
command: res.error.errors.find((e) => e.path[0] === "command")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
format: undefined,
|
||||
certPath: undefined,
|
||||
keyPath: undefined,
|
||||
pfxPassword: undefined,
|
||||
jksAlias: undefined,
|
||||
jksKeypass: undefined,
|
||||
jksStorepass: undefined,
|
||||
shell: undefined,
|
||||
preCommand: undefined,
|
||||
command: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
format: res.error?.errors?.find((e) => e.path[0] === "format")?.message,
|
||||
certPath: res.error?.errors?.find((e) => e.path[0] === "certPath")?.message,
|
||||
keyPath: res.error?.errors?.find((e) => e.path[0] === "keyPath")?.message,
|
||||
pfxPassword: res.error?.errors?.find((e) => e.path[0] === "pfxPassword")?.message,
|
||||
jksAlias: res.error?.errors?.find((e) => e.path[0] === "jksAlias")?.message,
|
||||
jksKeypass: res.error?.errors?.find((e) => e.path[0] === "jksKeypass")?.message,
|
||||
jksStorepass: res.error?.errors?.find((e) => e.path[0] === "jksStorepass")?.message,
|
||||
shell: res.error?.errors?.find((e) => e.path[0] === "shell")?.message,
|
||||
preCommand: res.error?.errors?.find((e) => e.path[0] === "preCommand")?.message,
|
||||
command: res.error?.errors?.find((e) => e.path[0] === "command")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -27,25 +27,20 @@ const DeployToQiniuCDN = () => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
const formSchema = z.object({
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
<div>
|
||||
@ -55,26 +50,9 @@ const DeployToQiniuCDN = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -80,33 +80,18 @@ const DeployToSSH = () => {
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
if (!res.success) {
|
||||
setError({
|
||||
...error,
|
||||
format: res.error.errors.find((e) => e.path[0] === "format")?.message,
|
||||
certPath: res.error.errors.find((e) => e.path[0] === "certPath")?.message,
|
||||
keyPath: res.error.errors.find((e) => e.path[0] === "keyPath")?.message,
|
||||
pfxPassword: res.error.errors.find((e) => e.path[0] === "pfxPassword")?.message,
|
||||
jksAlias: res.error.errors.find((e) => e.path[0] === "jksAlias")?.message,
|
||||
jksKeypass: res.error.errors.find((e) => e.path[0] === "jksKeypass")?.message,
|
||||
jksStorepass: res.error.errors.find((e) => e.path[0] === "jksStorepass")?.message,
|
||||
preCommand: res.error.errors.find((e) => e.path[0] === "preCommand")?.message,
|
||||
command: res.error.errors.find((e) => e.path[0] === "command")?.message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
format: undefined,
|
||||
certPath: undefined,
|
||||
keyPath: undefined,
|
||||
pfxPassword: undefined,
|
||||
jksAlias: undefined,
|
||||
jksKeypass: undefined,
|
||||
jksStorepass: undefined,
|
||||
preCommand: undefined,
|
||||
command: undefined,
|
||||
});
|
||||
}
|
||||
setError({
|
||||
...error,
|
||||
format: res.error?.errors?.find((e) => e.path[0] === "format")?.message,
|
||||
certPath: res.error?.errors?.find((e) => e.path[0] === "certPath")?.message,
|
||||
keyPath: res.error?.errors?.find((e) => e.path[0] === "keyPath")?.message,
|
||||
pfxPassword: res.error?.errors?.find((e) => e.path[0] === "pfxPassword")?.message,
|
||||
jksAlias: res.error?.errors?.find((e) => e.path[0] === "jksAlias")?.message,
|
||||
jksKeypass: res.error?.errors?.find((e) => e.path[0] === "jksKeypass")?.message,
|
||||
jksStorepass: res.error?.errors?.find((e) => e.path[0] === "jksStorepass")?.message,
|
||||
preCommand: res.error?.errors?.find((e) => e.path[0] === "preCommand")?.message,
|
||||
command: res.error?.errors?.find((e) => e.path[0] === "command")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -13,28 +13,34 @@ const DeployToTencentCDN = () => {
|
||||
const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
|
||||
|
||||
useEffect(() => {
|
||||
setError({});
|
||||
if (!data.id) {
|
||||
setDeploy({
|
||||
...data,
|
||||
config: {
|
||||
domain: "",
|
||||
},
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
const formSchema = z.object({
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
<div>
|
||||
@ -44,26 +50,9 @@ const DeployToTencentCDN = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -8,65 +8,16 @@ import { Label } from "@/components/ui/label";
|
||||
import { useDeployEditContext } from "./DeployEdit";
|
||||
|
||||
const DeployToTencentCOS = () => {
|
||||
const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
useEffect(() => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
const bucketResp = bucketSchema.safeParse(data.config?.bucket);
|
||||
if (!bucketResp.success) {
|
||||
setError({
|
||||
...error,
|
||||
bucket: JSON.parse(bucketResp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
bucket: "",
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const regionResp = regionSchema.safeParse(data.config?.region);
|
||||
if (!regionResp.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: JSON.parse(regionResp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: "",
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
|
||||
|
||||
useEffect(() => {
|
||||
if (!data.id) {
|
||||
setDeploy({
|
||||
...data,
|
||||
config: {
|
||||
region: "",
|
||||
region: "ap-guangzhou",
|
||||
bucket: "",
|
||||
domain: "",
|
||||
},
|
||||
@ -74,17 +25,27 @@ const DeployToTencentCOS = () => {
|
||||
}
|
||||
}, []);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
useEffect(() => {
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
const formSchema = z.object({
|
||||
region: z.string().min(1, t("domain.deployment.form.tencent_cos_region.placeholder")),
|
||||
bucket: z.string().min(1, t("domain.deployment.form.tencent_cos_bucket.placeholder")),
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
const regionSchema = z.string().regex(/^ap-[a-z]+$/, {
|
||||
message: t("domain.deployment.form.tencent_cos_region.placeholder"),
|
||||
});
|
||||
|
||||
const bucketSchema = z.string().regex(/^.+-\d+$/, {
|
||||
message: t("domain.deployment.form.tencent_cos_bucket.placeholder"),
|
||||
});
|
||||
useEffect(() => {
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
region: res.error?.errors?.find((e) => e.path[0] === "region")?.message,
|
||||
bucket: res.error?.errors?.find((e) => e.path[0] === "bucket")?.message,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
@ -95,26 +56,9 @@ const DeployToTencentCOS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.region}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = regionSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
region: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
region: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.region = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.region = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -129,26 +73,9 @@ const DeployToTencentCOS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.bucket}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = bucketSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
bucket: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
bucket: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.bucket = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.bucket = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -163,26 +90,9 @@ const DeployToTencentCOS = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -14,47 +14,36 @@ const DeployToTencentTEO = () => {
|
||||
const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
|
||||
|
||||
useEffect(() => {
|
||||
setError({});
|
||||
if (!data.id) {
|
||||
setDeploy({
|
||||
...data,
|
||||
config: {
|
||||
zoneId: "",
|
||||
},
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const resp = domainSchema.safeParse(data.config?.domain);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
}, [data]);
|
||||
setError({});
|
||||
}, []);
|
||||
|
||||
const formSchema = z.object({
|
||||
zoneId: z.string().min(1, t("domain.deployment.form.tencent_teo_zone_id.placeholder")),
|
||||
domain: z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
}),
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const resp = zoneIdSchema.safeParse(data.config?.zoneId);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
zoneId: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
zoneId: "",
|
||||
});
|
||||
}
|
||||
const res = formSchema.safeParse(data.config);
|
||||
setError({
|
||||
...error,
|
||||
zoneId: res.error?.errors?.find((e) => e.path[0] === "zoneId")?.message,
|
||||
domain: res.error?.errors?.find((e) => e.path[0] === "domain")?.message,
|
||||
});
|
||||
}, [data]);
|
||||
|
||||
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
|
||||
message: t("common.errmsg.domain_invalid"),
|
||||
});
|
||||
|
||||
const zoneIdSchema = z.string().regex(/^zone-[0-9a-zA-Z]{9}$/, {
|
||||
message: t("common.errmsg.zoneid_invalid"),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="flex flex-col space-y-8">
|
||||
<div>
|
||||
@ -64,26 +53,9 @@ const DeployToTencentTEO = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.zoneId}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = zoneIdSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
zoneId: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
zoneId: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.zoneId = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.zoneId = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
@ -98,26 +70,9 @@ const DeployToTencentTEO = () => {
|
||||
className="w-full mt-1"
|
||||
value={data?.config?.domain}
|
||||
onChange={(e) => {
|
||||
const temp = e.target.value;
|
||||
|
||||
const resp = domainSchema.safeParse(temp);
|
||||
if (!resp.success) {
|
||||
setError({
|
||||
...error,
|
||||
domain: JSON.parse(resp.error.message)[0].message,
|
||||
});
|
||||
} else {
|
||||
setError({
|
||||
...error,
|
||||
domain: "",
|
||||
});
|
||||
}
|
||||
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config.domain = temp;
|
||||
draft.config ??= {};
|
||||
draft.config.domain = e.target.value?.trim();
|
||||
});
|
||||
setDeploy(newData);
|
||||
}}
|
||||
|
@ -6,9 +6,16 @@ import KVList from "./KVList";
|
||||
import { type KVType } from "@/domain/domain";
|
||||
|
||||
const DeployToWebhook = () => {
|
||||
const { deploy: data, setDeploy } = useDeployEditContext();
|
||||
const { deploy: data, setDeploy, setError } = useDeployEditContext();
|
||||
|
||||
const { setError } = useDeployEditContext();
|
||||
useEffect(() => {
|
||||
if (!data.id) {
|
||||
setDeploy({
|
||||
...data,
|
||||
config: {},
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
setError({});
|
||||
@ -20,9 +27,7 @@ const DeployToWebhook = () => {
|
||||
variables={data?.config?.variables}
|
||||
onValueChange={(variables: KVType[]) => {
|
||||
const newData = produce(data, (draft) => {
|
||||
if (!draft.config) {
|
||||
draft.config = {};
|
||||
}
|
||||
draft.config ??= {};
|
||||
draft.config.variables = variables;
|
||||
});
|
||||
setDeploy(newData);
|
||||
|
@ -51,7 +51,6 @@
|
||||
"common.errmsg.host_invalid": "Please enter the correct domain name or IP",
|
||||
"common.errmsg.ip_invalid": "Please enter IP",
|
||||
"common.errmsg.url_invalid": "Please enter a valid URL",
|
||||
"common.errmsg.zoneid_invalid": "Please enter Zone ID",
|
||||
|
||||
"common.provider.aliyun": "Alibaba Cloud",
|
||||
"common.provider.aliyun.oss": "Alibaba Cloud - OSS",
|
||||
|
@ -95,6 +95,8 @@
|
||||
"domain.deployment.form.tencent_cos_region.placeholder": "Please enter region (e.g. ap-guangzhou)",
|
||||
"domain.deployment.form.tencent_cos_bucket.label": "Bucket",
|
||||
"domain.deployment.form.tencent_cos_bucket.placeholder": "Please enter bucket",
|
||||
"domain.deployment.form.tencent_cdn_region.label": "Region",
|
||||
"domain.deployment.form.tencent_cdn_region.placeholder": "Please enter region (e.g. ap-guangzhou)",
|
||||
"domain.deployment.form.tencent_clb_region.label": "Region",
|
||||
"domain.deployment.form.tencent_clb_region.placeholder": "Please enter region (e.g. ap-guangzhou)",
|
||||
"domain.deployment.form.tencent_clb_resource_type.label": "Resource Type",
|
||||
|
@ -51,7 +51,6 @@
|
||||
"common.errmsg.host_invalid": "请输入正确的域名或 IP 地址",
|
||||
"common.errmsg.ip_invalid": "请输入正确的 IP 地址",
|
||||
"common.errmsg.url_invalid": "请输入正确的 URL",
|
||||
"common.errmsg.zoneid_invalid": "请输入正确的 Zone ID",
|
||||
|
||||
"common.provider.aliyun": "阿里云",
|
||||
"common.provider.aliyun.oss": "阿里云 - 对象存储 OSS",
|
||||
|
@ -115,6 +115,8 @@
|
||||
"domain.deployment.form.tencent_teo_zone_id.placeholder": "请输入 Zone ID",
|
||||
"domain.deployment.form.tencent_teo_domain.label": "部署到域名(支持泛域名, 应与服务器上配置的域名完全一致, 每行一个域名)",
|
||||
"domain.deployment.form.tencent_teo_domain.placeholder": "请输入部署到的域名",
|
||||
"domain.deployment.form.huaweicloud_cdn_region.label": "地域",
|
||||
"domain.deployment.form.huaweicloud_cdn_region.placeholder": "请输入地域(如 cn-north-1)",
|
||||
"domain.deployment.form.huaweicloud_elb_region.label": "地域",
|
||||
"domain.deployment.form.huaweicloud_elb_region.placeholder": "请输入地域(如 cn-north-1)",
|
||||
"domain.deployment.form.huaweicloud_elb_resource_type.label": "替换方式",
|
||||
|
Loading…
x
Reference in New Issue
Block a user