From af3e20709d13e67a9b6cd5c40c30ddc6f8ddf418 Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Thu, 24 Oct 2024 21:42:39 +0800 Subject: [PATCH] refactor: clean code --- ui/src/components/certimate/DeployEdit.tsx | 2 +- .../certimate/DeployToAliyunCDN.tsx | 11 +++++++ .../certimate/DeployToAliyunOSS.tsx | 30 +++++++++---------- .../certimate/DeployToKubernetesSecret.tsx | 11 ++++--- .../components/certimate/DeployToQiniuCDN.tsx | 11 +++++++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/ui/src/components/certimate/DeployEdit.tsx b/ui/src/components/certimate/DeployEdit.tsx index 0b22fcd2..11903b79 100644 --- a/ui/src/components/certimate/DeployEdit.tsx +++ b/ui/src/components/certimate/DeployEdit.tsx @@ -6,7 +6,7 @@ type DeployEditContext = { deploy: DeployConfig; error: Record; setDeploy: (deploy: DeployConfig) => void; - setError: (error: Record) => void; + setError: (error: Record) => void; }; export const Context = createContext({} as DeployEditContext); diff --git a/ui/src/components/certimate/DeployToAliyunCDN.tsx b/ui/src/components/certimate/DeployToAliyunCDN.tsx index d6735473..074f27a0 100644 --- a/ui/src/components/certimate/DeployToAliyunCDN.tsx +++ b/ui/src/components/certimate/DeployToAliyunCDN.tsx @@ -12,6 +12,17 @@ const DeployToAliyunCDN = () => { const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); + useEffect(() => { + if (!data.id) { + setDeploy({ + ...data, + config: { + domain: "", + }, + }); + } + }, []); + useEffect(() => { setError({}); }, []); diff --git a/ui/src/components/certimate/DeployToAliyunOSS.tsx b/ui/src/components/certimate/DeployToAliyunOSS.tsx index ea110cde..ccfcc870 100644 --- a/ui/src/components/certimate/DeployToAliyunOSS.tsx +++ b/ui/src/components/certimate/DeployToAliyunOSS.tsx @@ -8,9 +8,22 @@ import { Label } from "@/components/ui/label"; import { useDeployEditContext } from "./DeployEdit"; const DeployToAliyunOSS = () => { + const { t } = useTranslation(); + const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); - const { t } = useTranslation(); + useEffect(() => { + if (!data.id) { + setDeploy({ + ...data, + config: { + endpoint: "oss-cn-hangzhou.aliyuncs.com", + bucket: "", + domain: "", + }, + }); + } + }, []); useEffect(() => { setError({}); @@ -44,20 +57,7 @@ const DeployToAliyunOSS = () => { bucket: "", }); } - }, []); - - useEffect(() => { - if (!data.id) { - setDeploy({ - ...data, - config: { - endpoint: "oss-cn-hangzhou.aliyuncs.com", - bucket: "", - domain: "", - }, - }); - } - }, []); + }, [data]); const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, { message: t("common.errmsg.domain_invalid"), diff --git a/ui/src/components/certimate/DeployToKubernetesSecret.tsx b/ui/src/components/certimate/DeployToKubernetesSecret.tsx index c5129324..c7b8e2a8 100644 --- a/ui/src/components/certimate/DeployToKubernetesSecret.tsx +++ b/ui/src/components/certimate/DeployToKubernetesSecret.tsx @@ -8,13 +8,8 @@ import { useDeployEditContext } from "./DeployEdit"; const DeployToKubernetesSecret = () => { const { t } = useTranslation(); - const { setError } = useDeployEditContext(); - useEffect(() => { - setError({}); - }, []); - - const { deploy: data, setDeploy } = useDeployEditContext(); + const { deploy: data, setDeploy, setError } = useDeployEditContext(); useEffect(() => { if (!data.id) { @@ -30,6 +25,10 @@ const DeployToKubernetesSecret = () => { } }, []); + useEffect(() => { + setError({}); + }, []); + return ( <>
diff --git a/ui/src/components/certimate/DeployToQiniuCDN.tsx b/ui/src/components/certimate/DeployToQiniuCDN.tsx index 327edce8..e4749206 100644 --- a/ui/src/components/certimate/DeployToQiniuCDN.tsx +++ b/ui/src/components/certimate/DeployToQiniuCDN.tsx @@ -12,6 +12,17 @@ const DeployToQiniuCDN = () => { const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); + useEffect(() => { + if (!data.id) { + setDeploy({ + ...data, + config: { + domain: "", + }, + }); + } + }, []); + useEffect(() => { setError({}); }, []);