| 1 | "use client"; |
| 2 | |
| 3 | import { Check, Code2 |
| 4 | import { type ReactNode, |
| 5 | import { toast } |
| 6 | |
| 7 | import { Button } |
| 8 | import { |
| 9 | InputGroup, |
| 10 | InputGroupAddon, |
| 11 | InputGroupButton, |
| 12 | InputGroupInput, |
| 13 | } from "@/components/ui/input-group"; |
| 14 | import { |
| 15 | Popover, |
| 16 | PopoverContent, |
| 17 | PopoverTrigger, |
| 18 | } from "@/components/ui/popover"; |
| 19 | import { Tabs, TabsContent |
| 20 | |
| 21 | export function ClonePopover({ |
| 22 | cloneUrl, |
| 23 | sshCloneUrl, |
| 24 | }: { |
| 25 | cloneUrl: string |
| 26 | sshCloneUrl?: string |
| 27 | }) { |
| 28 | return ( |
| 29 | <Popover> |
| 30 | <PopoverTrigger asChild> |
| 31 | <Button size=" |
| 32 | <Code2 data-icon=" |
| 33 | Code |
| 34 | </Button> |
| 35 | </PopoverTrigger> |
| 36 | |
| 37 | <PopoverContent align=" |
| 38 | <div className="flex flex-col gap-2 |
| 39 | <p className="text-sm font-semibold |
| 40 | <CloneTransports |
| 41 | http={ |
| 42 | <> |
| 43 | <CloneUrlField cloneUrl={ |
| 44 | <p className="text-xs text-muted-foreground |
| 45 | The password is a personal access token from account settings, |
| 46 | not your login password. |
| 47 | </p> |
| 48 | </> |
| 49 | } |
| 50 | ssh={ |
| 51 | sshCloneUrl && ( |
| 52 | <> |
| 53 | <CloneUrlField cloneUrl={ |
| 54 | <p className="text-xs text-muted-foreground |
| 55 | Needs an SSH key on your account. Log in as <code>git</code> |
| 56 | ; the key says who you are. |
| 57 | </p> |
| 58 | </> |
| 59 | ) |
| 60 | } |
| 61 | /> |
| 62 | </div> |
| 63 | </PopoverContent> |
| 64 | </Popover> |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | /** One transport, or a tab per transport. An instance with no SSH listener has nothing to switch between, so it gets the HTTP panel on its own. */ |
| 69 | export function CloneTransports({ |
| 70 | http, |
| 71 | ssh, |
| 72 | }: { |
| 73 | http: ReactNode |
| 74 | ssh?: ReactNode |
| 75 | }) { |
| 76 | if (!ssh) |
| 77 | |
| 78 | return ( |
| 79 | <Tabs defaultValue=" |
| 80 | <TabsList className=" |
| 81 | <TabsTrigger value=" |
| 82 | <TabsTrigger value=" |
| 83 | </TabsList> |
| 84 | <TabsContent value=" |
| 85 | {http} |
| 86 | </TabsContent> |
| 87 | <TabsContent value=" |
| 88 | {ssh} |
| 89 | </TabsContent> |
| 90 | </Tabs> |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | export function CloneUrlField({ |
| 95 | const [copied, |
| 96 | |
| 97 | async function copy |
| 98 | try { |
| 99 | await navigator.clipboard |
| 100 | setCopied(true); |
| 101 | setTimeout(() => |
| 102 | } catch { |
| 103 | toast.error("Could not copy the clone URL. |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return ( |
| 108 | <InputGroup> |
| 109 | <InputGroupInput readOnly value |
| 110 | <InputGroupAddon align=" |
| 111 | <InputGroupButton |
| 112 | size="icon-xs" |
| 113 | aria-label="Copy clone URL" |
| 114 | onClick={copy} |
| 115 | > |
| 116 | {copied ? <Check |
| 117 | </InputGroupButton> |
| 118 | </InputGroupAddon> |
| 119 | </InputGroup> |
| 120 | ); |
| 121 | } |