-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d115f84
commit fdfbfd3
Showing
1 changed file
with
98 additions
and
14 deletions.
There are no files selected for viewing
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,33 +1,117 @@ | ||
import { useState } from "react"; | ||
import { Flex, Heading } from "@aws-amplify/ui-react"; | ||
import React, { useState, useEffect } from "react"; | ||
import { Button, Flex, Heading } from "@aws-amplify/ui-react"; | ||
import NavBar from "../NavBar/NavBar"; | ||
import SidebarConsole from "../SideBar/SidebarConsole"; | ||
import { NotificationContainer } from 'react-notifications'; | ||
import { MyPage } from '../Console'; | ||
import { NotificationContainer } from "react-notifications"; | ||
import axios from "axios"; | ||
import { useUserContext } from '../../UserContext'; | ||
|
||
function Migration() { | ||
const [selectedProvider, setSelectedProvider] = useState(null); | ||
const [isSuccess, setIsSuccess] = useState(false); | ||
const { currentUser } = useUserContext(); | ||
|
||
// SidebarConsole에서 사용하는 onSelectProvider prop에 맞춰 핸들러 정의 | ||
const handleSelectProvider = (provider) => { | ||
console.log("Selected provider in Migration:", provider); // 디버깅용 로그 | ||
console.log("Selected provider in Migration:", provider); | ||
setSelectedProvider(provider); | ||
}; | ||
|
||
const handleBedrockChange = async () => { | ||
if (!selectedProvider) { | ||
alert("Please select a provider first."); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await axios.post("https://alb.aiwa-cloud.com/bedrock/api/username", { | ||
user_email: currentUser.id, | ||
platform: selectedProvider, | ||
}); | ||
|
||
if (response.status === 200) { | ||
alert("Bedrock change completed successfully!"); | ||
setIsSuccess(true); // 성공 시 Terraform Apply 버튼 활성화 | ||
} | ||
} catch (error) { | ||
console.error("Error during Bedrock change:", error); | ||
alert("Failed to change Bedrock. Please try again."); | ||
} | ||
}; | ||
|
||
const handleTerraformApply = async () => { | ||
if (!selectedProvider) { | ||
alert("Please select a provider first."); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await axios.post("https://alb.aiwa-cloud.com/bedrock/api/confirm", { | ||
user_email: currentUser.id, | ||
platform: selectedProvider, | ||
}); | ||
|
||
if (response.status === 200) { | ||
alert("Terraform applied successfully!"); | ||
} | ||
} catch (error) { | ||
console.error("Error during Terraform apply:", error); | ||
alert("Failed to apply Terraform. Please try again."); | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={{ height: '100vh', display: 'flex', flexDirection: 'column' }}> | ||
<div style={{ height: "100vh", display: "flex", flexDirection: "column" }}> | ||
<NavBar /> | ||
<NotificationContainer /> | ||
<Flex direction="row" className="console-content"> | ||
<Flex direction="row" className="console-content" style={{ flexGrow: 1 }}> | ||
<SidebarConsole onSelectProvider={handleSelectProvider} /> | ||
{selectedProvider && <MyPage provider={selectedProvider} />} | ||
<Heading level={4}>Migration List</Heading> | ||
</Flex> | ||
<div style={{ padding: "20px", flexGrow: 1 }}> | ||
<Heading level={4}>Migration Actions</Heading> | ||
|
||
|
||
{/* 사용자 이메일 표시 */} | ||
<p style={{ marginBottom: "20px" }}> | ||
Logged in as: <strong>{currentUser.id}</strong> | ||
</p> | ||
|
||
{/* 플랫폼 선택 버튼 */} | ||
<div style={{ marginBottom: "20px" }}> | ||
<p>Select a Provider:</p> | ||
<Button | ||
onClick={() => handleSelectProvider("AWS")} | ||
variation={selectedProvider === "AWS" ? "primary" : "default"} | ||
style={{ marginRight: "10px" }} | ||
> | ||
AWS | ||
</Button> | ||
<Button | ||
onClick={() => handleSelectProvider("GCP")} | ||
variation={selectedProvider === "GCP" ? "primary" : "default"} | ||
> | ||
GCP | ||
</Button> | ||
</div> | ||
|
||
{/* 작업 버튼 */} | ||
<div style={{ marginTop: "20px" }}> | ||
<Button | ||
onClick={handleBedrockChange} | ||
variation="primary" | ||
style={{ marginRight: "10px" }} | ||
> | ||
Bedrock Change | ||
</Button> | ||
<Button | ||
onClick={handleTerraformApply} | ||
variation="secondary" | ||
disabled={!isSuccess} // Bedrock Change 성공 시에만 활성화 | ||
> | ||
Terraform Apply | ||
</Button> | ||
</div> | ||
</div> | ||
</Flex> | ||
</div> | ||
); | ||
} | ||
|
||
export default Migration; | ||
|
||
export default Migration; |