2022-12-11 06:58:22 +00:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
|
|
|
import { useUser } from '@/react/hooks/useUser';
|
|
|
|
|
|
|
|
import { UploadLicenseDialog } from './UploadLicenseDialog';
|
|
|
|
import { LoadingDialog } from './LoadingDialog';
|
|
|
|
import { NonAdminUpgradeDialog } from './NonAdminUpgradeDialog';
|
2023-01-19 13:31:49 +00:00
|
|
|
import { GetLicenseDialog } from './GetLicenseDialog';
|
2022-12-11 06:58:22 +00:00
|
|
|
|
|
|
|
type Step = 'uploadLicense' | 'loading' | 'getLicense';
|
|
|
|
|
|
|
|
export function UpgradeDialog({ onDismiss }: { onDismiss: () => void }) {
|
|
|
|
const { isAdmin } = useUser();
|
|
|
|
const [currentStep, setCurrentStep] = useState<Step>('uploadLicense');
|
2023-01-19 13:31:49 +00:00
|
|
|
const [isGetLicenseSubmitted, setIsGetLicenseSubmitted] = useState(false);
|
2022-12-11 06:58:22 +00:00
|
|
|
const component = getDialog();
|
|
|
|
|
|
|
|
return component;
|
|
|
|
|
|
|
|
function getDialog() {
|
|
|
|
if (!isAdmin) {
|
|
|
|
return <NonAdminUpgradeDialog onDismiss={onDismiss} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (currentStep) {
|
|
|
|
case 'getLicense':
|
2023-01-19 13:31:49 +00:00
|
|
|
return (
|
|
|
|
<GetLicenseDialog
|
|
|
|
goToUploadLicense={(isSubmitted) => {
|
|
|
|
setCurrentStep('uploadLicense');
|
|
|
|
setIsGetLicenseSubmitted(isSubmitted);
|
|
|
|
}}
|
|
|
|
onDismiss={onDismiss}
|
|
|
|
/>
|
|
|
|
);
|
2022-12-11 06:58:22 +00:00
|
|
|
case 'uploadLicense':
|
|
|
|
return (
|
|
|
|
<UploadLicenseDialog
|
|
|
|
goToLoading={() => setCurrentStep('loading')}
|
|
|
|
onDismiss={onDismiss}
|
2023-01-19 13:31:49 +00:00
|
|
|
goToGetLicense={() => setCurrentStep('getLicense')}
|
|
|
|
isGetLicenseSubmitted={isGetLicenseSubmitted}
|
2022-12-11 06:58:22 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
case 'loading':
|
|
|
|
return <LoadingDialog />;
|
|
|
|
default:
|
|
|
|
throw new Error('step type not found');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|