Skip to content

Commit

Permalink
Merge pull request #664 from bcgov/feat/srs-339
Browse files Browse the repository at this point in the history
add an api request in frontend to create a user in database.
  • Loading branch information
midhun-aot authored Apr 16, 2024
2 parents 5f141a9 + 3d7ed08 commit edf8128
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
43 changes: 40 additions & 3 deletions frontend/src/app/features/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import "./Dashboard.css";
import { SdmDashboard } from "./sdmDashboard/SdmDashboard";
import { ReviewerDashoard } from "./reviewerDashboard/ReviewerDashoard";
import { getSDMUserRole } from "../../helpers/envManager";
import { getAxiosInstanceForUsers } from "../../helpers/utility";
import { USERS } from "../../helpers/endpoints";
import { getAxiosInstanceForComs, getAxiosInstanceForUsers } from "../../helpers/utility";
import { COMS, USERS } from "../../helpers/endpoints";

const Dashboard = () => {
const dispatch = useDispatch<AppDispatch>();
Expand Down Expand Up @@ -53,7 +53,8 @@ const Dashboard = () => {
useEffect( () => {
if(auth.user?.profile.identity_provider === BCeID || auth.user?.profile.identity_provider === BCSC)
{
assignGroupToUser();
assignGroupToUser();
assignUserToBCbox();
}
}, []);

Expand All @@ -73,6 +74,42 @@ const Dashboard = () => {

}

const assignUserToBCbox = () => {
try{

// Get the user's identity ID from auth.user.profile.sub
const identityId = auth.user?.profile.sub;

if (!identityId) {
throw new Error('User identity ID is missing.');
}
// Make the Axios GET request with value in the query string
getAxiosInstanceForComs().get(COMS, {
params: {
identityId: auth.user?.profile.sub
}
})
.then(response => {
if(response.data.success)
{
console.log(response.data.message);
}
else {
throw new Error('Failed to assign user to BCbox.');
}
})
.catch(error => {
// Handle errors
console.error('Error assigning user to BCbox:', error.message);
});
}
catch (error: any) {
// Handle errors
console.error('Error assigning user to BCbox:', error.message);
}

}

const handleFormsflowWebRedirection = () => {
const formsFlowWebURL = process.env.REACT_APP_FORMSFLOW_WEB_URL || ((window as any)._env_ && (window as any)._env_.REACT_APP_FORMSFLOW_WEB_URL) || "";
const locationBeforeAuthRedirect = sessionStorage.getItem('locationBeforeAuthRedirect');
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/app/helpers/endpoints.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export const USERS = "/users";

export const COMS = "/api/v1/user"

export const GRAPHQL= "/graphql"

export const API:string = process.env.REACT_APP_BACKEND_API|| ((window as any)._env_ && (window as any)._env_.REACT_APP_BACKEND_API)

export const USERS_API: string = process.env.REACT_APP_BACKEND_USERS_API|| ((window as any)._env_ && (window as any)._env_.REACT_APP_BACKEND_USERS_API)
export const USERS_API: string = process.env.REACT_APP_BACKEND_USERS_API|| ((window as any)._env_ && (window as any)._env_.REACT_APP_BACKEND_USERS_API)

export const COMS_API: string = process.env.REACT_APP_BCBOX_BASE_URL|| ((window as any)._env_ && (window as any)._env_.REACT_APP_BCBOX_BASE_URL)
19 changes: 18 additions & 1 deletion frontend/src/app/helpers/utility.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from '@reduxjs/toolkit';
import { API, USERS_API } from './endpoints'
import { API, COMS_API, USERS_API } from './endpoints'
import axios from "axios";
import { User } from "oidc-client-ts"
import { getClientSettings } from '../auth/UserManagerSetting';
Expand Down Expand Up @@ -61,3 +61,20 @@ export const getAxiosInstanceForUsers = () => {

return instance;
}

export const getAxiosInstanceForComs = () => {

const user = getUser();
const instance = axios.create({
baseURL: COMS_API,
timeout: 1000,
headers: {
'Authorization': 'Bearer '+user?.access_token,
'requestID': generateRequestId(),
'Access-Control-Allow-Origin':'*',
'Content-Type':'application/json'
}
});

return instance;
}

0 comments on commit edf8128

Please sign in to comment.