Skip to content

Commit eab691b

Browse files
committed
react components for one click
1 parent f32b98c commit eab691b

File tree

5 files changed

+110
-0
lines changed

5 files changed

+110
-0
lines changed

docs/tutorials/adding-custom-one-click-deploy.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ sidebar_position: 800
44
description: Add a custom 1-Click Deploy button to deploy your own app.
55
---
66

7+
import {OriginalRepoUrl, TemplateUrl, EncodedTemplateUrl, OneClickUrl} from '../../src/components/URLEncoder';
8+
79
# Adding a Custom 1-Click Deploy
810

911
This tutorial will show you how to add a custom Defang 1-Click Deploy button to deploy your own app to Defang Playground.
@@ -113,6 +115,11 @@ https://github.com/<your-github-username>/<your-project-here>
113115
https%3A%2F%2Fgithub.com%2F<your-github-username>%2F<your-project-here>
114116
```
115117

118+
<OriginalRepoUrl/>
119+
<TemplateUrl/>
120+
<EncodedTemplateUrl/>
121+
<OneClickUrl/>
122+
116123
## Step 5 - Create the 1-Click Deploy Link
117124

118125
Finally, you will need to format the 1-Click Deploy Link as `https://portal.defang.dev/redirect?url=` + your encoded URL. This ensures that the user can get [logged in](/docs/concepts/authentication/) to Defang before they get redirected to clone your app for deployment.

package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"docusaurus-lunr-search": "^3.2.0",
2929
"fuse.js": "^7.0.0",
3030
"gray-matter": "^4.0.3",
31+
"jotai": "^2.11.0",
3132
"prism-react-renderer": "^2.1.0",
3233
"react": "^18.2.0",
3334
"react-dom": "^18.2.0",
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Stack, TextField } from '@mui/material';
2+
import { useState } from 'react';
3+
import {atom, useAtom} from 'jotai';
4+
5+
const urlAtom = atom("");
6+
7+
export function OriginalRepoUrl(){
8+
const [url, setUrl] = useState("");
9+
return (
10+
<Stack spacing={2}>
11+
<TextField value={url} onChange={e => setUrl(e.target.value)} label="Your Repo URL" helperText="Like https://github.com/defanglabs/defang" />
12+
</Stack>
13+
);
14+
}
15+
16+
function getTemplateUrl(url: string){
17+
// extract github user and repo from url
18+
const regex = /https:\/\/github.com\/([^\/]+)\/([^\/]+)/;
19+
const match = url.match(regex);
20+
const user = match ? match[1] : "";
21+
const repo = match ? match[2] : "";
22+
23+
// https://github.com/new?template_name=sample-django-template&template_owner=DefangSamples
24+
return `https://github.com/new?template_name=${repo}&template_owner=${user}&name=${repo}`;
25+
}
26+
27+
export function TemplateUrl(){
28+
const [url] = useAtom(urlAtom);
29+
30+
const templateUrl = getTemplateUrl(url);
31+
32+
return (
33+
<Stack spacing={2}>
34+
<TextField value={templateUrl} label="Your Template URL" />
35+
</Stack>
36+
);
37+
}
38+
39+
function getEncodedTemplateUrl(url: string){
40+
const templateUrl = getTemplateUrl(url);
41+
return encodeURIComponent(templateUrl);
42+
}
43+
44+
45+
export function EncodedTemplateUrl(){
46+
const [url] = useAtom(urlAtom);
47+
const encodedTemplateUrl = getEncodedTemplateUrl(url);
48+
return (
49+
<Stack spacing={2}>
50+
<TextField value={encodedTemplateUrl} label="The Encoded Template URL" />
51+
</Stack>
52+
);
53+
}
54+
55+
function getOneClickUrl(url: string){
56+
const encodedTemplateUrl = getEncodedTemplateUrl(url);
57+
return `https://portal.defang.dev/redirect?url=${encodedTemplateUrl}`;
58+
}
59+
60+
61+
export function OneClickUrl(){
62+
const [url] = useAtom(urlAtom);
63+
const oneClickUrl = getOneClickUrl(url);
64+
return (
65+
<Stack spacing={2}>
66+
<TextField value={oneClickUrl} label="Your 1-Click URL" />
67+
</Stack>
68+
);
69+
}
70+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.features {
2+
display: flex;
3+
align-items: center;
4+
padding: 2rem 0;
5+
width: 100%;
6+
}
7+
8+
.featureSvg {
9+
height: 200px;
10+
width: 200px;
11+
}

0 commit comments

Comments
 (0)