Skip to content

Commit 44716fd

Browse files
authored
Merge pull request #65 from zenml-io/talha/feedback-fixes
configuration for demo
2 parents 4478150 + d128c44 commit 44716fd

File tree

3 files changed

+86
-19
lines changed

3 files changed

+86
-19
lines changed

src/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ import './App.css';
1111
import './ui/default.css';
1212

1313
const { store, persistor } = configureStore();
14+
if (
15+
process.env.REACT_APP_DEMO_SETUP === 'true' &&
16+
(process.env.REACT_APP_USERNAME === undefined ||
17+
process.env.REACT_APP_PASSWORD === undefined)
18+
) {
19+
console.warn(
20+
'You need to add process.env.REACT_APP_USERNAME and process.env.REACT_APP_PASSWORD in .env file.',
21+
);
22+
}
1423

1524
const App: React.FC = () => {
1625
return (

src/ui/layouts/common/layouts/AuthenticatedLayout/AuthenticatedHeader.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,26 @@ export const AuthenticatedHeader: React.FC<{
8787
<Paragraph size="small">Settings</Paragraph>
8888
</FlexBox>
8989
</LinkBox>
90-
<LinkBox onClick={logout}>
91-
<FlexBox
92-
className={styles.popupItem}
93-
paddingHorizontal="md"
94-
paddingVertical="sm"
95-
alignItems="center"
96-
>
97-
<Box paddingRight="sm">
98-
<icons.signOut
99-
size={iconSizes.sm}
100-
color={iconColors.red}
101-
/>
102-
</Box>
103-
<Paragraph color="red" size="small">
104-
Logout
105-
</Paragraph>
106-
</FlexBox>
107-
</LinkBox>
90+
{process.env.REACT_APP_DEMO_SETUP === 'true' ? null : (
91+
<LinkBox onClick={logout}>
92+
<FlexBox
93+
className={styles.popupItem}
94+
paddingHorizontal="md"
95+
paddingVertical="sm"
96+
alignItems="center"
97+
>
98+
<Box paddingRight="sm">
99+
<icons.signOut
100+
size={iconSizes.sm}
101+
color={iconColors.red}
102+
/>
103+
</Box>
104+
<Paragraph color="red" size="small">
105+
Logout
106+
</Paragraph>
107+
</FlexBox>
108+
</LinkBox>
109+
)}
108110
</Box>
109111
</OutsideClickHandler>
110112
)}

src/ui/layouts/session/Login/index.tsx

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { useEffect, useState } from 'react';
22

33
import {
44
H2,
@@ -8,6 +8,7 @@ import {
88
Box,
99
Image,
1010
EaseInBox,
11+
FullWidthSpinner,
1112
} from '../../../components';
1213

1314
import { Form } from './Form';
@@ -18,8 +19,63 @@ import image from '../imageNew.png';
1819
import { translate } from './translate';
1920
import { routePaths } from '../../../../routes/routePaths';
2021
import { Link } from 'react-router-dom';
22+
import { useDispatch, usePushRoute } from '../../../hooks';
2123

24+
import { loginAction } from '../../../../redux/actions/session/loginAction';
25+
import { showToasterAction, userActions } from '../../../../redux/actions';
26+
import { toasterTypes } from '../../../../constants';
2227
const Login: React.FC = () => {
28+
const [loading, setLoading] = useState(false);
29+
const dispatch = useDispatch();
30+
const password = process.env.REACT_APP_PASSWORD;
31+
const username = process.env.REACT_APP_USERNAME;
32+
const { push } = usePushRoute();
33+
const login = async () => {
34+
setLoading(true);
35+
36+
await dispatch(
37+
loginAction({
38+
password,
39+
username,
40+
onFailure: (errorText) => {
41+
dispatch(
42+
showToasterAction({
43+
description: errorText,
44+
type: toasterTypes.failure,
45+
}),
46+
);
47+
setLoading(false);
48+
},
49+
onSuccess: async () => {
50+
dispatch(
51+
showToasterAction({
52+
description: translate('toasts.successfulLogin.text'),
53+
type: toasterTypes.success,
54+
}),
55+
);
56+
setLoading(false);
57+
58+
await dispatch(userActions.getMy({}));
59+
await push(routePaths.userEmail);
60+
},
61+
}),
62+
);
63+
};
64+
useEffect(() => {
65+
if (process.env.REACT_APP_DEMO_SETUP === 'true') {
66+
setLoading(true);
67+
login();
68+
}
69+
return () => {
70+
setLoading(false);
71+
};
72+
// eslint-disable-next-line react-hooks/exhaustive-deps
73+
}, []);
74+
75+
if (loading) {
76+
return <FullWidthSpinner color="black" size="md" />;
77+
}
78+
2379
return (
2480
<EaseInBox>
2581
<Container

0 commit comments

Comments
 (0)