Skip to content

Commit

Permalink
feat: 플로팅 버튼에 따라 토스트 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
urjimyu committed Feb 29, 2024
1 parent 213df48 commit e2761d8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 36 deletions.
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
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;

0 comments on commit e2761d8

Please sign in to comment.