ํ๋ก์ ํธ๋ฅผ ํ๋ฉด์, ์ฌ๋ฌ ๋ฐฉ์์ Axios ์์ฒญ์ด ์์๋๋ฐ ์ด์ ๋ํ ์ฝ๋๋ฅผ ์ ์ฅํ๋ฉด์ ์์ผ๋ก ๊ณ์ ์ฐธ๊ณ ํ๋ ์์ผ๋ก ๊ณต๋ถํ๋ ค๊ณ ๋ถ์!
const [items, setItems] = useState([]);
const setBranchSet = () => {
axios({
method: 'GET',
url: 'http://localhost:8080/api/kiosk/home/kiosk-list'
})
.then((res) => {
setItems(res.data)
})
.catch((err) => console.log(err))
}
useEffect(() => {
setBranchSet();
}, [])
{
items.map(item => {
return <KioskBranchLocation key={item.id} id={item.id} name={item.name} />
})
}
const { id } = useParams()
const [rentCnt, setRentCnt] = useState(0);
const [returnCnt, setReturnCnt] = useState(0);
const BrollyURL = `http://localhost:8080/api/kiosk/home/brolly/${id}`
axios({
method: 'GET',
url: BrollyURL,
})
.then((res) => {
setRentCnt(res.data.brollyCnt)
setReturnCnt(res.data.emptyCnt)
})
.catch((err) => {
console.log(err)
})
<div css={KioskButtons}>
<KioskRentBtn rentCnt={rentCnt} />
<KioskRemoveEventListener />
<KioskReturnBtn returnCnt={returnCnt} />
</div>
const [loading, setLoading] = useState(false);
const saveImage = () => {
// ๋ฐ์ดํฐ URL๋ก ๊ทธ๋๋ก ๋ณด๋ด๊ธฐ
const canvas = document.getElementById("$canvas");
const imgURL = canvas.toDataURL("image/png");
setLoading(true);
axios({
method: 'POST',
url: 'https://localhost:8080/api/brolly/return',
data: {
'brollyName': qrdata,
'caseId': id,
'imgData': imgURL
}
})
.then((res) => {
console.log(res.data.success)
if (!res.data.success) {
clearImage();
setOpen(true);
setLoading(false);
}
})
.catch((err) => console.log(err));
};
<div css={SpinnerDiv}>
{loading ? <Stack sx={{ zIndex: '990', backgroundColor: 'rgba(255, 255, 255, 0.5)', width: '102vw', height: '102vh', display: 'flex', justifyContent: 'center', alignItems: 'center' }} spacing={5} direction="row">
<CircularProgress sx={{ color: 'white' }} />
</Stack> : null}
</div>
<div>
<Dialog
sx={{ width: '100vw' }}
open={open}
TransitionComponent={Transition}
keepMounted
onClose={handleClose}
aria-describedby="alert-dialog-slide-description"
>
<DialogTitle sx={{backgroundColor: '#EEF1FF', fontFamily: 'GangwonEduPowerExtraBoldA'}} fontSize={32} fontWeight={900}>{"์ฐ์ฐ์ด ์ธ์๋์ง ์์์ต๋๋ค."}</DialogTitle>
<DialogContent sx={{backgroundColor: '#EEF1FF'}}>
<DialogContentText sx={{fontFamily: 'GangwonEduPowerExtraBoldA'}} fontSize={20} fontWeight={700} id="alert-dialog-slide-description">
์ฐ์ฐ์ ๊ผญ ํผ์ณ์ ์ดฌ์ํด์ฃผ์ธ์. ์ฐ์ฐ์ด ์ธ์๋์ง ์์ผ๋ฉด ๋ฐ๋ฉ ์ฒ๋ฆฌ๊ฐ ๋์ง์์ต๋๋ค.
</DialogContentText>
</DialogContent>
<DialogActions sx={{backgroundColor: '#EEF1FF'}}>
<Button sx={{fontFamily: 'GangwonEduPowerExtraBoldA'}} onClick={handleClose}>๋ซ๊ธฐ</Button>
</DialogActions>
</Dialog>
</div>
ํด๋น ํ๊ทธ๋ MUI ์ฌ์ฉ
const { id } = useParams()
const [address, setAddress] = useState('');
useEffect(() => {
// ์ด๊ฑฐ ์์ ํด์ผํจ
const getAddress = () => {
// ํค์ค์คํฌ geo ์์ ์ง์ ์ ํด๋นํ๋ ์๋ ๊ฒฝ๋๊ฐ ๋ฐ์์ค๊ธฐ
// let geoURL = `http://192.168.100.80:8080/api/kiosk/home/kiosk-geo?id=1`
let geoURL = `https://localhost:8080/api/kiosk/home/kiosk-geo?id=${id}`
let addressURL = ``;
axios.get(geoURL)
.then((res) => {
return res.data;
})
.then((data) => {
// addressURL = `http://192.168.100.80:8080/api/address/reverse-geo?lat=${data.lat}&lng=${data.lng}`;
addressURL = `https://localhost:8080/api/address/reverse-geo?lat=${data.lat}&lng=${data.lng}`;
axios.get(addressURL)
.then((res) => {
setAddress(res.data.address_name)
})
})
.catch((err) => console.log(err))
};
getAddress();
}, [id])
const [celsius, setCelsius] = useState(0);
const [windspeed, setWindspeed] = useState(0);
const [imgsrc, setImgsrc] = useState("");
const { id } = useParams();
useEffect(() => {
const getWeather = () => {
// ํค์ค์คํฌ geo ์์ ์ง์ ์ ํด๋นํ๋ ์๋ ๊ฒฝ๋๊ฐ ๋ฐ์์ค๊ธฐ
let geoURL = `https://localhost:8080/api/kiosk/home/kiosk-geo?id=${id}`;
let weatherURL = ``;
axios
.get(geoURL)
.then((res) => {
return res.data;
})
.then((data) => {
weatherURL = `https://localhost:8080/api/weather/current-weather?lat=${data.lat}&lng=${data.lng}`;
axios.get(weatherURL).then((res) => {
setImgsrc(res.data.icon);
setCelsius(res.data.temp);
setWindspeed(res.data.wind_speed);
});
})
.catch((err) => console.log(err));
};
getWeather();
}, [id]);
<div css={KioskHomeWeatherTextBox}>
<p className='celsius'>ํ์ฌ ๊ธฐ์จ {Math.round(celsius).toFixed(1)}<span>โฐ</span></p>
<p className='windspeed'>ํ์ : {windspeed}(m/s)</p>
</div>
const { isBrolly } = useParams();
const { id } = useParams();
const navigate = useNavigate();
const [isReturn, setIsReturn] = useState(false);
const [kioskName, setKioskName] = useState('');
const location = useLocation();
const queryParams = new URLSearchParams(location.search)
const depositeMoney = Number(queryParams.get('depositeMoney')).toLocaleString('ko-KR');
const period = Number(queryParams.get('period')).toLocaleString('ko-KR');
const price = Number(queryParams.get('price')).toLocaleString('ko-KR');
const refundMoney = Number(queryParams.get('refundMoney')).toLocaleString('ko-KR');
const KioskNameURL = `https://localhost:8080/api/kiosk/home/kiosk-name?id=${id}`
useEffect(() => {
if (isBrolly == 1) {
setIsReturn(true)
}
axios({
method:'GET',
url: KioskNameURL,
})
.then((res) => setKioskName(res.data))
.catch((err) => console.log(err))
const timer = setTimeout(() => {
navigate(`/kiosk/${id}`);
}, 30000);
return () => {
clearTimeout(timer);
};
}, [isReturn])
<div css={KioskReturnReceiptView}>
<h1>์๊ธ ์ฌํญ</h1>
<div css={KioskReturnReceipt}>
<div className='ReceiptTitle'>
<p className='BranchName'>{kioskName}</p>
</div>
<div className='ReceiptTotal'>
<p className='Payment'>{refundMoney}<span>์</span></p>
</div>
<div className='ReceiptDetailView'>
<div className='FirstHorizon'></div>
<div className='ReceiptDetail'><span className='FontColorGray'>๋ณด์ฆ๊ธ</span><span>{depositeMoney}์</span></div>
<div className='ReceiptDetail'><span className='FontColorGray'>์ด์ฉ ๊ธฐ๊ฐ</span><span>{period}์ผ</span></div>
<div className='ReceiptDetail'><span className='FontColorGray'>์ด์ฉ ๊ธ์ก</span><span>{price}์</span></div>
<div className='SecondHorizon'></div>
<div className='ReceiptDetailRefunds'><span>ํ๊ธ ๊ธ์ก</span><span>{refundMoney}์</span></div>
</div>
</div>
</div>
axios ์์ฒญ์ ๋ํ ํ์์ ์ตํ ์ ์์๊ณ , ์์ง ๋ก๊ทธ์ธ๊ณผ ํ์๊ฐ์ ๋ฑ์ ํ ๋, headers๋ Token ์ฒ๋ฆฌ ํ์์ ์์ง ๊ฒฝํํด๋ณด์ง ๋ชปํ๋ค. ๊ทธ๋์ ์ด๋ฅผ ๊ฒฝํํด๋ณด๊ธฐ ์ํด์ ๋ค์ ํ๋ก์ ํธ์์๋ ๊ฒฝํํด๋ณผ ๊ณํ์ด๋ค.