refactor: clean code

This commit is contained in:
Fu Diwei 2024-10-24 21:42:39 +08:00
parent ee531dd186
commit af3e20709d
5 changed files with 43 additions and 22 deletions

View File

@ -6,7 +6,7 @@ type DeployEditContext = {
deploy: DeployConfig; deploy: DeployConfig;
error: Record<string, string>; error: Record<string, string>;
setDeploy: (deploy: DeployConfig) => void; setDeploy: (deploy: DeployConfig) => void;
setError: (error: Record<string, string>) => void; setError: (error: Record<string, string | undefined>) => void;
}; };
export const Context = createContext<DeployEditContext>({} as DeployEditContext); export const Context = createContext<DeployEditContext>({} as DeployEditContext);

View File

@ -12,6 +12,17 @@ const DeployToAliyunCDN = () => {
const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
useEffect(() => {
if (!data.id) {
setDeploy({
...data,
config: {
domain: "",
},
});
}
}, []);
useEffect(() => { useEffect(() => {
setError({}); setError({});
}, []); }, []);

View File

@ -8,9 +8,22 @@ import { Label } from "@/components/ui/label";
import { useDeployEditContext } from "./DeployEdit"; import { useDeployEditContext } from "./DeployEdit";
const DeployToAliyunOSS = () => { const DeployToAliyunOSS = () => {
const { t } = useTranslation();
const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); 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(() => { useEffect(() => {
setError({}); setError({});
@ -44,20 +57,7 @@ const DeployToAliyunOSS = () => {
bucket: "", bucket: "",
}); });
} }
}, []); }, [data]);
useEffect(() => {
if (!data.id) {
setDeploy({
...data,
config: {
endpoint: "oss-cn-hangzhou.aliyuncs.com",
bucket: "",
domain: "",
},
});
}
}, []);
const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, { const domainSchema = z.string().regex(/^(?:\*\.)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/, {
message: t("common.errmsg.domain_invalid"), message: t("common.errmsg.domain_invalid"),

View File

@ -8,13 +8,8 @@ import { useDeployEditContext } from "./DeployEdit";
const DeployToKubernetesSecret = () => { const DeployToKubernetesSecret = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { setError } = useDeployEditContext();
useEffect(() => { const { deploy: data, setDeploy, setError } = useDeployEditContext();
setError({});
}, []);
const { deploy: data, setDeploy } = useDeployEditContext();
useEffect(() => { useEffect(() => {
if (!data.id) { if (!data.id) {
@ -30,6 +25,10 @@ const DeployToKubernetesSecret = () => {
} }
}, []); }, []);
useEffect(() => {
setError({});
}, []);
return ( return (
<> <>
<div className="flex flex-col space-y-8"> <div className="flex flex-col space-y-8">

View File

@ -12,6 +12,17 @@ const DeployToQiniuCDN = () => {
const { deploy: data, setDeploy, error, setError } = useDeployEditContext(); const { deploy: data, setDeploy, error, setError } = useDeployEditContext();
useEffect(() => {
if (!data.id) {
setDeploy({
...data,
config: {
domain: "",
},
});
}
}, []);
useEffect(() => { useEffect(() => {
setError({}); setError({});
}, []); }, []);