Skip to content

Commit

Permalink
Merge pull request #96 from AWS-Cloud-School-6/94-fix-gcp-project-id-…
Browse files Browse the repository at this point in the history
…값-불러오기

#94 [Fix]: GCP project id 값 불러오기
  • Loading branch information
integer-bin authored Nov 26, 2024
2 parents b419268 + 27eb10f commit 9e89a5c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
3 changes: 1 addition & 2 deletions aiwa-mcp-frontend/src/Console/Console.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ function MyPage({ provider }) {
};

return (

<Flex direction="column" padding="2rem">
<Flex direction="column" padding="2rem" width="400px">
<Text fontSize="2xl" fontWeight="bold" marginBottom="1rem">마이페이지 - {provider}</Text>

<TextField
Expand Down
1 change: 1 addition & 0 deletions aiwa-mcp-frontend/src/Console/SideBar/SidebarConsole.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function SidebarConsole({ onSelectProvider }) {
<p><strong>Company: {key.companyName}</strong></p>
<p>Access Key: {maskAccessKey(key.accessKey)}</p>
<p>Secret Key: {maskAccessKey(key.secretKey)}</p>
<p>Project ID: {key.projectId}</p>
{key.gcpKeyPath && <p>GCP Key Path: {key.gcpKeyPath}</p>}
</div>
))}
Expand Down
39 changes: 31 additions & 8 deletions aiwa-mcp-frontend/src/UserContext.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React, { createContext, useContext, useState, useEffect } from 'react';
import { useAuthenticator } from '@aws-amplify/ui-react'; // Use Amplify's Authenticator
import axios from 'axios';
import { MEMBER_API_URL } from './index';

const UserContext = createContext(); // Create a context

Expand All @@ -20,16 +22,14 @@ export const UserProvider = ({ children }) => {
return null;
}
});
const [projectId, setProjectId] = useState(null);

useEffect(() => {
if (user) {
try {
setCurrentUser({
id: user.signInDetails.loginId,
});
} catch (error) {
console.error('Error setting current user:', error);
}
// user가 있을 때만 currentUser 설정
setCurrentUser({
id: user.signInDetails.loginId,
});
} else {
setCurrentUser(null);
}
Expand All @@ -44,12 +44,35 @@ export const UserProvider = ({ children }) => {
}
}, [selectedCompany]);

// projectId를 가져오는 useEffect
useEffect(() => {
const fetchProjectId = async () => {
if (currentUser?.id && selectedCompany) { // optional chaining 사용
try {
const response = await axios.get(`${MEMBER_API_URL}/members/${currentUser.id}/${selectedCompany}`);
// console.log(response.data.data.aiwaKeys[0].projectId);
setProjectId(response.data.data.aiwaKeys[0].projectId);
setCurrentUser(prev => ({
...prev,
projectId: response.data.data.aiwaKeys[0].projectId
}));
} catch (error) {
console.error('Error fetching project ID:', error);
}
}
};

fetchProjectId();
}, [currentUser?.id, selectedCompany]);

return (
<UserContext.Provider value={{
currentUser,
setCurrentUser,
selectedCompany,
setSelectedCompany
setSelectedCompany,
projectId,
setProjectId
}}>
{children}
</UserContext.Provider>
Expand Down
2 changes: 0 additions & 2 deletions aiwa-mcp-frontend/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ export const GCP_API_URL = 'https://alb.aiwa-cloud.com/gcp/api';

export const MEMBER_API_URL = 'https://alb.aiwa-cloud.com/member/api';

export const GCP_API_URL = 'https://alb.aiwa-cloud.com/gcp/api';


function App() {
return (
Expand Down

0 comments on commit 9e89a5c

Please sign in to comment.