-
Notifications
You must be signed in to change notification settings - Fork 894
feat: add license settings UI #7210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
d1e0377
wip: license page
rodrimaia 16e0a5c
WIP
rodrimaia 432456f
WIP
rodrimaia a26bdc1
wip
rodrimaia 496f535
wip
rodrimaia bcb5d9a
wip
rodrimaia 7adf2f1
wip
rodrimaia 8ece196
wip
rodrimaia 3774944
wip
rodrimaia 5b782ce
Apply suggestions from code review
rodrimaia eaba405
wip: ui improvements
rodrimaia 1d107d8
Merge branch 'main' into add_license_settings
rodrimaia ee583e1
wip: extract components
rodrimaia 21a610e
wip: stories
rodrimaia fba262c
wip: stories
rodrimaia 0922b5b
fixes from PR reviews
rodrimaia 6ab9d3e
fix stories
rodrimaia 8d55d98
fix empty license page
rodrimaia 832f599
fix copy
rodrimaia c3a1141
fix
rodrimaia 16a8445
wip
rodrimaia 0322172
add golang test
rodrimaia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
site/src/pages/DeploySettingsPage/LicensesSettingsPage/AddNewLicensePageView.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import AddNewLicensePageView from "./AddNewLicensePageView" | ||
|
||
export default { | ||
title: "pages/AddNewLicensePageView", | ||
component: AddNewLicensePageView, | ||
} | ||
|
||
export const Default = () => <AddNewLicensePageView /> |
179 changes: 179 additions & 0 deletions
179
site/src/pages/DeploySettingsPage/LicensesSettingsPage/AddNewLicensePageView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
import Button from "@material-ui/core/Button" | ||
import TextField from "@material-ui/core/TextField" | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import CloudUploadOutlined from "@material-ui/icons/CloudUploadOutlined" | ||
import { useMutation } from "@tanstack/react-query" | ||
import { createLicense } from "api/api" | ||
import { Fieldset } from "components/DeploySettingsLayout/Fieldset" | ||
import { Header } from "components/DeploySettingsLayout/Header" | ||
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils" | ||
import { Stack } from "components/Stack/Stack" | ||
import { DropzoneDialog } from "material-ui-dropzone" | ||
import { FC, PropsWithChildren } from "react" | ||
import { Link as RouterLink, useNavigate } from "react-router-dom" | ||
import { useToggle } from "react-use" | ||
|
||
const AddNewLicense: FC = () => { | ||
const styles = useStyles() | ||
const [isDialogOpen, toggleDialogOpen] = useToggle(false) | ||
const navigate = useNavigate() | ||
|
||
const { | ||
mutate: saveLicenseKeyApi, | ||
isLoading: isCreating, | ||
isError: creationFailed, | ||
} = useMutation(createLicense) | ||
|
||
function handleFileUploaded(files: File[]) { | ||
const fileReader = new FileReader() | ||
fileReader.onload = () => { | ||
const licenseKey = fileReader.result as string | ||
|
||
saveLicenseKey(licenseKey) | ||
|
||
fileReader.onerror = () => { | ||
displayError("Failed to read file") | ||
} | ||
} | ||
|
||
fileReader.readAsText(files[0]) | ||
} | ||
|
||
function saveLicenseKey(licenseKey: string) { | ||
saveLicenseKeyApi( | ||
{ license: licenseKey }, | ||
{ | ||
onSuccess: () => { | ||
displaySuccess("License key saved") | ||
navigate("/settings/deployment/licenses?success=true") | ||
}, | ||
rodrimaia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onError: () => displayError("Failed to save license key"), | ||
}, | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Stack | ||
alignItems="baseline" | ||
direction="row" | ||
justifyContent="space-between" | ||
> | ||
<Header | ||
title="Add your license" | ||
description="Add a license to your account to unlock more features." | ||
/> | ||
rodrimaia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Button | ||
component={RouterLink} | ||
to="/settings/deployment/licenses" | ||
variant="outlined" | ||
> | ||
Back to licenses | ||
</Button> | ||
</Stack> | ||
|
||
<Stack className={styles.main}> | ||
<Stack alignItems="center"> | ||
<Button | ||
className={styles.ctaButton} | ||
startIcon={<CloudUploadOutlined />} | ||
size="large" | ||
onClick={() => toggleDialogOpen()} | ||
> | ||
Upload License Key | ||
rodrimaia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Button> | ||
</Stack> | ||
<DropzoneDialog | ||
open={isDialogOpen} | ||
onSave={handleFileUploaded} | ||
showPreviews | ||
maxFileSize={1000000} | ||
onClose={() => toggleDialogOpen(false)} | ||
/> | ||
|
||
<DividerWithText>or</DividerWithText> | ||
|
||
<Fieldset | ||
title="Paste your license key" | ||
validation={creationFailed ? "License key is invalid" : undefined} | ||
onSubmit={(e) => { | ||
e.preventDefault() | ||
|
||
const form = e.target | ||
const formData = new FormData(form as HTMLFormElement) | ||
|
||
const licenseKey = formData.get("licenseKey") | ||
|
||
saveLicenseKey(licenseKey?.toString() || "") | ||
}} | ||
button={ | ||
<Button type="submit" disabled={isCreating}> | ||
Save License | ||
</Button> | ||
rodrimaia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
> | ||
<TextField | ||
name="licenseKey" | ||
placeholder="Paste your license key here" | ||
multiline | ||
rows={4} | ||
fullWidth | ||
/> | ||
</Fieldset> | ||
</Stack> | ||
</> | ||
) | ||
} | ||
|
||
export default AddNewLicense | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
main: { | ||
paddingTop: theme.spacing(5), | ||
}, | ||
ctaButton: { | ||
backgroundImage: `linear-gradient(90deg, ${theme.palette.secondary.main} 0%, ${theme.palette.secondary.dark} 100%)`, | ||
width: theme.spacing(30), | ||
marginBottom: theme.spacing(4), | ||
}, | ||
formSectionRoot: { | ||
alignItems: "center", | ||
}, | ||
description: { | ||
color: theme.palette.text.secondary, | ||
lineHeight: "160%", | ||
}, | ||
title: { | ||
...theme.typography.h5, | ||
fontWeight: 600, | ||
marging: theme.spacing(1), | ||
}, | ||
container: { | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
border: { | ||
borderBottom: `2px solid ${theme.palette.divider}`, | ||
width: "100%", | ||
}, | ||
content: { | ||
paddingTop: theme.spacing(0.5), | ||
paddingBottom: theme.spacing(0.5), | ||
paddingRight: theme.spacing(2), | ||
paddingLeft: theme.spacing(2), | ||
fontWeight: 500, | ||
fontSize: theme.typography.h5.fontSize, | ||
color: theme.palette.text.secondary, | ||
}, | ||
})) | ||
|
||
const DividerWithText: FC<PropsWithChildren> = ({ children }) => { | ||
const classes = useStyles() | ||
return ( | ||
<div className={classes.container}> | ||
<div className={classes.border} /> | ||
<span className={classes.content}>{children}</span> | ||
<div className={classes.border} /> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.