Skip to content

Commit

Permalink
feat: navigate between all stages
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Sep 4, 2024
1 parent ba8d043 commit 9202f5c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 15 deletions.
60 changes: 47 additions & 13 deletions frontend/src/component/onboarding/ConnectSdkDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ const NextStepSectionSpacedContainer = styled('div')(({ theme }) => ({
padding: theme.spacing(3, 8, 3, 8),
}));

type OnboardingStage =
| { name: 'select-sdk' }
| { name: 'generate-api-key' }
| { name: 'test-connection' };
type OnboardingStage = 'select-sdk' | 'generate-api-key' | 'test-connection';

export const ConnectSdkDialog = ({
open,
Expand All @@ -71,7 +68,8 @@ export const ConnectSdkDialog = ({
const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
const [sdk, setSdk] = useState<Sdk | null>(null);
const [environment, setEnvironment] = useState<string | null>(null);
const [stage, setStage] = useState<OnboardingStage>({ name: 'select-sdk' });
const [apiKey, setApiKey] = useState<string | null>(null);
const [stage, setStage] = useState<OnboardingStage>('select-sdk');

useEffect(() => {
if (environments.length > 0) {
Expand All @@ -83,46 +81,82 @@ export const ConnectSdkDialog = ({
<StyledDialog open={open} onClose={onClose}>
<Box sx={{ display: 'flex' }}>
<ConnectSdk>
{stage.name === 'select-sdk' ? (
{stage === 'select-sdk' ? (
<SelectSdk
onSelect={(sdk) => {
setSdk(sdk);
setStage({ name: 'generate-api-key' });
setStage('generate-api-key');
}}
/>
) : null}
{stage.name === 'generate-api-key' && sdk && environment ? (
{stage === 'generate-api-key' && sdk && environment ? (
<GenerateApiKey
environments={environments}
environment={environment}
project={project}
sdkType={sdk.type}
onEnvSelect={setEnvironment}
onApiKey={(apiKey) => {
setApiKey(apiKey);
}}
/>
) : null}
{stage === 'test-connection' && sdk && environment ? (
<div>Last stage</div>
) : null}

{stage.name === 'generate-api-key' ? (
{stage === 'generate-api-key' ? (
<Navigation>
<NextStepSectionSpacedContainer>
<Button
variant='text'
color='inherit'
onClick={() => {
setStage({ name: 'select-sdk' });
setStage('select-sdk');
}}
>
Back
</Button>
<Button variant='contained'>Next</Button>
<Button
variant='contained'
onClick={() => {
setStage('test-connection');
}}
>
Next
</Button>
</NextStepSectionSpacedContainer>
</Navigation>
) : null}
{stage === 'test-connection' ? (
<Navigation>
<NextStepSectionSpacedContainer>
<Button
variant='text'
color='inherit'
onClick={() => {
setStage('generate-api-key');
}}
>
Back
</Button>
<Button
variant='contained'
onClick={() => {
onClose();
}}
>
Finish
</Button>
</NextStepSectionSpacedContainer>
</Navigation>
) : null}
</ConnectSdk>

{isLargeScreen && stage.name === 'select-sdk' ? (
{isLargeScreen && stage === 'select-sdk' ? (
<SelectSdkConcepts />
) : null}
{isLargeScreen && stage.name === 'generate-api-key' ? (
{isLargeScreen && stage === 'generate-api-key' ? (
<GenrateApiKeyConcepts />
) : null}
</Box>
Expand Down
12 changes: 10 additions & 2 deletions frontend/src/component/onboarding/GenerateApiKey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { SingleSelectConfigButton } from '../common/DialogFormTemplate/ConfigButtons/SingleSelectConfigButton';
import EnvironmentsIcon from '@mui/icons-material/CloudCircle';
import { ArcherContainer, ArcherElement } from 'react-archer';
import { useEffect } from 'react';

const ChooseEnvironment = ({
environments,
Expand Down Expand Up @@ -159,11 +160,11 @@ const TokenExplanation = ({
</SecretExplanationDescription>
</ArcherElement>
<ArcherElement
id='secreat-description'
id='secret-description'
relations={[
{
targetId: 'secret',
targetAnchor: 'bottom',
targetAnchor: 'right',
sourceAnchor: 'top',
},
]}
Expand All @@ -185,6 +186,7 @@ interface GenerateApiKeyProps {
environment: string;
sdkType: 'client' | 'frontend';
onEnvSelect: (env: string) => void;
onApiKey: (apiKey: string | null) => void;
}

export const GenerateApiKey = ({
Expand All @@ -193,12 +195,18 @@ export const GenerateApiKey = ({
project,
sdkType,
onEnvSelect,
onApiKey,
}: GenerateApiKeyProps) => {
const { tokens, refetch: refreshTokens } = useProjectApiTokens(project);
const { createToken, loading: creatingToken } = useProjectApiTokensApi();
const currentEnvironmentToken = tokens.find(
(token) => token.environment === environment && token.type === sdkType,
);

useEffect(() => {
onApiKey(currentEnvironmentToken?.secret || null);
}, [currentEnvironmentToken]);

const parsedToken = parseToken(currentEnvironmentToken?.secret);

const { setToastApiError } = useToast();
Expand Down

0 comments on commit 9202f5c

Please sign in to comment.