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

[선물방 메인] 삭제 모달 공통 컴포넌트로 분리, 플로팅 버튼 기능 추가 #445

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ const GiftAddPageLayout = ({ targetDate, roomId, setStep, setItemNum }: GiftAddP
setStep(1);
};

const handleClickConfirmDeleteBtn = (giftId: number) => {
mutation.mutate(giftId);
const handleClickConfirmDeleteBtn = (giftId?: number) => {
if (giftId !== undefined) {
mutation.mutate(giftId);
}
Comment on lines +47 to +50
Copy link
Member

Choose a reason for hiding this comment

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

if 문으로 mutation을 넣었군요! 저도 이렇게 모달을 열어보겠습니다!

setIsModalOpen(false);
};

return (
<S.GiftAddPageWrapper>
{isModalOpen && (
<DeleteModal
onClickCancel={() => setIsModalOpen(false)}
setIsModalOpen={setIsModalOpen}
onClickDelete={handleClickConfirmDeleteBtn}
clickedItem={clickedItem}
>
Expand Down
8 changes: 4 additions & 4 deletions src/components/GiftHome/GiftHomeSummary/GiftHomeSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import * as S from './GiftHomeSummary.styled';

interface GiftHomeSummaryProps {
data: RoomInfoType;
isBtn: boolean;
}

export const GiftHomeSummary = ({ data }: GiftHomeSummaryProps) => {
export const GiftHomeSummary = ({ data, isBtn }: GiftHomeSummaryProps) => {
const baseURL = import.meta.env.VITE_APP_BASE_URL_KAKAO;
const { handleCopyToClipboard } = useClipboard();
console.log('isBtn', isBtn);
const { handleCopyToClipboard } = useClipboard(isBtn);

return (
<S.GiftHomeSummaryWrapper>
Expand All @@ -28,8 +30,6 @@ export const GiftHomeSummary = ({ data }: GiftHomeSummaryProps) => {
<S.Body09Text>선물 토너먼트까지</S.Body09Text>

<CountDownTimer targetDate={new Date(data.tournamentStartDate)} giftee={data.gifteeName} />


</S.GiftHomeSummaryWrapper>
);
};
Expand Down
17 changes: 13 additions & 4 deletions src/components/common/Modal/DeleteModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ import { IcCancel } from '../../../assets/svg';

interface DeleteModalProps {
children: React.ReactNode;
onClickDelete: (giftId: number) => void;
onClickCancel: () => void;
clickedItem: number | undefined;
onClickDelete: (giftId?: number) => void;
setIsModalOpen: React.Dispatch<React.SetStateAction<boolean>>;
clickedItem?: number | undefined;
}

const DeleteModal = ({ children, onClickDelete, onClickCancel, clickedItem }: DeleteModalProps) => {
const DeleteModal = ({
children,
onClickDelete,
setIsModalOpen,
clickedItem,
}: DeleteModalProps) => {
const onClickCancel = () => {
setIsModalOpen(false);
};

return (
<>
<S.Overlay />
Expand Down
43 changes: 24 additions & 19 deletions src/hooks/useCopyClip.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
import { useCallback } from 'react';
import { toast } from 'react-toastify';

const useClipboard = () => {
const handleCopyToClipboard = useCallback(async (text: string) => {
try {
await navigator.clipboard.writeText(text);
toast.info('링크 복사가 완료되었어요', {
position: 'bottom-center',
autoClose: 700,
hideProgressBar: true,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: 'colored',
icon: false,
});
} catch (err) {
console.log(err);
}
}, []);
const useClipboard = (isBtn?: boolean) => {
console.log('FINAL isBTN', isBtn);
const handleCopyToClipboard = useCallback(
async (text: string) => {
try {
await navigator.clipboard.writeText(text);
toast.info('링크 복사가 완료되었어요', {
position: 'bottom-center',
autoClose: 700,
hideProgressBar: true,
closeOnClick: false,
pauseOnHover: false,
draggable: false,
progress: undefined,
theme: 'colored',
icon: false,
className: isBtn ? 'custom-toast-margin' : '',
});
} catch (err) {
console.log(err);
}
},
[isBtn],
);

return { handleCopyToClipboard };
};
Expand Down
39 changes: 26 additions & 13 deletions src/pages/GiftHome/GiftHome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BtnFill from '../../components/common/Button/Cta/fill/BtnFill';
import * as S from './GiftHome.styled';
import useGetRoomInfo from '../../hooks/queries/room/useGetRoomInfo';
import GiftHomeMyGifts from './GiftHomeMyGifts/GiftHomeMyGifts';
import { useEffect, useState } from 'react';

export default function GiftHome() {
const params = useParams();
Expand All @@ -14,15 +15,23 @@ export default function GiftHome() {

const { data } = useGetRoomInfo({ roomId: Number(roomId) });
const tournamentStartTime = data?.data.tournamentStartDate;
const myItemsNum = data?.data.roomMyGiftDtoList.length;

const [isBtn, setIsBtn] = useState(myItemsNum < 2);

useEffect(() => {
console.log('myItemsNum', myItemsNum);
setIsBtn(myItemsNum < 2);
}, [myItemsNum]);

const handleClickBtn = () => {
navigate(`/add-gift/${roomId}/${tournamentStartTime}`);
};

return (
<S.GiftHomeWrapper>
<GiftHomeSummary data={data?.data} />
{data?.data.roomMyGiftDtoList.length > 0 ? (
<GiftHomeSummary data={data?.data} isBtn={isBtn} />
{myItemsNum > 0 ? (
<GiftHomeMyGifts
roomId={Number(roomId)}
data={data.data.roomMyGiftDtoList}
Expand All @@ -42,17 +51,21 @@ export default function GiftHome() {
targetDate={data.data.tournamentStartDate}
data={data.data.hotProductGiftDtoList}
/>
<BtnFill
children={'선물 등록하기'}
onClick={handleClickBtn}
customStyle={{
position: 'fixed',
bottom: '0',
marginBottom: '2rem',
width: '33.5rem',
padding: '1.5rem 8.1rem 1.6rem 8.1rem',
}}
/>
{myItemsNum < 2 ? (
<BtnFill
children={'선물 등록하기'}
onClick={handleClickBtn}
customStyle={{
position: 'fixed',
bottom: '0',
marginBottom: '2rem',
width: '33.5rem',
padding: '1.5rem 8.1rem 1.6rem 8.1rem',
}}
/>
) : (
<></>
)}
</S.GiftHomeWrapper>
);
}
4 changes: 4 additions & 0 deletions src/style/GlobalStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ body {
#root::-webkit-scrollbar {
display: none; /* 크롬, 사파리, 오페라, 엣지 스크롤바 숨김 */
}

.custom-toast-margin{
margin-bottom: 6.4rem;
}
`;

export default GlobalStyle;