Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions components/stock-operation-modal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const StockOperationModal = (props) => {
const [quantity, setQuantity] = useState('');
const [isUserLoggedIn, setIsUserLoggedIn] = useState(false);
const [userMoney, setUserMoney] = useState(0);
const [loading, setLoadingState] = useState(false);

const validateQuantity = (quantity) => {
if (quantity > availableQty) {
Expand Down Expand Up @@ -80,7 +81,7 @@ const StockOperationModal = (props) => {
listedPrice: listedPriceOfStock,
totalPrice: quantity * listedPriceOfStock,
};

setLoadingState(true);
fetch(`${BASE_API_URL}/trade/stock/new/self`, {
credentials: 'include',
method: 'POST',
Expand All @@ -96,13 +97,15 @@ const StockOperationModal = (props) => {
throw new Error(response.statusText);
}
})
.then((data) =>
.then((data) => {
alert(
`Trading Successful! Your balance is ${data.userBalance} Dineros`
)
)
);
setLoadingState(false);
})
.catch((err) => {
alert(err.message);
setLoadingState(false);
});
}
};
Expand Down Expand Up @@ -170,10 +173,14 @@ const StockOperationModal = (props) => {
? styles.greenButton
: styles.redButton
}`}
disabled={!(nameOfStock && listedPriceOfStock && quantity)}
disabled={
!(nameOfStock && listedPriceOfStock && quantity) && loading
}
onClick={submitHandler}
>
{transactionType}
<div className={loading ? styles.spin : ''}>
{!loading && transactionType}
</div>
</button>
</div>
</div>
Expand Down
272 changes: 145 additions & 127 deletions components/stock-operation-modal/stock-operation.module.css
Original file line number Diff line number Diff line change
@@ -1,148 +1,166 @@
.backgroundVisible {
position: fixed;
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
display: block;
cursor: default;
}

.modalWrapper {
position: fixed;
z-index: 100;
background: white;
border-radius: 10px;
padding: 20px 20px;
width: 40%;
max-width: 435px;
height: auto;
top: 30vh;
left: 34%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
display: block;
/* animation: fade-slide-in 0.3s ease-in-out forwards; */
}

/* @keyframes fade-slide-in {
from {
transform: translateY(-30rem);
}
to {
transform: translateY(0);
}
} */

.modalContent {
padding: 1rem;
display: flex;
flex-direction: column;
}

.modalActions {
padding: 1rem;
display: flex;
justify-content: flex-end;
}

.label {
font-weight: bold;
margin: 0.5rem 0;
color: #464646;
}

.select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

.closedButton {
cursor: pointer;
position: absolute;
top: 8px;
right: 15px;
z-index: 10;
width: 20px;
height: 20px;
color: rgb(199, 57, 57);
border-radius: 50%;
text-align: center;
font-size: 1rem;
font-weight: 700;
}

@media only screen and (max-width: 600px) {
.background {
width: 100%;
height: 100%;
height: 100vh;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
display: block;
pointer-events: all;
}

.modalWrapper {
position: fixed;
z-index: 100;
background: white;
border-radius: 10px;
padding: 20px 20px;
width: 40%;
max-width: 435px;
padding: 20px 10px;
width: 80%;
height: auto;
top: 30vh;
left: 34%;
left: 10%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
display: block;
animation: fade-slide-in 0.3s ease-in-out forwards;
}

@keyframes fade-slide-in {
from {
transform: translateY(-30rem);
}
to {
transform: translateY(0);
}
}

.modalContent {
padding: 1rem;
display: flex;
flex-direction: column;
}

.modalActions {
padding: 1rem;
display: flex;
justify-content: flex-end;
}

.label {
font-weight: bold;
margin: 0.5rem 0;
color: #464646;
}

.select {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

.closedButton {
cursor: pointer;
position: absolute;
top: 8px;
right: 15px;
z-index: 10;
width: 20px;
height: 20px;
color: rgb(199, 57, 57);
border-radius: 50%;
text-align: center;
font-size: 1rem;
font-weight: 700;
}
.closedButton:hover {
transform: scale(2);
}

@media only screen and (max-width: 600px) {
.background {
width: 100%;
height: 100vh;
top: 0;
left: 0;
background: rgba(0, 0, 0, 0.5);
z-index: 100;
display: block;
pointer-events: all;
}

.modalWrapper {
position: fixed;
z-index: 100;
background: white;
border-radius: 10px;
padding: 20px 10px;
width: 80%;
height: auto;
top: 30vh;
left: 10%;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.26);
display: block;
animation: fade-slide-in 0.3s ease-out forwards;
}
}

.buttonClass {
width: 100%;
padding: 10px 20px;
margin-top: 16px;
border-radius: 5px;
color: white;
font-weight: bold;
font-size: 20px;
cursor: pointer;
display: flex;
justify-content: center;
}

.greenButton {
background-color: #2ecc71;
border: 1px solid #2ecc71;
}

.redButton {
color: white;
background-color: #ff3838;
border: 1px solid #ff3838;
animation: fade-slide-in 0.3s ease-out forwards;
}

.errorMessage {
font-size: 0.8rem;
margin-top: -10px;
margin-bottom: 10px;
color: red;
}

.buttonClass {
width: 100%;
padding: 10px 20px;
margin-top: 16px;
border-radius: 5px;
color: white;
font-weight: bold;
font-size: 20px;
cursor: pointer;
display: flex;
justify-content: center;
}

.spin {
border: 16px solid #0e57c4;
border-radius: 50%;
border-top: 4px solid #c9d4e6;
border-right: 4px solid #bbc9dd;
border-bottom: 4px solid #96bff9;
border-left: 4px solid #c9e0ff;
width: 25px;
height: 25px;
-webkit-animation: spin 1s linear infinite;
animation: spin 1s linear infinite;
}

@keyframes spin {
0% {
transform: rotate(0deg);
}

.buttonDisabled {
background-color: #cccccc;
color: #666666;
opacity: 0.5;
100% {
transform: rotate(360deg);
}

}

.greenButton {
background-color: #2ecc71;
border: 1px solid #2ecc71;
}

.redButton {
color: white;
background-color: #ff3838;
border: 1px solid #ff3838;
}

.errorMessage {
font-size: 0.8rem;
margin-top: -10px;
margin-bottom: 10px;
color: red;
}

.buttonDisabled {
background-color: #cccccc;
color: #666666;
opacity: 0.5;
}