-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev-client' of github.com:codestates-seb/seb45_main_008…
… into dev-client#17/stockOrder
- Loading branch information
Showing
10 changed files
with
512 additions
and
31 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
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
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import styled from 'styled-components'; | ||
import axios from 'axios'; | ||
|
||
const CashModal: React.FC<CashModalProps> = ({ onClose, memberId }) => { | ||
const [cash, setCash] = useState<number | null>(null); | ||
const [cashInput, setCashInput] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
axios.get(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/cash/${memberId}`) | ||
.then(response => { | ||
if (response.status === 200) { | ||
setCash(response.data.cash); | ||
} else if (response.status === 204) { | ||
// Handle the "No Content" scenario. This could be setting cash to 0 or displaying a message. | ||
setCash(0); // Or handle it in a way that suits your needs | ||
} | ||
}) | ||
.catch(error => { | ||
console.error("Error fetching cash:", error); | ||
}); | ||
}, [memberId]); | ||
|
||
const handleCashReceive = () => { | ||
axios.post(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/cash/${memberId}`, { | ||
cash: cashInput | ||
}) | ||
.then(response => { | ||
if (response.status === 201) { | ||
// Update the cash display with the new value | ||
setCash(prevCash => prevCash ? prevCash + Number(cashInput) : Number(cashInput)); | ||
} else { | ||
console.warn("Unexpected status code:", response.status); | ||
} | ||
}) | ||
.catch(error => { | ||
console.error("Error updating cash:", error); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ModalBackground> | ||
<ModalContainer> | ||
<CloseButton onClick={onClose}>×</CloseButton> | ||
<Title>현금</Title> | ||
<p>현재 현금: {cash ? cash.toLocaleString() : 'Loading...'}</p> | ||
<div> | ||
<CashInput | ||
type="number" | ||
value={cashInput} | ||
onChange={e => setCashInput(e.target.value)} | ||
placeholder="현금 입력" | ||
/> | ||
<ReceiveButton onClick={handleCashReceive}>받기</ReceiveButton> | ||
</div> | ||
</ModalContainer> | ||
</ModalBackground> | ||
); | ||
}; | ||
|
||
interface CashModalProps { | ||
onClose: () => void; | ||
memberId: string; | ||
} | ||
|
||
// Styled Components Definitions: | ||
|
||
const ModalBackground = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
`; | ||
|
||
const ModalContainer = styled.div` | ||
position: relative; | ||
background-color: white; | ||
padding: 20px; | ||
width: 400px; | ||
border-radius: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
const Title = styled.h2` | ||
margin-bottom: 20px; | ||
font-size: 1.6rem; | ||
font-weight: 400; | ||
`; | ||
|
||
const CloseButton = styled.button` | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
background: #FFFFFF; | ||
border: 1px solid lightgray; | ||
font-size: 1.5rem; | ||
cursor: pointer; | ||
`; | ||
|
||
const CashInput = styled.input` | ||
padding: 10px; | ||
border: 1px solid lightgray; | ||
border-radius: 5px; | ||
margin-right: 10px; | ||
`; | ||
|
||
const ReceiveButton = styled.button` | ||
padding: 10px 15px; | ||
background-color: darkgreen; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
`; | ||
|
||
export default CashModal; |
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import styled from 'styled-components'; | ||
import axios from 'axios'; | ||
|
||
const MemberInfoModal: React.FC<MemberInfoModalProps> = ({ onClose, memberId }) => { | ||
const [memberInfo, setMemberInfo] = useState<MemberData | null>(null); // Use the MemberData type | ||
|
||
const titleText = "회원정보"; | ||
const loadingText = "Loading..."; | ||
const nameText = "이름: "; | ||
const emailText = "이메일: "; | ||
const createdAtText = "회원 가입 일시: "; | ||
const memberIdText = "회원 ID: "; | ||
|
||
useEffect(() => { | ||
// Fetch member info when the modal is opened | ||
axios.get<MemberData>(`http://ec2-13-125-246-160.ap-northeast-2.compute.amazonaws.com/members/${memberId}`) | ||
.then(response => { | ||
setMemberInfo(response.data); | ||
}) | ||
.catch(error => { | ||
console.error("Error fetching member info:", error); | ||
}); | ||
}, [memberId]); | ||
|
||
return ( | ||
<ModalBackground> | ||
<ModalContainer> | ||
<CloseButton onClick={onClose}>×</CloseButton> | ||
<Title>{titleText}</Title> | ||
{memberInfo ? ( | ||
<div> | ||
{/* Display member information */} | ||
<p>{memberIdText}{memberInfo.memberId}</p> | ||
<p>{nameText}{memberInfo.name}</p> | ||
<p>{emailText}{memberInfo.email}</p> | ||
<p>{createdAtText}{memberInfo.createdAt}</p> | ||
</div> | ||
) : ( | ||
<p>{loadingText}</p> | ||
)} | ||
</ModalContainer> | ||
</ModalBackground> | ||
); | ||
}; | ||
|
||
interface MemberInfoModalProps { | ||
onClose: () => void; | ||
memberId: string; | ||
} | ||
interface MemberData { | ||
memberId: number; | ||
email: string; | ||
name: string; | ||
createdAt: string; | ||
} | ||
|
||
// Styled Components Definitions: | ||
|
||
const ModalBackground = styled.div` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
`; | ||
|
||
const ModalContainer = styled.div` | ||
position: relative; | ||
background-color: white; | ||
padding: 20px; | ||
width: 400px; | ||
border-radius: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
`; | ||
|
||
const Title = styled.h2` | ||
margin-bottom: 20px; | ||
font-size: 1.6rem; | ||
font-weight: 400; | ||
`; | ||
|
||
const CloseButton = styled.button` | ||
position: absolute; | ||
top: 10px; | ||
right: 10px; | ||
background: #FFFFFF; | ||
border: 1px solid lightgray; | ||
font-size: 1.5rem; | ||
cursor: pointer; | ||
`; | ||
|
||
export default MemberInfoModal; |
Oops, something went wrong.