Skip to content

Commit a3d7c7b

Browse files
committed
Merge remote-tracking branch 'origin/dev' into feature/pipeline-run-dag
2 parents 2f415bc + 2af8614 commit a3d7c7b

File tree

42 files changed

+1885
-460
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1885
-460
lines changed

global.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ interface TUser {
3939
email: string;
4040
organizationId: TId;
4141
userName: string;
42+
email_opted_in: any;
43+
emailOptedIn: any;
4244
}
4345

4446
interface TOrganization {

src/api/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const endpoints = {
22
login: '/login',
33
signup: (username: string): string => `/users/${username}/activate`,
4+
userEmail: (userId: string): string => `/users/${userId}/email-opt-in`,
45
forgot: '/login/email/resetpassword',
56
version: '/version',
67
users: {

src/api/session/saveUserEmail.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { fetchApiWithAuthRequest } from '../fetchApi';
2+
import { endpoints } from '../endpoints';
3+
import { httpMethods } from '../constants';
4+
import { apiUrl } from '../apiUrl';
5+
6+
const SaveUserEmail = ({
7+
userId,
8+
email,
9+
email_opted_in,
10+
authenticationToken,
11+
}: {
12+
userId: string,
13+
email: string,
14+
email_opted_in: any,
15+
authenticationToken: string,
16+
}): Promise<TUser> =>
17+
fetchApiWithAuthRequest({
18+
url: apiUrl(endpoints.userEmail(userId)),
19+
method: httpMethods.put,
20+
authenticationToken,
21+
headers: {
22+
'Content-Type': 'application/json',
23+
},
24+
data: { email, email_opted_in },
25+
});
26+
27+
export default SaveUserEmail;

src/redux/actionTypes/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const userActionTypes = {
1010
USERS_GET_MY_USER: 'USERS_GET_MY_USER',
1111
USERS_GET_USER_FOR_ID: 'USERS_GET_USER_FOR_ID',
1212
UPDATE_USER_EMAIL: 'UPDATE_USER_EMAIL',
13+
SAVE_USER_EMAIL: 'SAVE_USER_EMAIL'
1314
};
1415

1516
const organizationActionTypes = {

src/redux/actionTypes/users.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ export const userActionTypes = {
55
getMyUser: generateApiActionsTypes(actionTypes.USERS_GET_MY_USER),
66
getUserForId: generateApiActionsTypes(actionTypes.USERS_GET_USER_FOR_ID),
77
updateUserEmail: generateApiActionsTypes(actionTypes.UPDATE_USER_EMAIL),
8+
saveUserEmail: generateApiActionsTypes(actionTypes.SAVE_USER_EMAIL),
89
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { userActionTypes } from '../../actionTypes';
2+
import saveUserEmailApi from '../../../api/session/saveUserEmail';
3+
4+
export const SaveUserEmailAction = ({
5+
userId,
6+
email,
7+
email_opted_in,
8+
onSuccess,
9+
onFailure,
10+
}: {
11+
userId: TId;
12+
email: string;
13+
email_opted_in: any;
14+
onSuccess?: () => void;
15+
onFailure?: () => void;
16+
}): TRequestAction => ({
17+
type: userActionTypes.saveUserEmail.request,
18+
payload: {
19+
apiMethod: saveUserEmailApi,
20+
isAuthenticated: true,
21+
failureActionType: userActionTypes.saveUserEmail.failure,
22+
successActionType: userActionTypes.saveUserEmail.success,
23+
params: { email, email_opted_in, userId },
24+
onSuccess,
25+
onFailure,
26+
},
27+
});

src/routes/appRoutesConfig.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from './RouteVisibility';
66
import Login from '../ui/layouts/session/Login';
77
import Signup from '../ui/layouts/session/Signup';
8+
import UserEmail from '../ui/layouts/session/UserEmail';
89
import ForgotPassword from '../ui/layouts/session/ForgotPassword';
910
import Home from '../ui/layouts/Home';
1011

@@ -40,6 +41,13 @@ const routes = [
4041
authentication: RouteVisibilityAuthentication.unauthenticatedOnly,
4142
},
4243
},
44+
{
45+
path: routePaths.userEmail,
46+
Component: UserEmail,
47+
visibility: {
48+
authentication: RouteVisibilityAuthentication.authenticatedOnly,
49+
},
50+
},
4351
{
4452
path: routePaths.forgot,
4553
Component: ForgotPassword,

src/routes/index.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useSelector,
1515
useLocationPath,
1616
useGetSearchParam,
17+
useDispatch
1718
} from '../ui/hooks';
1819

1920
import { sessionSelectors } from '../redux/selectors/session';
@@ -26,17 +27,28 @@ import { WaitToEnter } from '../ui/components';
2627

2728
import { isRouteFound } from './utils/isRouteFound';
2829
import { NotFound } from '../ui/layouts/NotFound';
30+
import { userSelectors } from '../redux/selectors';
31+
import {
32+
userActions,
33+
} from '../redux/actions';
34+
2935

3036
const useReplaceRouteIfNeeded = ({
3137
currentLocation,
3238
setNotFound,
3339
}: any): void => {
3440
const { replaceRoute } = useReplaceRoute();
3541

42+
const user = useSelector(userSelectors.myUser);
3643
const routeFromSearchParam = useGetSearchParam('route');
3744

3845
const isAuthenticated = useSelector(sessionSelectors.authenticationToken);
3946

47+
// const dispatch = useDispatch();
48+
// React.useEffect(() => {
49+
// dispatch(userActions.getMy({}));
50+
// }, [dispatch, userActions, isAuthenticated])
51+
4052
React.useEffect(() => {
4153
setNotFound(
4254
isRouteFound({
@@ -47,12 +59,13 @@ const useReplaceRouteIfNeeded = ({
4759

4860
React.useEffect(() => {
4961
replaceRouteIfNeeded({
62+
user,
5063
currentLocation,
5164
isAuthenticated,
5265
replaceRoute,
5366
routeFromSearchParam,
5467
});
55-
}, [currentLocation, isAuthenticated, replaceRoute]);
68+
}, [user, currentLocation, isAuthenticated, replaceRoute]);
5669
};
5770

5871
export const AppRoute = ({ path, component, exact }: any): JSX.Element => {

src/routes/routePaths.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export const routePaths = {
22
login: '/login',
33
signup: '/signup',
4+
// userEmail: (userId: TId): string => `/user-email/${userId}`,
5+
userEmail: `/user-email`,
46
forgot: '/forgot-password',
57
home: '/',
68
pipelines: {

src/routes/utils/replaceRouteIfNeeded.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
RouteInterface,
33
RouteVisibilityAuthentication,
44
} from '../RouteVisibility';
5-
import { loggedOutRoute, loggedInRoute } from '../../constants';
5+
import { loggedOutRoute } from '../../constants';
66

77
const isUnauthenticatedOrMissingRoute = (
88
currentLocation: RouteInterface | undefined,
@@ -25,19 +25,23 @@ const isAuthenticatedOrMissingRoute = (
2525
let timeout = null as any;
2626

2727
export const replaceRouteIfNeeded = ({
28+
user,
2829
isAuthenticated,
2930
currentLocation,
3031
replaceRoute,
3132
routeFromSearchParam,
3233
}: {
34+
user: any;
3335
isAuthenticated: any;
3436
currentLocation: RouteInterface | undefined;
3537
replaceRoute: (arg1: string) => void;
3638
routeFromSearchParam: null | string;
3739
}): void => {
3840
clearTimeout(timeout);
41+
3942
const routeToReplace = () => {
40-
return isAuthenticated ? loggedInRoute : loggedOutRoute;
43+
const logRoute = user?.email === '' ? `/user-email` : '/'
44+
return isAuthenticated ? logRoute : loggedOutRoute;
4145
};
4246
const replaceToLoggedInRoute =
4347
isAuthenticated && isUnauthenticatedOrMissingRoute(currentLocation);

0 commit comments

Comments
 (0)