1- import { Button , HStack } from "@chakra-ui/react" ;
1+ import { Button , HStack , Spinner } from "@chakra-ui/react" ;
22import { FormProvider } from "react-hook-form" ;
33import CheckBox from "../../../components/internal-ui/CheckBox" ;
44import {
@@ -12,11 +12,18 @@ import { terraformEC2Mapper } from "../../../utils/mapperFunctions";
1212import useTerraFormHandler from "../hooks" ;
1313
1414const EC2 = ( ) => {
15- const { formMethods, handleSubmit, onSubmit, isSuccess, isError } =
16- useTerraFormHandler < TerraformEc2FormData , ApiRequestTerraformEc2 > (
17- terraformEc2DefaultValues ,
18- Endpoints . POST_IAC_T_EC2
19- ) ;
15+ const {
16+ formMethods,
17+ handleSubmit,
18+ onSubmit,
19+ isSuccess,
20+ isError,
21+ status,
22+ data,
23+ } = useTerraFormHandler < TerraformEc2FormData , ApiRequestTerraformEc2 > (
24+ terraformEc2DefaultValues ,
25+ Endpoints . POST_IAC_T_EC2
26+ ) ;
2027
2128 const handleFormSubmit = handleSubmit ( ( data ) =>
2229 onSubmit ( terraformEC2Mapper ( data ) )
@@ -31,29 +38,40 @@ const EC2 = () => {
3138 < p className = "font-bold" > EC2 service: </ p >
3239 < CheckBox
3340 fieldName = { TerraformEC2Fields . KEY_PAIR }
34- label = "Key pair? "
41+ label = "Key pair"
3542 />
3643 < CheckBox
3744 fieldName = { TerraformEC2Fields . SECURITY_GROUP }
38- label = "Security group? "
45+ label = "Security group"
3946 />
4047 < CheckBox
4148 fieldName = { TerraformEC2Fields . AWS_INSTANCE }
42- label = "AWS instance? "
49+ label = "AWS instance"
4350 />
4451 < CheckBox
4552 fieldName = { TerraformEC2Fields . AMI_FROM_INSTANCE }
46- label = "AMI from instance? "
53+ label = "AMI from instance"
4754 />
4855 </ HStack >
49- < Button type = "submit" bg = "orange.700" w = "8rem" h = "3rem" >
50- Generate
56+ < Button
57+ type = "submit"
58+ disabled = { status === "pending" && ! data }
59+ bg = "orange.700"
60+ w = "8rem"
61+ h = "3rem"
62+ >
63+ { status === "pending" ? (
64+ < span className = "loading loading-ring loading-md " > </ span >
65+ ) : (
66+ < p > Generate</ p >
67+ ) }
5168 </ Button >
5269 </ div >
5370 </ form >
5471 </ FormProvider >
5572 { isSuccess && < p className = "text-green-600" > Generated Succesfully</ p > }
5673 { isError && < p className = "text-red-700" > Operation failed</ p > }
74+ { ( status === "pending" || status === "idle" ) && < Spinner /> }
5775 </ div >
5876 ) ;
5977} ;
0 commit comments