Skip to content

Commit fb73b75

Browse files
committed
feat: update the demo page flow
1 parent 2bf4be1 commit fb73b75

9 files changed

Lines changed: 108 additions & 40 deletions

File tree

ui/dashboard/src/app/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import {
1414
AuthProvider,
1515
useAuth,
1616
getCurrentEnvironment,
17-
hasEditable
17+
hasEditable,
18+
AuthDemoCallbackPage
1819
} from 'auth';
1920
import { ENVIRONMENT_WITH_EMPTY_ID } from 'constants/app';
2021
import {
2122
PAGE_PATH_APIKEYS,
2223
PAGE_PATH_AUDIT_LOGS,
2324
PAGE_PATH_AUTH_CALLBACK,
25+
PAGE_PATH_AUTH_DEMO_CALLBACK,
2426
PAGE_PATH_AUTH_SIGNIN,
2527
PAGE_PATH_DEBUGGER,
2628
PAGE_PATH_DEMO_SITE,
@@ -104,6 +106,10 @@ function App() {
104106
path={PAGE_PATH_AUTH_CALLBACK}
105107
element={<AuthCallbackPage />}
106108
/>
109+
<Route
110+
path={PAGE_PATH_AUTH_DEMO_CALLBACK}
111+
element={<AuthDemoCallbackPage />}
112+
/>
107113
<Route
108114
path={PAGE_PATH_AUTH_SIGNIN}
109115
element={<SignInEmailPage />}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { FC, useEffect, memo } from 'react';
2+
import { useLocation, useNavigate } from 'react-router-dom';
3+
import { exchangeDemoToken, ExchangeTokenPayload } from '@api/auth';
4+
import { urls } from 'configs';
5+
import { PAGE_PATH_DEMO_SITE } from 'constants/routing';
6+
import { getCookieState } from 'cookie';
7+
import { useSubmit, useToast } from 'hooks';
8+
import queryString from 'query-string';
9+
import { AppLoading } from 'app';
10+
import { useAuth } from './auth-context';
11+
12+
export const AuthDemoCallbackPage: FC = memo(() => {
13+
const { errorNotify } = useToast();
14+
const { setIsGoogleAuthError, setIsInitialLoading } = useAuth();
15+
const navigate = useNavigate();
16+
const location = useLocation();
17+
const query = location.search;
18+
19+
const { onSubmit: onGoogleDemoHandler } = useSubmit(
20+
async (payload: ExchangeTokenPayload) => {
21+
try {
22+
const response = await exchangeDemoToken(payload);
23+
if (response.token) {
24+
navigate(`${PAGE_PATH_DEMO_SITE}?token=${response.token}`);
25+
}
26+
} catch (error) {
27+
setIsGoogleAuthError(true);
28+
setIsInitialLoading(false);
29+
errorNotify(error);
30+
navigate(PAGE_PATH_DEMO_SITE);
31+
}
32+
}
33+
);
34+
35+
useEffect(() => {
36+
const { code, state } = queryString.parse(query);
37+
const cookieState = getCookieState();
38+
setIsInitialLoading(true);
39+
40+
if (!!code && typeof code === 'string' && state === cookieState) {
41+
onGoogleDemoHandler({
42+
code,
43+
redirectUrl: urls.AUTH_DEMO_REDIRECT,
44+
type: 2 // Google auth type
45+
});
46+
} else {
47+
throw new Error('Invalid authentication.');
48+
}
49+
}, [query]);
50+
51+
return <AppLoading />;
52+
});

ui/dashboard/src/auth/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './auth-context';
22
export * from './auth-callback';
33
export * from './utils';
4+
export * from './auth-demo-callback';

ui/dashboard/src/configs/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import {
2+
PAGE_PATH_AUTH_CALLBACK,
3+
PAGE_PATH_AUTH_DEMO_CALLBACK
4+
} from 'constants/routing';
15
import resolveConfig from 'tailwindcss/resolveConfig';
26
import customTailwindConfig from '../../tailwind.config';
37

@@ -23,8 +27,12 @@ export const urls = {
2327
releaseMode !== 'prod' ? import.meta.env.VITE_WEB_API_ENDPOINT : '',
2428
AUTH_REDIRECT:
2529
releaseMode !== 'prod'
26-
? `${import.meta.env.VITE_AUTH_REDIRECT_ENDPOINT}/auth/callback`
27-
: `${window.location.origin}/auth/callback`,
30+
? `${import.meta.env.VITE_AUTH_REDIRECT_ENDPOINT}${PAGE_PATH_AUTH_CALLBACK}`
31+
: `${window.location.origin}${PAGE_PATH_AUTH_CALLBACK}`,
32+
AUTH_DEMO_REDIRECT:
33+
releaseMode !== 'prod'
34+
? `${import.meta.env.VITE_AUTH_REDIRECT_ENDPOINT}${PAGE_PATH_AUTH_DEMO_CALLBACK}`
35+
: `${window.location.origin}${PAGE_PATH_AUTH_DEMO_CALLBACK}`,
2836
ORIGIN_URL:
2937
releaseMode !== 'prod'
3038
? `${import.meta.env.VITE_AUTH_REDIRECT_ENDPOINT}`

ui/dashboard/src/constants/routing.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ export const PAGE_PATH_FEATURE_HISTORY = '/history';
3737
export const PAGE_PATH_FEATURE_CODE_REFS = '/code-references';
3838

3939
export const PAGE_PATH_AUTH_CALLBACK = '/auth/callback';
40+
export const PAGE_PATH_AUTH_DEMO_CALLBACK = '/demo/auth/callback';
4041
export const PAGE_PATH_AUTH_SIGNIN = '/auth/signin';
4142
export const PAGE_PATH_DEMO_SITE = '/demo';

ui/dashboard/src/pages/audit-logs/collection-layout/audit-log-list.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,20 @@ const AuditLogList = memo(
4848
{getDateLabel(item)}
4949
</p>
5050
<div className="flex flex-col w-full gap-y-2">
51-
{formattedAuditLogs.get(item)?.map((item, i) => (
52-
<AuditLogItem
53-
isExpanded={
54-
expandOrCollapseAllState === ExpandOrCollapse.EXPAND ||
55-
expandedItems.includes(item.id)
56-
}
57-
key={item.id}
58-
prefix={`line-${index}${i}`}
59-
auditLog={item}
60-
onClick={() => onToggleExpandItem(item.id)}
61-
/>
62-
))}
51+
{formattedAuditLogs
52+
.get(item)
53+
?.map((item, i) => (
54+
<AuditLogItem
55+
isExpanded={
56+
expandOrCollapseAllState === ExpandOrCollapse.EXPAND ||
57+
expandedItems.includes(item.id)
58+
}
59+
key={item.id}
60+
prefix={`line-${index}${i}`}
61+
auditLog={item}
62+
onClick={() => onToggleExpandItem(item.id)}
63+
/>
64+
))}
6365
</div>
6466
</div>
6567
);

ui/dashboard/src/pages/demo/demo-form.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Input from 'components/input';
1212
interface AccessDemoForm {
1313
organizationName: string;
1414
organizationUrlCode: string;
15-
email: string;
1615
isAgree: boolean;
1716
}
1817

@@ -28,22 +27,20 @@ const formSchema = ({ requiredMessage, translation }: FormSchemaProps) =>
2827
name: translation('common:url-code')
2928
})
3029
),
31-
email: yup.string().email().required(requiredMessage),
3230
isAgree: yup
3331
.boolean()
3432
.isTrue(translation('message:required-agreement-terms'))
3533
.required(requiredMessage)
3634
});
3735

