-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: revamp the frontend architecture (#6598)
* feat: setup the app context to fetch users,licenses and feature flags * feat: added global event listeners for after_login event * feat: remove redux from app state and private route * feat: syncronize the approutes file * feat: cleanup the private routes * feat: handle login and logout * feat: cleanup the app layout file * feat: cleanup and syncronize side nav item * fix: minor small re-render issue * feat: parallel processing for sync calls for faster bootup of application * feat: some refactoring for private routes * fix: entire application too much re-rendering * fix: remove redux * feat: some more corrections * feat: fix all the files except signup * feat: add app provider to the test-utils * feat: should fix a lot of tests * chore: fix more tests * chore: fix more tests * feat: fix some tests and corrected the redux mock * feat: delete snapshot * fix: test cases * fix: pipeline actions test cases * fix: billing test cases * feat: update the signup API to accept isAnonymous and hasOptedUpdates * chore: cleanup the console logs * fix: indefinite loading on manage licenses screen * fix: better handling and route to something_went_wrong in case of qs down * fix: signup for subsequent users * chore: update test-utils * fix: jerky behaviour on entering the home page * feat: handle the retention for login context flow * fix: do not let users workaround workspace blocked screen
- Loading branch information
1 parent
accafbc
commit 26fe5e4
Showing
136 changed files
with
1,935 additions
and
3,080 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,28 @@ | ||
import getLocalStorageApi from 'api/browser/localstorage/get'; | ||
import setLocalStorageApi from 'api/browser/localstorage/set'; | ||
import getUserApi from 'api/user/getUser'; | ||
import { Logout } from 'api/utils'; | ||
import { LOCALSTORAGE } from 'constants/localStorage'; | ||
import store from 'store'; | ||
import AppActions from 'types/actions'; | ||
import { | ||
LOGGED_IN, | ||
UPDATE_USER, | ||
UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN, | ||
UPDATE_USER_IS_FETCH, | ||
} from 'types/actions/app'; | ||
import { SuccessResponse } from 'types/api'; | ||
import { PayloadProps } from 'types/api/user/getUser'; | ||
|
||
const afterLogin = async ( | ||
const afterLogin = ( | ||
userId: string, | ||
authToken: string, | ||
refreshToken: string, | ||
): Promise<SuccessResponse<PayloadProps> | undefined> => { | ||
interceptorRejected?: boolean, | ||
): void => { | ||
setLocalStorageApi(LOCALSTORAGE.AUTH_TOKEN, authToken); | ||
setLocalStorageApi(LOCALSTORAGE.REFRESH_AUTH_TOKEN, refreshToken); | ||
|
||
store.dispatch<AppActions>({ | ||
type: UPDATE_USER_ACCESS_REFRESH_ACCESS_TOKEN, | ||
payload: { | ||
accessJwt: authToken, | ||
refreshJwt: refreshToken, | ||
}, | ||
}); | ||
|
||
const [getUserResponse] = await Promise.all([ | ||
getUserApi({ | ||
userId, | ||
token: authToken, | ||
}), | ||
]); | ||
|
||
if (getUserResponse.statusCode === 200 && getUserResponse.payload) { | ||
store.dispatch<AppActions>({ | ||
type: LOGGED_IN, | ||
payload: { | ||
isLoggedIn: true, | ||
}, | ||
}); | ||
|
||
const { payload } = getUserResponse; | ||
|
||
store.dispatch<AppActions>({ | ||
type: UPDATE_USER, | ||
payload: { | ||
ROLE: payload.role, | ||
email: payload.email, | ||
name: payload.name, | ||
orgName: payload.organization, | ||
profilePictureURL: payload.profilePictureURL, | ||
userId: payload.id, | ||
orgId: payload.orgId, | ||
userFlags: payload.flags, | ||
}, | ||
}); | ||
|
||
const isLoggedInLocalStorage = getLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN); | ||
|
||
if (isLoggedInLocalStorage === null) { | ||
setLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN, 'true'); | ||
} | ||
|
||
store.dispatch({ | ||
type: UPDATE_USER_IS_FETCH, | ||
payload: { | ||
isUserFetching: false, | ||
}, | ||
}); | ||
|
||
return getUserResponse; | ||
setLocalStorageApi(LOCALSTORAGE.USER_ID, userId); | ||
setLocalStorageApi(LOCALSTORAGE.IS_LOGGED_IN, 'true'); | ||
|
||
if (!interceptorRejected) { | ||
window.dispatchEvent( | ||
new CustomEvent('AFTER_LOGIN', { | ||
detail: { | ||
accessJWT: authToken, | ||
refreshJWT: refreshToken, | ||
id: userId, | ||
}, | ||
}), | ||
); | ||
} | ||
|
||
store.dispatch({ | ||
type: UPDATE_USER_IS_FETCH, | ||
payload: { | ||
isUserFetching: false, | ||
}, | ||
}); | ||
|
||
Logout(); | ||
|
||
return undefined; | ||
}; | ||
|
||
export default afterLogin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import { ApiV2Instance as axios } from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps } from 'types/api/licenses/getAll'; | ||
|
||
const getAll = async (): Promise< | ||
SuccessResponse<PayloadProps> | ErrorResponse | ||
> => { | ||
try { | ||
const response = await axios.get('/licenses'); | ||
const response = await axios.get('/licenses'); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
}; | ||
|
||
export default getAll; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,18 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/user/getUser'; | ||
|
||
const getUser = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.get(`/user/${props.userId}`, { | ||
headers: { | ||
Authorization: `bearer ${props.token}`, | ||
}, | ||
}); | ||
const response = await axios.get(`/user/${props.userId}`); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: 'Success', | ||
payload: response.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: 'Success', | ||
payload: response.data, | ||
}; | ||
}; | ||
|
||
export default getUser; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.