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

View File

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

View File

@ -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"),

View File

@ -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 (
<>
<div className="flex flex-col space-y-8">

View File

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