|
| 1 | +import { zodResolver } from "@hookform/resolvers/zod"; |
| 2 | +import { CircuitBoard, HelpCircle } from "lucide-react"; |
| 3 | +import { useEffect, useState } from "react"; |
| 4 | +import { useForm } from "react-hook-form"; |
| 5 | +import { toast } from "sonner"; |
| 6 | +import { z } from "zod"; |
1 | 7 | import { AlertBlock } from "@/components/shared/alert-block";
|
2 | 8 | import { Button } from "@/components/ui/button";
|
3 | 9 | import {
|
@@ -37,12 +43,6 @@ import {
|
37 | 43 | } from "@/components/ui/tooltip";
|
38 | 44 | import { slugify } from "@/lib/slug";
|
39 | 45 | import { api } from "@/utils/api";
|
40 |
| -import { zodResolver } from "@hookform/resolvers/zod"; |
41 |
| -import { CircuitBoard, HelpCircle } from "lucide-react"; |
42 |
| -import { useEffect, useState } from "react"; |
43 |
| -import { useForm } from "react-hook-form"; |
44 |
| -import { toast } from "sonner"; |
45 |
| -import { z } from "zod"; |
46 | 46 |
|
47 | 47 | const AddComposeSchema = z.object({
|
48 | 48 | composeType: z.enum(["docker-compose", "stack"]).optional(),
|
@@ -78,6 +78,8 @@ export const AddCompose = ({ projectId, projectName }: Props) => {
|
78 | 78 | const { mutateAsync, isLoading, error, isError } =
|
79 | 79 | api.compose.create.useMutation();
|
80 | 80 |
|
| 81 | + const hasServers = servers && servers.length > 0; |
| 82 | + |
81 | 83 | const form = useForm<AddCompose>({
|
82 | 84 | defaultValues: {
|
83 | 85 | name: "",
|
@@ -163,62 +165,64 @@ export const AddCompose = ({ projectId, projectName }: Props) => {
|
163 | 165 | )}
|
164 | 166 | />
|
165 | 167 | </div>
|
166 |
| - <FormField |
167 |
| - control={form.control} |
168 |
| - name="serverId" |
169 |
| - render={({ field }) => ( |
170 |
| - <FormItem> |
171 |
| - <TooltipProvider delayDuration={0}> |
172 |
| - <Tooltip> |
173 |
| - <TooltipTrigger asChild> |
174 |
| - <FormLabel className="break-all w-fit flex flex-row gap-1 items-center"> |
175 |
| - Select a Server {!isCloud ? "(Optional)" : ""} |
176 |
| - <HelpCircle className="size-4 text-muted-foreground" /> |
177 |
| - </FormLabel> |
178 |
| - </TooltipTrigger> |
179 |
| - <TooltipContent |
180 |
| - className="z-[999] w-[300px]" |
181 |
| - align="start" |
182 |
| - side="top" |
183 |
| - > |
184 |
| - <span> |
185 |
| - If no server is selected, the application will be |
186 |
| - deployed on the server where the user is logged in. |
187 |
| - </span> |
188 |
| - </TooltipContent> |
189 |
| - </Tooltip> |
190 |
| - </TooltipProvider> |
| 168 | + {hasServers && ( |
| 169 | + <FormField |
| 170 | + control={form.control} |
| 171 | + name="serverId" |
| 172 | + render={({ field }) => ( |
| 173 | + <FormItem> |
| 174 | + <TooltipProvider delayDuration={0}> |
| 175 | + <Tooltip> |
| 176 | + <TooltipTrigger asChild> |
| 177 | + <FormLabel className="break-all w-fit flex flex-row gap-1 items-center"> |
| 178 | + Select a Server {!isCloud ? "(Optional)" : ""} |
| 179 | + <HelpCircle className="size-4 text-muted-foreground" /> |
| 180 | + </FormLabel> |
| 181 | + </TooltipTrigger> |
| 182 | + <TooltipContent |
| 183 | + className="z-[999] w-[300px]" |
| 184 | + align="start" |
| 185 | + side="top" |
| 186 | + > |
| 187 | + <span> |
| 188 | + If no server is selected, the application will be |
| 189 | + deployed on the server where the user is logged in. |
| 190 | + </span> |
| 191 | + </TooltipContent> |
| 192 | + </Tooltip> |
| 193 | + </TooltipProvider> |
191 | 194 |
|
192 |
| - <Select |
193 |
| - onValueChange={field.onChange} |
194 |
| - defaultValue={field.value} |
195 |
| - > |
196 |
| - <SelectTrigger> |
197 |
| - <SelectValue placeholder="Select a Server" /> |
198 |
| - </SelectTrigger> |
199 |
| - <SelectContent> |
200 |
| - <SelectGroup> |
201 |
| - {servers?.map((server) => ( |
202 |
| - <SelectItem |
203 |
| - key={server.serverId} |
204 |
| - value={server.serverId} |
205 |
| - > |
206 |
| - <span className="flex items-center gap-2 justify-between w-full"> |
207 |
| - <span>{server.name}</span> |
208 |
| - <span className="text-muted-foreground text-xs self-center"> |
209 |
| - {server.ipAddress} |
| 195 | + <Select |
| 196 | + onValueChange={field.onChange} |
| 197 | + defaultValue={field.value} |
| 198 | + > |
| 199 | + <SelectTrigger> |
| 200 | + <SelectValue placeholder="Select a Server" /> |
| 201 | + </SelectTrigger> |
| 202 | + <SelectContent> |
| 203 | + <SelectGroup> |
| 204 | + {servers?.map((server) => ( |
| 205 | + <SelectItem |
| 206 | + key={server.serverId} |
| 207 | + value={server.serverId} |
| 208 | + > |
| 209 | + <span className="flex items-center gap-2 justify-between w-full"> |
| 210 | + <span>{server.name}</span> |
| 211 | + <span className="text-muted-foreground text-xs self-center"> |
| 212 | + {server.ipAddress} |
| 213 | + </span> |
210 | 214 | </span>
|
211 |
| - </span> |
212 |
| - </SelectItem> |
213 |
| - ))} |
214 |
| - <SelectLabel>Servers ({servers?.length})</SelectLabel> |
215 |
| - </SelectGroup> |
216 |
| - </SelectContent> |
217 |
| - </Select> |
218 |
| - <FormMessage /> |
219 |
| - </FormItem> |
220 |
| - )} |
221 |
| - /> |
| 215 | + </SelectItem> |
| 216 | + ))} |
| 217 | + <SelectLabel>Servers ({servers?.length})</SelectLabel> |
| 218 | + </SelectGroup> |
| 219 | + </SelectContent> |
| 220 | + </Select> |
| 221 | + <FormMessage /> |
| 222 | + </FormItem> |
| 223 | + )} |
| 224 | + /> |
| 225 | + )} |
222 | 226 | <FormField
|
223 | 227 | control={form.control}
|
224 | 228 | name="appName"
|
|
0 commit comments