Skip to content

Commit a32e7e0

Browse files
committed
fix(build-server): enforce selection rules for Build Server and Build Registry
- Updated validation schema to require that both Build Server and Build Registry must be selected together or both set to None. - Added informational alert to guide users on the selection requirements. - Enhanced onChange handlers to reset the corresponding field when one is set to "none".
1 parent ee9edd7 commit a32e7e0

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

apps/dokploy/components/dashboard/application/advanced/show-build-server.tsx

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,31 @@ interface Props {
3838
applicationId: string;
3939
}
4040

41-
const schema = z.object({
42-
buildServerId: z.string().min(1, "Build server is required"),
43-
buildRegistryId: z.string().min(1, "Build registry is required"),
44-
});
41+
const schema = z
42+
.object({
43+
buildServerId: z.string().optional(),
44+
buildRegistryId: z.string().optional(),
45+
})
46+
.refine(
47+
(data) => {
48+
// Both empty/none is valid
49+
const buildServerIsNone =
50+
!data.buildServerId || data.buildServerId === "none";
51+
const buildRegistryIsNone =
52+
!data.buildRegistryId || data.buildRegistryId === "none";
53+
54+
// Both should be either filled or empty
55+
if (buildServerIsNone && buildRegistryIsNone) return true;
56+
if (!buildServerIsNone && !buildRegistryIsNone) return true;
57+
58+
return false;
59+
},
60+
{
61+
message:
62+
"Both Build Server and Build Registry must be selected together, or both set to None",
63+
path: ["buildServerId"], // Show error on buildServerId field
64+
},
65+
);
4566

4667
type Schema = z.infer<typeof schema>;
4768

@@ -121,6 +142,11 @@ export const ShowBuildServer = ({ applicationId }: Props) => {
121142
container starts running.
122143
</AlertBlock>
123144

145+
<AlertBlock type="info">
146+
<strong>Note:</strong> Build Server and Build Registry must be
147+
configured together. You can either select both or set both to None.
148+
</AlertBlock>
149+
124150
{!registries || registries.length === 0 ? (
125151
<AlertBlock type="warning">
126152
You need to add at least one registry to use build servers. Please
@@ -147,7 +173,13 @@ export const ShowBuildServer = ({ applicationId }: Props) => {
147173
<FormItem>
148174
<FormLabel>Build Server</FormLabel>
149175
<Select
150-
onValueChange={field.onChange}
176+
onValueChange={(value) => {
177+
field.onChange(value);
178+
// If setting to "none", also reset build registry to "none"
179+
if (value === "none") {
180+
form.setValue("buildRegistryId", "none");
181+
}
182+
}}
151183
value={field.value || "none"}
152184
>
153185
<FormControl>
@@ -197,7 +229,13 @@ export const ShowBuildServer = ({ applicationId }: Props) => {
197229
<FormItem>
198230
<FormLabel>Build Registry</FormLabel>
199231
<Select
200-
onValueChange={field.onChange}
232+
onValueChange={(value) => {
233+
field.onChange(value);
234+
// If setting to "none", also reset build server to "none"
235+
if (value === "none") {
236+
form.setValue("buildServerId", "none");
237+
}
238+
}}
201239
value={field.value || "none"}
202240
>
203241
<FormControl>

0 commit comments

Comments
 (0)