2022-12-11 06:58:22 +00:00
|
|
|
import { Field, Form, Formik } from 'formik';
|
|
|
|
import { object, SchemaOf, string } from 'yup';
|
|
|
|
|
|
|
|
import { useUpgradeEditionMutation } from '@/react/portainer/system/useUpgradeEditionMutation';
|
|
|
|
import { notifySuccess } from '@/portainer/services/notifications';
|
2023-09-05 16:06:36 +00:00
|
|
|
import { useAnalytics } from '@/react/hooks/useAnalytics';
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
import { Button, LoadingButton } from '@@/buttons';
|
|
|
|
import { FormControl } from '@@/form-components/FormControl';
|
|
|
|
import { Input } from '@@/form-components/Input';
|
|
|
|
import { Modal } from '@@/modals/Modal';
|
2023-01-19 13:31:49 +00:00
|
|
|
import { Alert } from '@@/Alert';
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
interface FormValues {
|
|
|
|
license: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const initialValues: FormValues = {
|
|
|
|
license: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
export function UploadLicenseDialog({
|
|
|
|
onDismiss,
|
|
|
|
goToLoading,
|
2023-01-19 13:31:49 +00:00
|
|
|
goToGetLicense,
|
|
|
|
isGetLicenseSubmitted,
|
2022-12-11 06:58:22 +00:00
|
|
|
}: {
|
|
|
|
onDismiss: () => void;
|
|
|
|
goToLoading: () => void;
|
2023-01-19 13:31:49 +00:00
|
|
|
goToGetLicense: () => void;
|
|
|
|
isGetLicenseSubmitted: boolean;
|
2022-12-11 06:58:22 +00:00
|
|
|
}) {
|
|
|
|
const upgradeMutation = useUpgradeEditionMutation();
|
2023-02-19 04:17:50 +00:00
|
|
|
const { trackEvent } = useAnalytics();
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
onDismiss={onDismiss}
|
|
|
|
aria-label="Upgrade Portainer to Business Edition"
|
|
|
|
>
|
|
|
|
<Modal.Header
|
2023-02-12 21:04:24 +00:00
|
|
|
title={<h4 className="text-xl font-medium">Upgrade Portainer</h4>}
|
2022-12-11 06:58:22 +00:00
|
|
|
/>
|
|
|
|
<Formik
|
|
|
|
initialValues={initialValues}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
validationSchema={validation}
|
2023-01-10 19:32:03 +00:00
|
|
|
validateOnMount
|
2022-12-11 06:58:22 +00:00
|
|
|
>
|
|
|
|
{({ errors }) => (
|
|
|
|
<Form noValidate>
|
|
|
|
<Modal.Body>
|
2023-01-19 13:31:49 +00:00
|
|
|
{!isGetLicenseSubmitted ? (
|
|
|
|
<p className="font-semibold text-gray-7">
|
|
|
|
Please enter your Portainer License below
|
|
|
|
</p>
|
|
|
|
) : (
|
|
|
|
<div className="mb-4">
|
|
|
|
<Alert color="success" title="License successfully sent">
|
|
|
|
Please check your email and copy your license into the field
|
|
|
|
below to upgrade Portainer.
|
|
|
|
</Alert>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
<FormControl
|
|
|
|
label="License"
|
|
|
|
errors={errors.license}
|
|
|
|
required
|
|
|
|
size="vertical"
|
|
|
|
>
|
|
|
|
<Field name="license" as={Input} required />
|
|
|
|
</FormControl>
|
|
|
|
</Modal.Body>
|
|
|
|
<Modal.Footer>
|
2023-02-12 21:04:24 +00:00
|
|
|
<div className="flex w-full gap-2 [&>*]:w-1/2">
|
2023-01-19 13:31:49 +00:00
|
|
|
<Button
|
|
|
|
color="default"
|
|
|
|
size="medium"
|
|
|
|
className="w-full"
|
|
|
|
onClick={goToGetLicense}
|
2022-12-11 06:58:22 +00:00
|
|
|
>
|
2023-01-19 13:31:49 +00:00
|
|
|
Get a license
|
|
|
|
</Button>
|
2022-12-11 06:58:22 +00:00
|
|
|
<LoadingButton
|
|
|
|
color="primary"
|
|
|
|
size="medium"
|
|
|
|
loadingText="Validating License"
|
|
|
|
isLoading={upgradeMutation.isLoading}
|
|
|
|
>
|
|
|
|
Start upgrade
|
|
|
|
</LoadingButton>
|
|
|
|
</div>
|
|
|
|
</Modal.Footer>
|
|
|
|
</Form>
|
|
|
|
)}
|
|
|
|
</Formik>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
|
|
|
|
function handleSubmit(values: FormValues) {
|
|
|
|
upgradeMutation.mutate(values, {
|
|
|
|
onSuccess() {
|
2023-02-19 04:17:50 +00:00
|
|
|
trackEvent('portainer-upgrade-license-key-provided', {
|
|
|
|
category: 'portainer',
|
|
|
|
metadata: {
|
|
|
|
Upgrade: 'true',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-12-11 06:58:22 +00:00
|
|
|
notifySuccess('Starting upgrade', 'License validated successfully');
|
|
|
|
goToLoading();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function validation(): SchemaOf<FormValues> {
|
|
|
|
return object().shape({
|
|
|
|
license: string()
|
|
|
|
.required('License is required')
|
|
|
|
.matches(/^\d-.+/, 'License is invalid'),
|
|
|
|
});
|
|
|
|
}
|