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

[#69] 쿠폰 수정 & 삭제 API , 쿠폰 배너 API 구현 #79

Merged
merged 23 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9f745a4
feat: 쿠폰 수정, 삭제, 토글 useMutation 작성
jinjoo-jung Jan 20, 2024
3667817
feat: useMuation 추가
jinjoo-jung Jan 21, 2024
0f45c6b
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
jinjoo-jung Jan 21, 2024
239c7dd
feat: 쿠폰 api 작성
jinjoo-jung Jan 21, 2024
787a402
feat: 검색 쿼리키로 관리하도록 구현
jinjoo-jung Jan 21, 2024
1a53114
design: 쿠폰 등록하기 버튼 디자인 수정
jinjoo-jung Jan 21, 2024
a715791
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
jinjoo-jung Jan 22, 2024
5713e0d
modify: 코드 수정
jinjoo-jung Jan 22, 2024
7854967
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
jinjoo-jung Jan 22, 2024
d73f371
feat: 배너 지역 & top3 api 연결
jinjoo-jung Jan 22, 2024
aa61a45
design: banner 디자인 수정
jinjoo-jung Jan 22, 2024
10e1ca5
feat: 대기 쿠폰에서 수정, 삭제 클릭시 모달 생성 구현
jinjoo-jung Jan 22, 2024
d36d0e9
feat: 만료 쿠폰 삭제 모달 생성 구현
jinjoo-jung Jan 22, 2024
187902d
design: 모달 버튼 호버시 색상 적용
jinjoo-jung Jan 22, 2024
08765f4
feat: 숙소 조건 값 함수 lib로 분리
jinjoo-jung Jan 22, 2024
7cede1c
feat: 쿠폰 삭제 api 연결
jinjoo-jung Jan 22, 2024
cf1ccd6
feat: 쿠폰 수정 버튼 클릭시 쿼리스트링으로 쿠폰번호 보내도록 구현
jinjoo-jung Jan 22, 2024
18e84d6
feat: 쿠폰 수정 api 연결
jinjoo-jung Jan 22, 2024
eec7a81
modify: 빌드 오류 수정
jinjoo-jung Jan 22, 2024
03bdf93
feat: 최근 등록일 기준 나열 (임시)
jinjoo-jung Jan 22, 2024
c871968
fix: 토글 on/off 버그 수정
jinjoo-jung Jan 22, 2024
4037b54
Merge branch 'dev' of https://github.com/CoolPeace-yanolza/frontend i…
jinjoo-jung Jan 23, 2024
e077fed
modify: 배너 api 주석 처리 (임시)
jinjoo-jung Jan 23, 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
7 changes: 6 additions & 1 deletion src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
export { default as instance } from './lib/instance';
export { default as postLogin } from './lib/postLogin';
export { default as postRefreshToken } from './lib/postRefreshToken';
export {
getCouponList,
couponUpdateApi,
couponDeleteApi,
couponToggleApi
} from './lib/getCouponList';
export { default as getTotalReport } from './lib/getTotalReport';
export { default as getYearReport } from './lib/getYearReport';
export { default as getCouponList } from './lib/getCouponList';
export { default as getHeaderAccommodation } from './lib/getHeaderAccommodation';
export { default as getMonthReports } from './lib/getMonthReports';
export { default as getDailyReport } from './lib/getDailyReport';
Expand Down
38 changes: 35 additions & 3 deletions src/api/lib/getCouponList.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { CouponListResponse } from '@/types/couponList';
import {
CouponDeleteCredential,
CouponListResponse,
CouponToggleCredential,
CouponUpdateCredential
} from '@/types/couponList';
import { instance } from '..';

// 쿠폰 정보 가져오는 api
const getCouponList = async (
export const getCouponList = async (
accommodationId: number,
date?: string,
status?: string,
Expand All @@ -22,4 +27,31 @@ const getCouponList = async (
return response.data;
};

export default getCouponList;
// 쿠폰 수정 api
export const couponUpdateApi = async (credential: CouponUpdateCredential) => {
const couponNumber = credential.coupon_number;
const response = await instance.put(
`/v1/coupons/${couponNumber}`,
credential
);
return response.data;
};

// 쿠폰 삭제 api
export const couponDeleteApi = async (
credential: CouponDeleteCredential
): Promise<void> => {
const couponNumber = credential.coupon_number;
const response = await instance.delete(`/v1/coupons/${couponNumber}`);
return response.data;
};

// 토클 on/off api
export const couponToggleApi = async (credential: CouponToggleCredential) => {
const couponNumber = credential.coupon_number;
const response = await instance.put(
`/v1/coupons/${couponNumber}/expose`,
credential
);
return response.data;
};
17 changes: 16 additions & 1 deletion src/components/CouponList/CouponBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import styled from '@emotion/styled';
import theme from '@styles/theme';

import bannerIcon from '@assets/icons/ic-couponlist-speaker.svg';
import { useRecoilValue } from 'recoil';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { useRecoilValue } from 'recoil';

위 import는 상단으로 위치 이동해주시면 좋을 것같습니다!

import { headerAccommodationState } from '@recoil/index';
// import { useGetCouponRanking } from '@hooks/queries/useGetCouponRanking';

const CouponBanner = () => {
const headerAccommodation = useRecoilValue(headerAccommodationState);
const sigunguData = headerAccommodation.sigungu;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 API없이 잘되었네요 👍..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요 다행입니다 ㅎㅎ

// const { data } = useGetCouponRanking(headerAccommodation.id);

return (
<BannerContainer>
<TabBanner>
Expand All @@ -14,7 +21,8 @@ const CouponBanner = () => {
<div>
<TabBannerTitle>이번 달 우리 지역 인기 쿠폰</TabBannerTitle>
<TabBannerContent>
OO구에서 가장 많이 사용된 쿠폰은? 재방문 고객 20% 할인쿠폰 이에요!
{sigunguData}에서 가장 많이 사용된 쿠폰은?
{/* <span>{data.first_coupon_title}쿠폰</span>이에요! */}
</TabBannerContent>
</div>
</TabBanner>
Expand Down Expand Up @@ -46,9 +54,16 @@ const TabBanner = styled.div`
const TabBannerTitle = styled.div`
font-size: 12px;
font-style: normal;
font-weight: 500;
margin-bottom: 6px;
`;
const TabBannerContent = styled.div`
font-size: 17px;
font-style: normal;
font-weight: 500;

span {
margin: 0px 5px;
border-bottom: 1px solid;
}
`;
6 changes: 5 additions & 1 deletion src/components/CouponList/CouponHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ const CouponRegisterButton = styled.div`

font-size: 17px;
color: ${theme.colors.white};
background: #ff3478;
background: linear-gradient(91deg, #ff3478 1.39%, #ff83ad 98.63%);
cursor: pointer;

&:hover {
background: #b22655;
}
`;
44 changes: 40 additions & 4 deletions src/components/CouponList/CouponItem/CouponExpired/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,37 @@ import { useRef, useState } from 'react';
import theme from '@styles/theme';
import rightIcon from '@assets/icons/ic-couponlist-right.svg';
import deleteIcon from '@assets/icons/ic-couponlist-delete.svg';
import { useOutsideClick } from '@hooks/index';
import { useCouponDelete, useOutsideClick } from '@hooks/index';
import { CouponListProps } from '@/types/couponList';
import Modal from '@components/modal';
import CouponCondition from '@utils/lib/couponCondition';

const CouponExpired = ({ couponInfo }: CouponListProps) => {
const [isShowRoomList, setIsShowRoomList] = useState(false);
const roomListRef = useRef<HTMLDivElement>(null);
const [isShowModal, setIsShowModal] = useState(false);
const { mutateAsync } = useCouponDelete();

useOutsideClick(roomListRef, () => setIsShowRoomList(false));

const handleRoomList = () => {
setIsShowRoomList(!isShowRoomList);
};

useOutsideClick(roomListRef, () => setIsShowRoomList(false));
const handleDeleteClick = () => {
setIsShowModal(true);
};

// 모달 확인 버튼에 대한 동작
const handleModalConfirm = () => {
mutateAsync({ coupon_number: couponInfo.coupon_number });
setIsShowModal(false);
};

// 모달 취소 버튼에 대한 동작
const handleModalClose = () => {
setIsShowModal(false);
};

return (
<CouponContainer>
Expand Down Expand Up @@ -44,7 +63,12 @@ const CouponExpired = ({ couponInfo }: CouponListProps) => {
</ContentWrap>
<ContentWrap>
<ContentTitle>일정</ContentTitle>
<ContentValue>{couponInfo.coupon_room_type}</ContentValue>
<ContentValue>
{couponInfo.coupon_room_type},
<span>
{CouponCondition(couponInfo.coupon_use_condition_days)}
</span>
</ContentValue>
</ContentWrap>
<ContentWrap>
<ContentTitle>객실</ContentTitle>
Expand Down Expand Up @@ -95,7 +119,15 @@ const CouponExpired = ({ couponInfo }: CouponListProps) => {
<RegisterDateValue>{couponInfo.created_date}</RegisterDateValue>
</ExposeDateWrap>
</DateContainer>
<Delete>삭제</Delete>
<Delete onClick={handleDeleteClick}>삭제</Delete>
{isShowModal && (
<Modal
modalText={`"${couponInfo.title}"을 삭제하시겠습니까?`}
subText={true}
onConfirmClick={handleModalConfirm}
onCloseClick={handleModalClose}
/>
)}
</CouponContainer>
);
};
Expand Down Expand Up @@ -217,6 +249,10 @@ const ContentValue = styled.div`
font-size: 11px;
font-style: normal;
font-weight: 400;

span {
margin-left: 3px;
}
`;

const DateContainer = styled.div`
Expand Down
23 changes: 21 additions & 2 deletions src/components/CouponList/CouponItem/CouponExpose/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,25 @@ import toggleOffIcon from '@assets/icons/ic-couponlist-toggleOff.svg';
import rightIcon from '@assets/icons/ic-couponlist-right.svg';
import deleteIcon from '@assets/icons/ic-couponlist-delete.svg';
import { CouponListProps, ToggleStyleProps } from '@/types/couponList';
import { useOutsideClick } from '@hooks/index';
import { useOutsideClick, useToggleChange } from '@hooks/index';
import { CouponCondition } from '@utils/lib/couponCondition';

const CouponExpose = ({ couponInfo }: CouponListProps) => {
const [isToggle, setIsToggle] = useState(true);
const [isShowRoomList, setIsShowRoomList] = useState(false);
const roomListRef = useRef<HTMLDivElement>(null);
const { mutateAsync } = useToggleChange();

const handleToggle = () => {
setIsToggle(!isToggle);
toggleUpdate();
};

const toggleUpdate = async () => {
await mutateAsync({
coupon_number: couponInfo.coupon_number,
coupon_status: '노출 OFF'
});
};

const handleRoomList = () => {
Expand Down Expand Up @@ -72,7 +82,12 @@ const CouponExpose = ({ couponInfo }: CouponListProps) => {
</ContentWrap>
<ContentWrap>
<ContentTitle>일정</ContentTitle>
<ContentValue>{couponInfo.coupon_room_type}</ContentValue>
<ContentValue>
{couponInfo.coupon_room_type},
<span>
{CouponCondition(couponInfo.coupon_use_condition_days)}
</span>
</ContentValue>
</ContentWrap>
<ContentWrap>
<ContentTitle>객실</ContentTitle>
Expand Down Expand Up @@ -363,6 +378,10 @@ const ContentValue = styled.div`
font-size: 11px;
font-style: normal;
font-weight: 400;

span {
margin-left: 3px;
}
`;

const DateContainer = styled.div`
Expand Down
20 changes: 17 additions & 3 deletions src/components/CouponList/CouponItem/CouponStop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import toggleOffIcon from '@assets/icons/ic-couponlist-toggleOff.svg';
import rightIcon from '@assets/icons/ic-couponlist-right.svg';
import deleteIcon from '@assets/icons/ic-couponlist-delete.svg';
import { CouponListProps, ToggleStyleProps } from '@/types/couponList';
import { useOutsideClick } from '@hooks/index';
import { useOutsideClick, useToggleChange } from '@hooks/index';
import CouponCondition from '@utils/lib/couponCondition';

const CouponStop = ({ couponInfo }: CouponListProps) => {
const [isToggle, setIsToggle] = useState(false);
const [isShowRoomList, setIsShowRoomList] = useState(false);
const roomListRef = useRef<HTMLDivElement>(null);

const { mutateAsync } = useToggleChange();
useOutsideClick(roomListRef, () => setIsShowRoomList(false));

const handleRoomList = () => {
Expand All @@ -22,6 +23,10 @@ const CouponStop = ({ couponInfo }: CouponListProps) => {

const handleToggle = () => {
setIsToggle(!isToggle);
mutateAsync({
coupon_number: couponInfo.coupon_number,
coupon_status: '노출 ON'
});
};

return (
Expand Down Expand Up @@ -72,7 +77,12 @@ const CouponStop = ({ couponInfo }: CouponListProps) => {
</ContentWrap>
<ContentWrap>
<ContentTitle>일정</ContentTitle>
<ContentValue>{couponInfo.coupon_room_type}</ContentValue>
<ContentValue>
{couponInfo.coupon_room_type},
<span>
{CouponCondition(couponInfo.coupon_use_condition_days)}
</span>
</ContentValue>
</ContentWrap>
<ContentWrap>
<ContentTitle>객실</ContentTitle>
Expand Down Expand Up @@ -269,6 +279,10 @@ const ContentValue = styled.div`
font-size: 11px;
font-style: normal;
font-weight: 400;

span {
margin-left: 3px;
}
`;

const DateContainer = styled.div`
Expand Down
Loading