Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/dashboard/src/onboarding/OnboardingStep.tsx
2500 views
1
/**
2
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
* Licensed under the GNU Affero General Public License (AGPL).
4
* See License.AGPL.txt in the project root for license information.
5
*/
6
7
import { FC, FormEvent, useCallback } from "react";
8
import Alert from "../components/Alert";
9
import { Button, ButtonProps } from "@podkit/buttons/Button";
10
import { Heading2, Subheading } from "../components/typography/headings";
11
import { LoadingButton } from "@podkit/buttons/LoadingButton";
12
13
type Props = {
14
title: string;
15
subtitle?: string;
16
isValid: boolean;
17
isSaving?: boolean;
18
error?: string;
19
onSubmit(): void;
20
submitButtonText?: string;
21
submitButtonType?: ButtonProps["variant"];
22
onCancel?(): void;
23
cancelButtonText?: string;
24
cancelButtonType?: ButtonProps["variant"];
25
};
26
export const OnboardingStep: FC<Props> = ({
27
title,
28
subtitle,
29
isValid,
30
isSaving = false,
31
error,
32
children,
33
onSubmit,
34
submitButtonText,
35
submitButtonType,
36
onCancel,
37
cancelButtonText,
38
cancelButtonType,
39
}) => {
40
const handleSubmit = useCallback(
41
async (e: FormEvent<HTMLFormElement>) => {
42
e.preventDefault();
43
if (isSaving || !isValid) {
44
return;
45
}
46
47
onSubmit();
48
},
49
[isSaving, isValid, onSubmit],
50
);
51
52
return (
53
<div className="flex flex-col items-center justify-center max-w-full">
54
{/* Intentionally adjusting the size of the heading here */}
55
<Heading2 className="text-4xl">{title}</Heading2>
56
{subtitle && <Subheading>{subtitle}</Subheading>}
57
58
<form className="mt-8 mb-14 max-w-lg" onSubmit={handleSubmit}>
59
{/* Form contents provided as children */}
60
{children}
61
62
{error && <Alert type="error">{error}</Alert>}
63
64
<div className={"mt-4" + (onCancel ? " flex space-x-2" : "")}>
65
{onCancel && (
66
<Button
67
type="button"
68
variant={cancelButtonType || "secondary"}
69
disabled={isSaving}
70
onClick={onCancel}
71
>
72
{cancelButtonText || "Cancel"}
73
</Button>
74
)}
75
<LoadingButton
76
type="submit"
77
variant={submitButtonType || "default"}
78
disabled={!isValid || isSaving}
79
className="w-full"
80
loading={isSaving}
81
>
82
{submitButtonText || "Continue"}
83
</LoadingButton>
84
</div>
85
</form>
86
</div>
87
);
88
};
89
90