3836
const DemoForm = ({ isDemoSiteEnabled }: { isDemoSiteEnabled?: boolean }) => {
39-
const { t } = useTranslation(['auth', 'common', 'form', 'message']);
37+
const { t } = useTranslation(['common', 'form', 'message']);
4038

4139
const form = useForm({
4240
resolver: yupResolver(useFormSchema(formSchema)),
4341
defaultValues: {
4442
organizationName: '',
4543
organizationUrlCode: '',
46-
email: '',
4744
isAgree: undefined
4845
},
4946
mode: 'onChange'
@@ -109,19 +106,6 @@ const DemoForm = ({ isDemoSiteEnabled }: { isDemoSiteEnabled?: boolean }) => {
109106
</Form.Item>
110107
)}
111108
/>
112-
<Form.Field
113-
control={form.control}
114-
name="email"
115-
render={({ field }) => (
116-
<Form.Item>
117-
<Form.Label required>{t('owner-email')}</Form.Label>
118-
<Form.Control>
119-
<Input placeholder={t('email')} {...field} />
120-
</Form.Control>
121-
<Form.Message />
122-
</Form.Item>
123-
)}
124-
/>
125109
<Form.Field
126110
control={form.control}
127111
name="isAgree"

ui/dashboard/src/pages/demo/index.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
2+
import { useLocation } from 'react-router-dom';
23
import { authenticationUrl } from '@api/auth';
34
import { useQueryDemoSiteStatus } from '@queries/demo-site-status';
45
import { urls } from 'configs';
6+
import { setCookieState } from 'cookie';
57
import { useSubmit } from 'hooks';
68
import { useTranslation } from 'i18n';
9+
import queryString from 'query-string';
710
import { cn } from 'utils/style';
811
import { IconGoogle } from '@icons';
912
import AuthWrapper from 'pages/signin/elements/auth-wrapper';
@@ -13,19 +16,23 @@ import FormLoading from 'elements/form-loading';
1316
import DemoForm from './demo-form';
1417

1518
const AccessDemoPage = () => {
16-
const { t } = useTranslation(['auth', 'common', 'form', 'message']);
19+
const { t } = useTranslation(['common', 'auth', 'message']);
20+
const location = useLocation();
21+
const query = location.search;
1722

23+
const [userToken, setUserToken] = useState('');
1824
const { data: demoSiteStatusData, isLoading } = useQueryDemoSiteStatus();
19-
const isDemoSiteEnabled = !demoSiteStatusData?.isDemoSiteEnabled;
2025

21-
const [isAuthenticated] = useState(false);
26+
const isDemoSiteEnabled = demoSiteStatusData?.isDemoSiteEnabled;
27+
const isAuthenticated = Boolean(userToken);
2228

2329
const { onSubmit: onGoogleLoginHandler, submitting } = useSubmit(() => {
2430
const state = `${Date.now()}`;
31+
setCookieState(state);
2532

2633
return authenticationUrl({
2734
state,
28-
redirectUrl: urls.AUTH_REDIRECT,
35+
redirectUrl: urls.AUTH_DEMO_REDIRECT,
2936
type: 2 // Google auth type
3037
}).then(response => {
3138
if (response.url) {
@@ -34,14 +41,21 @@ const AccessDemoPage = () => {
3441
});
3542
});
3643

44+
useEffect(() => {
45+
const { token } = queryString.parse(query);
46+
if (token && typeof token === 'string') {
47+
setUserToken(token);
48+
}
49+
}, [query]);
50+
3751
return (
3852
<AuthWrapper>
3953
{isLoading ? (
4054
<FormLoading />
4155
) : (
4256
<>
4357
<h1 className="text-gray-900 typo-head-bold-huge">
44-
{t(isAuthenticated ? 'privacy-notice' : 'demo')}
58+
{t(isAuthenticated ? 'auth:privacy-notice' : 'auth:demo')}
4559
</h1>
4660
<div
4761
className={cn('text-gray-600 typo-para-medium mt-6', {

ui/dashboard/src/pages/feature-flag-details/code-refs/code-accordion/highlighter/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
}
44

55
.token.boolean {
6-
@apply !text-accent-pink-500;
7-
}
6+
@apply !text-accent-pink-500;
7+
}
88

99
.token.comment {
1010
@apply !text-accent-green-600;

0 commit comments

Comments
 (0)