fix(vercel): set git repos path, fix regex and add error ui
swadhinbiswas committed 9 months ago
3373cc3
1 parent 57ed157
commit 3373cc3
2 files changed
+68 -5
Showing 2 changed files+68-5
▼src/pages/new.astro
+56-4
| @@ -27,6 +27,37 @@ if (!user) { | ||
27 | 27 | </p> |
28 | 28 | </div> |
29 | 29 | |
30 | + <div | |
31 | + id="error-container" | |
32 | + class="hidden mb-6 rounded-md bg-destructive/15 p-4 text-destructive border border-destructive/50" | |
33 | + > | |
34 | + <div class="flex items-start gap-4"> | |
35 | + <svg | |
36 | + xmlns="http://www.w3.org/2000/svg" | |
37 | + width="24" | |
38 | + height="24" | |
39 | + viewBox="0 0 24 24" | |
40 | + fill="none" | |
41 | + stroke="currentColor" | |
42 | + stroke-width="2" | |
43 | + stroke-linecap="round" | |
44 | + stroke-linejoin="round" | |
45 | + class="h-5 w-5" | |
46 | + ><circle cx="12" cy="12" r="10"></circle><path d="m15 9-6 6" | |
47 | + ></path><path d="m9 9 6 6"></path></svg | |
48 | + > | |
49 | + <div> | |
50 | + <h5 | |
51 | + id="error-title" | |
52 | + class="font-medium leading-none tracking-tight mb-1" | |
53 | + > | |
54 | + Error | |
55 | + </h5> | |
56 | + <div id="error-desc" class="text-sm opacity-90"></div> | |
57 | + </div> | |
58 | + </div> | |
59 | + </div> | |
60 | + | |
30 | 61 | <form id="create-repo-form" class="space-y-8"> |
31 | 62 | <Card> |
32 | 63 | <CardHeader> |
| @@ -50,7 +81,7 @@ if (!user) { | ||
50 | 81 | name="name" |
51 | 82 | placeholder="repository-name" |
52 | 83 | required |
53 | - pattern="[a-zA-Z0-9._-]+" | |
84 | + pattern="[a-zA-Z0-9._\\-]+" | |
54 | 85 | title="Only letters, numbers, dots, hyphens, and underscores are allowed." |
55 | 86 | className="w-full md:w-[300px]" |
56 | 87 | /> |
| @@ -230,11 +261,21 @@ if (!user) { | ||
230 | 261 | const submitBtn = document.getElementById( |
231 | 262 | "submit-btn", |
232 | 263 | ) as HTMLButtonElement | null; |
264 | + const errorContainer = document.getElementById( | |
265 | + "error-container", | |
266 | + ) as HTMLDivElement | null; | |
267 | + const errorTitle = document.getElementById( | |
268 | + "error-title", | |
269 | + ) as HTMLElement | null; | |
270 | + const errorDesc = document.getElementById("error-desc") as HTMLElement | null; | |
233 | 271 | |
234 | 272 | if (form && submitBtn) { |
235 | 273 | form.addEventListener("submit", async (e) => { |
236 | 274 | e.preventDefault(); |
237 | 275 | |
276 | + // Reset error | |
277 | + if (errorContainer) errorContainer.classList.add("hidden"); | |
278 | + | |
238 | 279 | // Disable button and show loading state |
239 | 280 | submitBtn.disabled = true; |
240 | 281 | const originalText = submitBtn.innerText; |
| @@ -270,12 +311,23 @@ if (!user) { | ||
270 | 311 | } |
271 | 312 | |
272 | 313 | // Redirect to the new repository |
273 | - // Since we don't have the repo page yet, redirect to dashboard or construct the URL | |
274 | - // The API returns the created repo object which has fullName | |
275 | 314 | window.location.href = `/${result.fullName}`; |
276 | 315 | } catch (error) { |
277 | 316 | console.error("Error creating repository:", error); |
278 | - alert(error instanceof Error ? error.message : "An error occurred"); | |
317 | + | |
318 | + if (errorContainer && errorTitle && errorDesc) { | |
319 | + errorContainer.classList.remove("hidden"); | |
320 | + errorTitle.innerText = "Error creating repository"; | |
321 | + errorDesc.innerText = | |
322 | + error instanceof Error ? error.message : "An error occurred"; | |
323 | + // Scroll to error | |
324 | + errorContainer.scrollIntoView({ | |
325 | + behavior: "smooth", | |
326 | + block: "center", | |
327 | + }); | |
328 | + } else { | |
329 | + alert(error instanceof Error ? error.message : "An error occurred"); | |
330 | + } | |
279 | 331 | |
280 | 332 | // Reset button |
281 | 333 | submitBtn.disabled = false; |
282 | 334 | |
▼vercel.json
+12-1
| @@ -9,5 +9,16 @@ | ||
9 | 9 | } |
10 | 10 | ] |
11 | 11 | } |
12 | - ] | |
12 | + ], | |
13 | + "regions": [ | |
14 | + "bom1" | |
15 | + ], | |
16 | + "env": { | |
17 | + "GIT_REPOS_PATH": "/tmp/repos" | |
18 | + }, | |
19 | + "build": { | |
20 | + "env": { | |
21 | + "GIT_REPOS_PATH": "/tmp/repos" | |
22 | + } | |
23 | + } | |
13 | 24 | } |
14 | 25 | |