Skip to content

Commit baf4635

Browse files
committed
feat(web): Make 'Version' and 'Networks' fields required in Docker Compose
1 parent cd60faf commit baf4635

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

web/src/components/form/form-input.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const FormInput = ({
1111
isNumber,
1212
inputType,
1313
inputClass,
14+
showError = true,
1415
...props
1516
}: FormFieldProps) => {
1617
const { className, ...restProps } = props;
@@ -26,7 +27,7 @@ export const FormInput = ({
2627
return (
2728
<Form.Field
2829
className={cn('form-field relative', {
29-
'mb-6': errorMessage,
30+
'mb-6': errorMessage && showError,
3031
})}
3132
name={name}
3233
>
@@ -49,7 +50,7 @@ export const FormInput = ({
4950
{...restProps}
5051
/>
5152
</Form.Control>
52-
{errorMessage && (
53+
{showError && errorMessage && (
5354
<div className="absolute left-0 top-full">
5455
<Form.Message className="form-message ml-auto text-sm text-red-500">
5556
{errorMessage}

web/src/pages/docker-compose/components/network-fields.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ const NetworkFields: FC = () => {
4141

4242
return (
4343
<div>
44-
<div className="flex items-center justify-between mb-4">
44+
<div className="mb-4 flex items-center justify-between">
4545
<div className="flex items-center">
4646
<p className="text-2xl font-bold">Networks</p>
4747
<button
4848
type="button"
4949
onClick={handleAppendNetwork}
50-
className="ml-4 btn btn-xs"
50+
className="btn btn-xs ml-4"
5151
>
5252
Add <Plus className="size-3" />
5353
</button>
@@ -56,10 +56,10 @@ const NetworkFields: FC = () => {
5656
</div>
5757

5858
<div className="space-y-4">
59-
<div className="w-full p-5 border border-gray-500 rounded-md">
59+
<div className="w-full rounded-md border border-gray-500 p-5">
6060
{fields.map((field, index) => (
6161
<div key={field.id} className="mb-4">
62-
<div className="flex items-center justify-between mb-4">
62+
<div className="mb-4 flex items-center justify-between">
6363
<p className="font-semibold">Network #{index + 1}</p>
6464
{index > 0 && (
6565
<button
@@ -73,7 +73,7 @@ const NetworkFields: FC = () => {
7373

7474
<div>
7575
{customNetwork && (
76-
<div className="flex justify-end mb-2">
76+
<div className="mb-2 flex justify-end">
7777
<FormCheckbox
7878
name={`networks.app_network.${index}.external`}
7979
label="External Network"
@@ -85,6 +85,7 @@ const NetworkFields: FC = () => {
8585
name={`networks.app_network.${index}.network_name`}
8686
label="App Network"
8787
placeholder="network_name"
88+
showError={false}
8889
/>
8990
{!customNetwork && (
9091
<FormSelect
@@ -101,6 +102,7 @@ const NetworkFields: FC = () => {
101102
name={`networks.app_network.${index}.name`}
102103
label="Name"
103104
placeholder="Name"
105+
showError={false}
104106
/>
105107
)}
106108
</div>

web/src/pages/docker-compose/docker-compose.type.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const NetworkSchema = zod.union([
120120
custom: zod.literal(false),
121121
app_network: zod.array(
122122
zod.object({
123-
network_name: zod.string(),
123+
network_name: zod.string().min(1, 'Network name is required.'),
124124
driver: labelValueSchema,
125125
}),
126126
),
@@ -129,16 +129,16 @@ export const NetworkSchema = zod.union([
129129
custom: zod.literal(true),
130130
app_network: zod.array(
131131
zod.object({
132-
network_name: zod.string(),
132+
network_name: zod.string().min(1, 'Network name is required.'),
133133
external: zod.boolean().optional(),
134-
name: zod.string(),
134+
name: zod.string().min(1, 'Name is required.'),
135135
}),
136136
),
137137
}),
138138
]);
139139

140140
export const DockerComposeSchema = zod.object({
141-
version: zod.string(),
141+
version: zod.string().min(1, 'Version is required.'),
142142
services: zod.array(ServiceSchema),
143143
networks: NetworkSchema,
144144
});

web/src/types/form.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type FormFieldProps = {
1111
isNumber?: boolean;
1212
inputType?: typeof HTMLInputElement.prototype.type;
1313
inputClass?: string;
14+
showError?: boolean;
1415
} & ComponentPropsWithoutRef<typeof Form.Field>;
1516

1617
export type FormConfig<T extends z.ZodType> = {

0 commit comments

Comments
 (0)