56 lines · 2.1 KB
| 1 | --- |
| 2 | import Base from '../layouts/Base.astro'; |
| 3 | import { apiPost } from '../lib/api'; |
| 4 | |
| 5 | let error = ''; |
| 6 | |
| 7 | if (Astro.request.method === 'POST') { |
| 8 | try { |
| 9 | const formData = await Astro.request.formData(); |
| 10 | const name = formData.get('name') as string; |
| 11 | const description = formData.get('description') as string; |
| 12 | const isPrivate = formData.get('visibility') === 'private'; |
| 13 | |
| 14 | const cookie = Astro.request.headers.get('cookie') || ''; |
| 15 | const { data } = await apiPost('/api/repos', { name, description, is_private: isPrivate }, cookie); |
| 16 | |
| 17 | // We need the owner username — for now redirect to home |
| 18 | return Astro.redirect('/'); |
| 19 | } catch (e: any) { |
| 20 | error = e.message; |
| 21 | } |
| 22 | } |
| 23 | --- |
| 24 | |
| 25 | <Base title="New repository"> |
| 26 | <div class="container" style="max-width: 600px; padding-top: 24px;"> |
| 27 | <h1 style="font-size: 1.5rem; margin-bottom: 20px;">Create a new repository</h1> |
| 28 | |
| 29 | {error && <div class="flash-error">{error}</div>} |
| 30 | |
| 31 | <form method="POST" class="card"> |
| 32 | <div class="form-group"> |
| 33 | <label for="name">Repository name</label> |
| 34 | <input type="text" id="name" name="name" required pattern="[a-zA-Z0-9._-]{1,64}" |
| 35 | placeholder="my-awesome-project" /> |
| 36 | </div> |
| 37 | <div class="form-group"> |
| 38 | <label for="description">Description <span style="color: var(--text-muted); font-weight: normal;">(optional)</span></label> |
| 39 | <input type="text" id="description" name="description" placeholder="Short description of your repository" /> |
| 40 | </div> |
| 41 | <div class="form-group"> |
| 42 | <label>Visibility</label> |
| 43 | <div style="display: flex; gap: 16px; margin-top: 4px;"> |
| 44 | <label style="display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer;"> |
| 45 | <input type="radio" name="visibility" value="public" checked /> Public |
| 46 | </label> |
| 47 | <label style="display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer;"> |
| 48 | <input type="radio" name="visibility" value="private" /> Private |
| 49 | </label> |
| 50 | </div> |
| 51 | </div> |
| 52 | <button type="submit" class="btn btn-primary">Create repository</button> |
| 53 | </form> |
| 54 | </div> |
| 55 | </Base> |
| 56 |