Skip to content

Commit 22ca916

Browse files
authored
Merge pull request #17 from 2022-Winter-Bootcamp-Team-D/feature/#16-Map_API
Feature/#16 map api
2 parents bde707e + 63cdf4a commit 22ca916

File tree

17 files changed

+712
-188
lines changed

17 files changed

+712
-188
lines changed

package-lock.json

Lines changed: 234 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@actbase/react-daum-postcode": "^1.0.4",
67
"@emotion/react": "^11.10.5",
78
"@emotion/styled": "^11.10.5",
89
"@material-ui/core": "^4.12.4",
@@ -17,15 +18,18 @@
1718
"@types/node": "^16.18.11",
1819
"@types/react": "^18.0.26",
1920
"@types/react-dom": "^18.0.10",
20-
"axios": "^1.2.2",
21+
"axios": "^1.2.5",
2122
"classnames": "^2.3.2",
2223
"dayjs": "^1.11.7",
24+
"http-proxy-middleware": "^2.0.6",
2325
"include-media": "^1.4.10",
2426
"open-color": "^1.9.1",
2527
"react": "^18.2.0",
2628
"react-datepicker": "^4.8.0",
2729
"react-dom": "^18.2.0",
30+
"react-geocode": "^0.2.3",
2831
"react-icons": "^4.7.1",
32+
"react-naver-maps": "^0.0.13",
2933
"react-router-dom": "^6.6.1",
3034
"react-scripts": "5.0.1",
3135
"react-table": "^7.8.0",
@@ -34,6 +38,7 @@
3438
"typescript": "^4.9.4",
3539
"web-vitals": "^2.1.4"
3640
},
41+
"proxy": "https://naveropenapi.apigw.ntruss.com",
3742
"scripts": {
3843
"start": "react-scripts start",
3944
"build": "react-scripts build",

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
work correctly both with client-side routing and a non-root public URL.
2525
Learn how to configure a non-root public URL by running `npm run build`.
2626
-->
27+
<script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?clientId=pg98qmcln0&submodules=panorama"></script>
2728
<title>React App</title>
2829
</head>
2930
<body>

src/components/CustomerRegister/RegisterInput.tsx

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ export default function RegisterInput() {
1919
console.log(token)
2020
}
2121

22-
//
23-
// const customerRegister =()=>{
24-
// //axios.post(url : post가 연결되어야 할 api주소, data : 백엔드에서 정의한 request body).then(앞 코드가 정상작동하면 실행되는 다음 행위)
25-
// axios.post('http://localhost:8000/api/v1/waitings/',{
26-
// store_id: localStorage.getItem('store_id'),
27-
// people: people,
28-
// token: 'token'})
29-
// .then((res) => console.log(res)) //(setItem) 로컬스토리지에 res.data.store_id를 "id"로 저장하는 코드,
30-
// // res는 사용자 마음대로 정의, res.data.store_id는 백엔드에서 받아온 response body
31-
// }
3222

3323
return (
3424
<div>

src/components/StoreRegister/StoreRegisterInput.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,34 @@
2222
color: black;
2323
border-radius: 10px;
2424

25+
}
26+
27+
/* 모달창을 화면 중앙. 최상단에 노출 */
28+
.container {
29+
/* 모달창 크기 */
30+
width: 300px;
31+
height: 200px;
32+
33+
/* 최상단 위치 */
34+
z-index: 999;
35+
36+
/* 중앙 배치 */
37+
/* top, bottom, left, right 는 브라우저 기준으로 작동한다. */
38+
/* translate는 본인의 크기 기준으로 작동한다. */
39+
position: absolute;
40+
top: 50%;
41+
left: 50%;
42+
transform: translate(-50%, -50%);
43+
44+
/* 모달창 디자인 */
45+
background-color: gray;
46+
border: 1px solid black;
47+
border-radius: 8px;
48+
}
49+
50+
/* 모달창 내부 X버튼 */
51+
.close {
52+
position: absolute;
53+
right: 10px;
54+
top: 10px;
2555
}
Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import Box from '@mui/material/Box';
33
import TextField from '@mui/material/TextField';
44
import './StoreRegisterInput.scss';
5-
import {
6-
Link, useNavigate
7-
} from "react-router-dom";
5+
import {Link, useNavigate} from "react-router-dom";
6+
// import StoreLocation from "./StoreLocation";
87
import axios from 'axios';
98

10-
//가게등록
119

1210
export default function RegisterInput() {
13-
1411
const [name, setName] = useState('')
1512
const [phone_num, setPhone_num] = useState('')
16-
const [posts, setPosts] = useState(0) //가게 주소
13+
const [posts, setPosts] = useState('') //가게 주소
1714
const [email, setEmail] = useState('')
1815
const [password, setPassword] = useState('')
19-
2016
const navigate = useNavigate();
17+
const [latitude, setlatitude] = useState(0);
18+
const [longitude, setLogitude] = useState(0);
19+
20+
21+
const storeSearch =()=>{
22+
axios.get(`map-geocode/v2/geocode?query=${posts}`,
23+
{
24+
headers: {
25+
"X-NCP-APIGW-API-KEY-ID": "pg98qmcln0",
26+
"X-NCP-APIGW-API-KEY": "ELFgrKAgPdLsxeQDxHBhqv1jQvrpZuVfDJ4Jcmrf"
27+
}
28+
})
29+
.then((response) => {
30+
setlatitude(response.data.addresses[0].y)
31+
setLogitude(response.data.addresses[0].x)
32+
})
33+
}
2134

2235
const storeRegister =()=>{
23-
//axios.post(url : post가 연결되어야 할 api주소, data : 백엔드에서 정의한 request body).then(앞 코드가 정상작동하면 실행되는 다음 행위)
24-
axios.post('http://localhost:8000/api/v1/stores/signin/',{
36+
axios.post('http://15.164.28.246:8000/api/v1/stores/signup/',{
2537
name: name,
2638
phone_num: phone_num,
27-
latitude: 0,
28-
longitude: 0,
39+
latitude: latitude,
40+
longitude: longitude,
2941
email : email,
3042
password: password})
31-
.then((res) =>localStorage.setItem("token", res.data.token) )
32-
navigate("/WaitingList") // .then에 넣어야 할듯..!
43+
.then((response) => {
44+
var str1 = 'Bearer '
45+
var token = str1.concat(response.data.access)
46+
localStorage.setItem('accessToken', token);
47+
console.log(response.data.latitude)
48+
console.log(response.data.longitude)
49+
navigate("/WaitingList")
50+
})
3351
}
34-
//console.log(localStorage.getItem("id")) 로컬스토리지에서 저장되어있는 값을 꺼내와서 console.log에 출력해서 확인하는 코드(getItem)
3552

3653
return (
3754
<div>
@@ -45,12 +62,12 @@ export default function RegisterInput() {
4562
>
4663
<TextField onChange={(e)=>{setName(e.target.value)}} id="standard-basic" label="가게명 / 업소명" variant="standard" />
4764
<TextField onChange={(e)=>{setPhone_num(e.target.value)}}id="standard-basic" label="가게 번호" variant="standard" />
48-
<TextField onChange={(e)=>{setPosts(Number(e.target.value))}}id="standard-basic" label="가게 주소" variant="standard" />
65+
<TextField onChange={(e)=>{setPosts((e.target.value))}}id="standard-basic" label="가게 주소" variant="standard" />
4966
<TextField onChange={(e)=>{setEmail(e.target.value)}}id="standard-basic" label="이메일 주소" variant="standard" />
50-
<TextField onChange={(e)=>{setPassword(e.target.value)}}id="standard-basic" label="비밀번호" variant="standard" />
67+
<TextField type="password" onChange={(e)=>{setPassword(e.target.value)}}id="standard-basic" label="비밀번호" variant="standard" />
5168
</Box>
69+
5270
<button onClick={storeRegister} className="ButtonStyle" >가게 등록</button>
5371
</div>
54-
5572
);
5673
}

src/components/WaitingList/ListTable.tsx

Lines changed: 91 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import CheckCircleIcon from '@mui/icons-material/CheckCircle';
1414
import CancelIcon from '@mui/icons-material/Cancel';
1515
import axios from 'axios';
1616
import {waitings, res} from './Waiting';
17+
import {useEffect,useState} from "react";
1718

1819
import { Console } from 'console';
20+
import { tokenToString } from 'typescript';
1921

2022
interface Column {
2123
id: 'waiting_id' | 'name' | 'people' | 'phone_num';
@@ -25,15 +27,18 @@ interface Column {
2527
format?: (value: number) => string;
2628
}
2729

30+
2831
const columns: readonly Column[] = [
29-
{ id: 'waiting_id', label: '순번', minWidth: 30 },
30-
{ id: 'name', label: '예약자', minWidth: 30 },
32+
33+
{ id: 'waiting_id', label: '순번', minWidth: 30, align: 'center', }, //(count++).toString()
34+
{ id: 'name', label: '예약자', minWidth: 30, align: 'center' },
3135
{
3236
id: 'people',
3337
label: '인원 수',
3438
minWidth: 30,
3539
align: 'center',
3640
},
41+
3742
{
3843
id: 'phone_num',
3944
label: '휴대폰 번호',
@@ -42,46 +47,78 @@ const columns: readonly Column[] = [
4247
},
4348
];
4449

45-
export default function ListTable({waiting}:{waiting:waitings[]}) {
50+
export default function ListTable({waiting ,setTemp}:{waiting:waitings[]|undefined; setTemp:React.Dispatch<React.SetStateAction<res | undefined>>}) {
51+
let abc: number;
4652
const [page, setPage] = React.useState(0);
47-
const [rowsPerPage, setRowsPerPage] = React.useState(100);
48-
const [rows, setRows] = React.useState<waitings[]>(waiting);
53+
const [rowsPerPage, setRowsPerPage] = React.useState(5);
54+
4955
const handleChangePage = (event: unknown, newPage: number) => {
5056
setPage(newPage)
51-
console.log(rows)
57+
console.log(waiting)
5258
};
5359

54-
function setrowData() {
55-
setRows(rows)
56-
}
57-
5860
const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement>) => {
5961
setRowsPerPage(+event.target.value);
6062
setPage(0);
6163
};
62-
64+
65+
//대기목록 MUI 안에 있는 호출 버튼
66+
const Call =(index: number)=>{
67+
if(waiting !== undefined) {
68+
axios.post('http://15.164.28.246:8000/api/v1/stores/notifications/',{
69+
waiting_id: waiting[index].waiting_id
70+
},
71+
{
72+
headers : {Authorization: localStorage.getItem('accessToken')}
73+
})
74+
.then((response) => {
75+
console.log('성공')
76+
})
77+
.catch((error) => {
78+
console.log('호출 실패');
79+
});
80+
}}
81+
6382
//대기목록 MUI 안에 있는 입장완료 버튼
6483
const Start = (index: number) => {
65-
axios.patch('http://localhost:8000/api/v1/stores/waitings/',{
66-
waiting_id: rows[index].waiting_id
67-
})
68-
.then((res) =>setRows(res.data.waiting)) //55행 이용, res로 넘어온 정보저장 해야대, 그렇기에 setRows가
69-
.catch((error) => {
70-
console.log('Error!');
71-
});
72-
}
73-
74-
//대기목록 MUI 안에 있는 대기취소 버튼
75-
const waitingCancel = (index: number) => {
76-
axios.patch<res>('http://localhost:8000/api/v1//stores/cancellations/',{
77-
waiting_id: rows[index].waiting_id
78-
})
79-
.then((res) =>setRows(res.data.waiting))
84+
if(waiting !== undefined) {
85+
axios.patch('http://15.164.28.246:8000/api/v1/stores/waitings/',{
86+
waiting_id: waiting[index].waiting_id
87+
},
88+
{
89+
headers : {Authorization: localStorage.getItem('accessToken')}
90+
}
91+
)
92+
.then((response) => {
93+
console.log('[입장완료]' + localStorage.getItem('accessToken'))
94+
})
8095
.catch((error) => {
8196
console.log('Error!');
8297
});
83-
}
84-
98+
}}
99+
100+
//대기목록 MUI 안에 있는 대기취소 버튼
101+
const waitingCancel = (index: number) => {
102+
if(waiting != undefined) {
103+
axios.patch<res>('http://15.164.28.246:8000/api/v1/stores/cancellations/',{
104+
waiting_id: waiting[index].waiting_id
105+
},
106+
{
107+
headers : {Authorization: localStorage.getItem('accessToken')}
108+
}
109+
)
110+
.then((response) => {
111+
//민아) 행 삭제 시도
112+
// setTemp(pre => ({...pre,waiting:[...response.data.waiting]}));
113+
console.log('[대기강제취소]' + localStorage.getItem('accessToken'))
114+
})
115+
.catch((error) => {
116+
console.log('Error!');
117+
});
118+
}}
119+
120+
121+
85122
return (
86123
<Paper className='tableStyle'>
87124
<TableContainer sx={{ maxHeight: 500 }}>
@@ -104,26 +141,33 @@ export default function ListTable({waiting}:{waiting:waitings[]}) {
104141
</TableHead>
105142
<TableBody>
106143

107-
{rows
108-
.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
109-
.map((row:any) => {
144+
145+
{waiting?.slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
146+
.map((row:any, index:number) => {
147+
148+
if(waiting != undefined) {
149+
abc = waiting.length
150+
}
151+
110152
return (
111153
<TableRow hover role="checkbox" tabIndex={-1} key={row.waiting_id}>
112-
{columns.map((column:any) => {
113-
console.log(rows)
154+
{columns.map((column:any, i:number) => {
155+
//console.log(waiting)
114156
const value = row[column.id];
115-
157+
116158
return (
117159
<TableCell key={column.id} align={column.align}>
118-
{column.format && typeof value === 'number'
119-
? column.format(value)
120-
: value}
160+
161+
{column?.id === 'waiting_id'
162+
? (page*rowsPerPage)+(index+1) : value}
163+
164+
121165
</TableCell>
122166
);
123167
})}
124-
<TableCell align="center"><IconButton><NotificationsActiveIcon color="warning"/></IconButton></TableCell>
125-
<TableCell onClick={() => Start(row.waiting_id)} align="center"><IconButton><CheckCircleIcon color="success"/></IconButton></TableCell>
126-
<TableCell onClick={() => waitingCancel(row.waiting_id)} align="center"><IconButton><CancelIcon color="error"/></IconButton></TableCell>
168+
<TableCell onClick={() => Call(index)} align="center"><IconButton><NotificationsActiveIcon color="warning"/></IconButton></TableCell>
169+
<TableCell onClick={() => Start(index)} align="center"><IconButton><CheckCircleIcon color="success"/></IconButton></TableCell>
170+
<TableCell onClick={() => waitingCancel(index)} align="center"><IconButton><CancelIcon color="error"/></IconButton></TableCell>
127171
</TableRow>
128172
);
129173
})}
@@ -134,12 +178,17 @@ export default function ListTable({waiting}:{waiting:waitings[]}) {
134178
<TablePagination
135179
rowsPerPageOptions={[5, 10, 25]}
136180
component="div"
137-
count={rows.length}
181+
count= {waiting?.length as number}
138182
rowsPerPage={rowsPerPage}
139183
page={page}
140184
onPageChange={handleChangePage}
141185
onRowsPerPageChange={handleChangeRowsPerPage}
142186
/>
143187
</Paper>
144188
);
145-
}
189+
}
190+
191+
ListTable.defaultProps = {
192+
waiting:[]
193+
}
194+

0 commit comments

Comments
 (0)