Skip to content

Commit

Permalink
return to keycloak alpha build
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarkowsky committed Oct 3, 2024
1 parent 61d0ae5 commit fa29764
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@bcgov/bc-sans": "2.1.0",
"@bcgov/citz-imb-sso-react": "1.1.0-beta",
"@bcgov/citz-imb-sso-react": "1.0.0-alpha7",
"@emotion/react": "11.13.0",
"@emotion/styled": "11.13.0",
"@mdi/js": "7.4.47",
Expand Down
4 changes: 2 additions & 2 deletions react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ const Router = () => {
index
element={
sso.isAuthenticated &&
auth.pimsUser.data?.Status === 'Active' &&
auth.pimsUser.data?.RoleId ? (
auth.pimsUser?.data?.Status === 'Active' &&
auth.pimsUser?.data?.RoleId ? (
showMap()
) : (
<BaseLayout displayFooter>
Expand Down
4 changes: 3 additions & 1 deletion react-app/src/contexts/lookupContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LookupAll } from '@/hooks/api/useLookupApi';
import useDataLoader from '@/hooks/useDataLoader';
import usePimsApi from '@/hooks/usePimsApi';
import { useSSO } from '@bcgov/citz-imb-sso-react';
import { CircularProgress } from '@mui/material';
import React, { createContext, useCallback, useMemo } from 'react';

type LookupContextValue = {
Expand All @@ -18,7 +19,7 @@ export const LookupContext = createContext<LookupContextValue>(undefined);
*/
export const LookupContextProvider: React.FC<React.PropsWithChildren> = (props) => {
const api = usePimsApi();
const { data, loadOnce } = useDataLoader(api.lookup.getAll);
const { data, loadOnce, isLoading } = useDataLoader(api.lookup.getAll);
const sso = useSSO();
if (!data && sso.isAuthenticated) {
loadOnce();
Expand Down Expand Up @@ -55,6 +56,7 @@ export const LookupContextProvider: React.FC<React.PropsWithChildren> = (props)
);

const contextValue = { data, getLookupValueById };
if (isLoading) return <CircularProgress sx={{ position: 'fixed', top: '50%', left: '50%' }} />;
return <LookupContext.Provider value={contextValue}>{props.children}</LookupContext.Provider>;
};

Expand Down
3 changes: 3 additions & 0 deletions react-app/src/contexts/userContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import usePimsUser, { IPimsUser as PimsUser } from '@/hooks/usePimsUser';
import { CircularProgress } from '@mui/material';
import React, { createContext } from 'react';
export interface PimsUserState {
pimsUser: PimsUser;
Expand All @@ -14,6 +15,8 @@ export const UserContext = createContext<PimsUserState | undefined>(undefined);
export const UserContextProvider: React.FC<React.PropsWithChildren> = (props) => {
const pimsUser = usePimsUser();

if (pimsUser.isLoading)
return <CircularProgress sx={{ position: 'fixed', top: '50%', left: '50%' }} />;
return (
<UserContext.Provider
value={{
Expand Down
2 changes: 1 addition & 1 deletion react-app/src/guards/AuthRouteGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const AuthRouteGuard = (props: AuthGuardProps) => {
const navigate = useNavigate();

useEffect(() => {
if (sso.isAuthenticated) {
if (sso.isAuthenticated && sso.state.accessToken) {
if (timeoutId.current) {
clearTimeout(timeoutId.current);
timeoutId.current = null;
Expand Down
9 changes: 4 additions & 5 deletions react-app/src/hooks/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ const useFetch = (baseUrl?: string) => {
}

// If token has expired
// TODO: Uncomment when bug is solved
// if (response.status === 401) {
// const currentLocation = window.location.pathname;
// sso.login({ postLoginRedirectURL: currentLocation + window.location.search });
// }
if (response.status === 401) {
const currentLocation = window.location.pathname;
sso.login({ postLoginRedirectURL: currentLocation + window.location.search });
}

const text = await response.text();
if (text.length) {
Expand Down
6 changes: 3 additions & 3 deletions react-app/src/pages/AccessRequest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const AccessRequest = () => {
const onSubmit = (data: AccessRequestType) => {
api.users.submitAccessRequest(data).then((response) => {
if (response.status === 201) {
auth.pimsUser.refreshData();
auth.pimsUser?.refreshData();
} else {
snackbar.setMessageState({
text: `Could not create account. Contact ${lookup.data.Config.contactEmail} for assistance.`,
Expand All @@ -181,7 +181,7 @@ export const AccessRequest = () => {
}

const selectPageContent = () => {
if (auth.pimsUser.data?.Status === 'Active' && !auth.pimsUser.data?.RoleId) {
if (auth.pimsUser?.data?.Status === 'Active' && !auth.pimsUser?.data?.RoleId) {
return (
<>
<Typography mb={'2rem'} variant="h2">
Expand All @@ -191,7 +191,7 @@ export const AccessRequest = () => {
</>
);
}
switch (auth.pimsUser.data?.Status) {
switch (auth.pimsUser?.data?.Status) {
case 'OnHold':
return (
<>
Expand Down

0 comments on commit fa29764

Please sign in to comment.