Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api 연결 #15

Merged
merged 50 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e06d3bd
feat: payment history get api
iOdiO89 Aug 22, 2024
2942e8d
feat: 승인 대기 주문 데이터 연결
iOdiO89 Aug 22, 2024
746f4ae
refactor: menu, option 타입 분리
iOdiO89 Aug 22, 2024
86747cc
fix: 새로고침시 focused 탭 정보 reset되지 않게 수정
iOdiO89 Aug 23, 2024
2a98bf8
feat: 탭별 알림 개수 설정
iOdiO89 Aug 23, 2024
ccd8855
fix: payment history DTO 수정
iOdiO89 Aug 23, 2024
f20dca0
fix: 진행중 알림개수 계산 오류 수정
iOdiO89 Aug 23, 2024
9ef6d54
fix: prevOrders type 재정의 및 데이터 연결
iOdiO89 Aug 23, 2024
6f194e2
fix: 각 탭별 orderCard 조회 조건 부여
iOdiO89 Aug 23, 2024
26b113a
refactor: 불필요한 코드 제거
iOdiO89 Aug 23, 2024
d58beb6
feat: ArrowIcon 애니메이션 추가
iOdiO89 Aug 23, 2024
2e72037
fix: update orderhistory interface
iOdiO89 Aug 25, 2024
8940f3f
fix: orderCard time prop 추가
iOdiO89 Aug 25, 2024
b7c22d5
fix: 이전 주문 보이기 animation 추가
iOdiO89 Aug 25, 2024
b224517
feat: payment history patch api
iOdiO89 Aug 25, 2024
bbc5d1b
feat: 카카오 로그인 구현
iOdiO89 Aug 26, 2024
06e42bf
fix: orderCard 시간 정보 입력
iOdiO89 Aug 26, 2024
a9cd8db
feat: payment history patch api
iOdiO89 Aug 26, 2024
3baf489
fix: /api/kakao 한번만 실행되게 변경
iOdiO89 Aug 26, 2024
d807691
fix: 승인대기 order card 시간 오류 수정
iOdiO89 Aug 26, 2024
a120cae
fix: options 출력 조건 수정
iOdiO89 Aug 26, 2024
61573b8
design: modify prevOrders animation style
iOdiO89 Aug 28, 2024
e51ecc7
fix: storeId atomWithStorage로 저장
iOdiO89 Aug 31, 2024
20330b4
fix: 승인 대기 Order 시간순으로 정렬
iOdiO89 Aug 31, 2024
ecf6d8a
feat: 주문거절 모달 구현 및 API 연결
iOdiO89 Sep 1, 2024
2591d27
fix: history 탭 count 변수 제거
iOdiO89 Sep 1, 2024
be9eda4
refactor: clickOrder 함수 재활용
iOdiO89 Sep 1, 2024
bd3806a
fix: history Input format 오류 수정
iOdiO89 Sep 1, 2024
49d27de
refactor: 탭별 알림개수 Update 위치 수정
iOdiO89 Sep 1, 2024
641a91a
feat: 히스토리탭 필터 적용
iOdiO89 Sep 1, 2024
f8f3ada
fix: UTC를 KST로 바꿔서 시간 출력
iOdiO89 Sep 1, 2024
d1a7c2f
refactor: 시간 출력 문구 변경 및 함수 분리
iOdiO89 Sep 1, 2024
d00e540
fix: 진행 중 탭에서는 Process data만 get하도록 변경
iOdiO89 Sep 1, 2024
da198d3
fix: Modal width 변경
iOdiO89 Sep 1, 2024
3b807dd
fix: 진행중인 주문 최신순으로 정렬
iOdiO89 Sep 1, 2024
3cd6992
feat: 결제 완료 400 에러시 modal 띄우기
iOdiO89 Sep 1, 2024
bbf710e
feat: 결제 완료 400 에러시 승인되지 않은 주문으로 scroll
iOdiO89 Sep 1, 2024
fdb7cfb
feat: Loading Indicator 추가
iOdiO89 Sep 1, 2024
658a47c
fix: 5초마다 get 반복하도록 수정
iOdiO89 Sep 1, 2024
285580d
feat: 새로운 주문이 들어오면 효과음 출력
iOdiO89 Sep 1, 2024
0b7eeff
fix: app 이름 변경
iOdiO89 Sep 1, 2024
c4c955a
fix: History 시간 순으로 정렬
iOdiO89 Sep 1, 2024
45cd655
fix: 모달 문구 수정
iOdiO89 Sep 1, 2024
eca3a64
fix: modal 문구 오류 수정
iOdiO89 Sep 1, 2024
edff171
refactor: 승인대기 탭만 5초마다 refetch하도록 설정
iOdiO89 Sep 1, 2024
b500051
refactor: 함수 파일 통합
iOdiO89 Sep 1, 2024
8446b03
refactor: 불필요한 Import 제거
iOdiO89 Sep 1, 2024
306652a
fix: 히스토리 탭 orderhistory 최신순 정렬
iOdiO89 Sep 1, 2024
483e3f9
fix: 진행중 탭 알림개수 계산방식 변경
iOdiO89 Sep 1, 2024
5e81f49
fix: 승인대기 중인 주문이 존재할 때는 계속 sound 발생하게
iOdiO89 Sep 3, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"dayjs": "^1.11.12",
"dotenv": "^16.4.5",
"electron-is-dev": "^3.0.1",
"framer-motion": "^11.3.30",
"jotai": "^2.9.0",
"jotai-devtools": "^0.10.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-loading-indicators": "^1.0.0",
"react-router-dom": "^6.25.1",
"react-scripts": "5.0.1",
"styled-components": "^6.1.12",
"typescript": "^4.9.5",
"use-sound": "^4.0.3",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down Expand Up @@ -62,5 +66,6 @@
"electron": "^31.2.1",
"electron-builder": "^24.13.3",
"wait-on": "^7.2.0"
}
},
"packageManager": "[email protected]"
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>얼루가게 PC</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import Layout from './components/layout'
import Login from './pages/login'
import HistoryMain from './pages/history'
import WaitMain from './pages/waiting'
import Redirect from 'pages/oauth'

export default function App() {
return (
<Routes>
<Route path={ROUTE.LOGIN} element={<Login />} />
<Route path={ROUTE.OAUTH} element={<Redirect />} />
<Route element={<Layout />}>
<Route path={ROUTE.WAITING_MAIN} element={<WaitMain />} />
<Route path={ROUTE.PROCESS_MAIN} element={<ProcessMain />} />
Expand Down
18 changes: 18 additions & 0 deletions src/apis/login.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import api from './network'

interface PostLoginResponse {
token: string
}

export interface PostKakaoLoginBody {
code: string
state: string
redirectUri: string
}

async function postKakaoLogin(body: PostKakaoLoginBody): Promise<PostLoginResponse> {
const { data } = await api.post(`/api/login/kakao`, body)
return data
}

export { postKakaoLogin }
48 changes: 48 additions & 0 deletions src/apis/my.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import api from './network'

type RoleType = 'OWNER' | 'MANAGER' | 'STAFF'
type DayType = 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday' | 'Sunday'

interface AbstractMember {
id: string | null
name: string | null
phone: string | null
providerType: 'KAKAO' | null
storeList: Store[]
}

interface My extends AbstractMember {
relationList: Relation[]
}

interface Relation {
id: string
storeId: string
member: AbstractMember
planList: Plan[]
role: RoleType
position: string
}

interface Plan {
id: string
relationId: string
day: DayType
startTime: string
endTime: string
restStartTime: string
restEndTime: string
}

interface Store {
storeId: string
name: string
}

async function getMy(): Promise<My> {
const { data } = await api.get<My>(`/api/my`)
return data
}

export { getMy }
export type { My }
42 changes: 42 additions & 0 deletions src/apis/network.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import axios from 'axios'

const setTokenFromLocalStorage = (access_token: string) => {
localStorage.setItem('access_token', access_token)
}

const getTokenFromLocalStorage = () => {
const accessToken = localStorage.getItem('access_token')
if (!accessToken) return null

return accessToken
}

const eollugageUrl = process.env.REACT_APP_API_URL

const api = axios.create({
baseURL: eollugageUrl,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
Accept: 'application/json',
'Access-Control-Allow-Origin': 'http://localhost:3000',
'Access-Control-Allow-Credentials': 'true',
},
validateStatus: status => {
return status < 300
},
})
api.interceptors.request.use(
async config => {
if (typeof document !== 'undefined') {
const token = getTokenFromLocalStorage()
config.headers.set('Authorization', `Bearer ${token}`)
}
return config
},
error => {
return Promise.reject(error)
},
)

export default api
export { setTokenFromLocalStorage, getTokenFromLocalStorage }
46 changes: 46 additions & 0 deletions src/apis/paymentHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import api from './network'

export interface PaymentHistory {
paymentHistoryId: string
storeId: string
tableNumber: number
status: PaymentHistoryStatus
paidAt: null
totalPrice: number
orderHistoryResponseDtoList: OrderHistory[]
}

export interface OrderHistory {
orderHistoryId: string
paymentHistoryId: string
orderDetail: string
totalPrice: number
createdAt: string
updatedAt: string | null
status: OrderHistoryStatus
}

type PaymentHistoryStatus = 'WAITING' | 'PROCESS' | 'HISTORY'
type OrderHistoryStatus = 'APPROVED' | 'PENDING' | 'DISAPPROVED' | 'HISTORY'

async function getPaymentHistory(storeId: string, status?: string, filter: string = 'ALL'): Promise<PaymentHistory[]> {
const statusQuery = status ? `&status=${status}` : ''
const { data } = await api.get(`/api/v1/stores/${storeId}/payment-histories?filter=${filter}${statusQuery}`)
return data
}

async function patchPaymentHistory(
storeId: string,
paymentHistoryId: string,
orderHistoryId: string,
status: string,
): Promise<PaymentHistory[]> {
const body = { status }
const { data } = await api.patch(
`/api/v1/stores/${storeId}/payment-histories/${paymentHistoryId}/order-histories/${orderHistoryId}`,
body,
)
return data
}

export { getPaymentHistory, patchPaymentHistory }
Binary file added src/assets/sound/newOrder.mp3
Binary file not shown.
41 changes: 22 additions & 19 deletions src/components/historyDateFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,49 @@
import dayjs from 'dayjs'
import React, { SetStateAction, useState } from 'react'
import React, { SetStateAction } from 'react'
import styled from 'styled-components'

const buttonText = ['오늘', '1주', '1개월']
const buttonText = [
{ label: '오늘', value: 'TODAY' },
{ label: '1주', value: 'WEEK' },
{ label: '1개월', value: 'MONTH' },
]

interface HistoryDateFilterProps {
date: string
setDate: React.Dispatch<SetStateAction<string>>
filter: string
setFilter: React.Dispatch<SetStateAction<string>>
}

export default function HistoryDateFilter({ date, setDate }: HistoryDateFilterProps) {
const [selectedIdx, setSelectedIdx] = useState<number>(0)

const onClickDate = (index: number) => {
setSelectedIdx(index)
switch (index) {
case 0:
export default function HistoryDateFilter({ date, setDate, filter, setFilter }: HistoryDateFilterProps) {
const onClickDate = (value: string) => {
switch (value) {
case 'TODAY':
setDate(dayjs().format('YYYY.MM.DD'))
setFilter('TODAY')
break
case 1:
case 'WEEK':
setDate(dayjs().subtract(1, 'week').format('YYYY.MM.DD') + ' - ' + dayjs().format('YYYY.MM.DD'))
setFilter('WEEK')
break
case 2:
case 'MONTH':
setDate(dayjs().subtract(1, 'month').format('YYYY.MM.DD') + ' - ' + dayjs().format('YYYY.MM.DD'))
setFilter('MONTH')
break
default:
setDate('error')
setFilter('ALL')
}
}

const onClickDateInput = (event: React.ChangeEvent<HTMLInputElement>) => {
setDate(dayjs(event.target.value).format('YYYY.MM.DD'))
}

return (
<Container>
{buttonText.map((text, i) => (
<DateButton selected={i === selectedIdx} onClick={() => onClickDate(i)}>
{text}
{buttonText.map((button, i) => (
<DateButton selected={button.value === filter} onClick={() => onClickDate(button.value)}>
{button.label}
</DateButton>
))}
<DateInput type="date" value={dayjs(date).format('YYYY.MM.DD')} onChange={onClickDateInput} />
<DateInput type="date" value={dayjs().format('YYYY-MM-DD')} defaultValue={dayjs().format('YYYY-MM-DD')} />
</Container>
)
}
Expand Down
30 changes: 30 additions & 0 deletions src/components/kakaoButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import styled from 'styled-components'
import { createRandomString } from 'utils/createRandomId'

export default function KakaoButton() {
const redirectUri = `${window.location.origin}/oauth`
const onClickLogin = () => {
window.location.href = `https://kauth.kakao.com/oauth/authorize?redirect_uri=${redirectUri}&client_id=${
process.env.REACT_APP_KAKAO_REST_KEY
}&response_type=code&state=${createRandomString(8)}`
}

return (
<KakaoLoginButton onClick={onClickLogin}>
<img src={require('assets/image/kakao.png')} width={24} height={24} alt="kakao-login-button" />
카카오 로그인
</KakaoLoginButton>
)
}

const KakaoLoginButton = styled.div`
background-color: #fee500;
width: 328px;
border-radius: 1000px;
padding: 20px 0;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
cursor: pointer;
`
20 changes: 17 additions & 3 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,34 @@ import { Outlet, useNavigate } from 'react-router'
import styled from 'styled-components'
import NavBar from './navBar'
import { useAtom } from 'jotai'
import { currentTabAtom, historyCountAtom, processCountAtom, waitingCountAtom } from 'utils/atom'
import { currentTabAtom, modalDetailAtom, modalShowAtom, processCountAtom, waitingCountAtom } from 'utils/atom'
import { ROUTE } from 'constants/path'
import Modal from './modal'

export default function Layout() {
const navigate = useNavigate()
const [, setCurrentTab] = useAtom(currentTabAtom)
const [waitingCount] = useAtom(waitingCountAtom)
const [processCount] = useAtom(processCountAtom)
const [historyCount] = useAtom(historyCountAtom)
const [modalDetail] = useAtom(modalDetailAtom)
const [modalShow] = useAtom(modalShowAtom)

const navBarItem = [
{
name: '승인 대기',
count: waitingCount,
label: ROUTE.WAITING_MAIN,
onClick: () => onClickTab(ROUTE.WAITING_MAIN),
},
{
name: '진행 중',
count: processCount,
label: ROUTE.PROCESS_MAIN,
onClick: () => onClickTab(ROUTE.PROCESS_MAIN),
},
{
name: '히스토리',
count: historyCount,
label: ROUTE.HISTORY_MAIN,
onClick: () => onClickTab(ROUTE.HISTORY_MAIN),
},
]
Expand All @@ -37,6 +41,16 @@ export default function Layout() {

return (
<Container>
{modalShow && (
<Modal
title={modalDetail?.title}
description={modalDetail?.description}
grayButtonText={modalDetail?.grayButtonText}
blackButtonText={modalDetail?.blackButtonText}
onClickGrayButton={modalDetail?.onClickGrayButton}
onClickBlackButton={modalDetail?.onClickBlackButton}
/>
)}
<NavWrapper>
<NavBar items={navBarItem} />
</NavWrapper>
Expand Down
Loading