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/#481] useToastHandler 훅 추가, 토스트 전부 상단으로 위치 (+ alert 제거), 핑크색으로 글자 칠해지도록 기능 구현 #482

Merged
merged 6 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -25,7 +25,7 @@ const PhoneNumber = ({ phone }: PhoneNumProps) => {
<S.Copy />
</S.PhoneNumLayout>
</S.PhoneNumWrapper>
<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={30}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
</>
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import useHeader from "./useHeader.ts";
import useLogin from "./useLogin.ts";
import useModal from "./useModal.ts";
import useToast from "./useToast.ts";
import useToastHandler from "./useToastHandler.ts";

export { useHamburger, useHeader, useLogin, useModal, useToast };
export { useHamburger, useHeader, useLogin, useModal, useToast, useToastHandler };
32 changes: 32 additions & 0 deletions src/hooks/useToastHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { useToast } from "@hooks";
import { useState } from "react";

interface ToastConfigProps {
message: string;
isTop: boolean;
}

//top & bottom, 혹은 메세지를 변경해야하는 경우 사용해야하는 훅
const useToastHandler = () => {
const { showToast, isToastVisible } = useToast();
const [toastConfig, setToastConfig] = useState<ToastConfigProps>({
message: "클립보드에 복사되었습니다!",
isTop: true,
});

//토스트 메세지, 위치를 정하는 유틸 함수
const handleToastVisible = (message: string, position: "top" | "bottom") => {
const isTop = position === "top" ? true : false;
setToastConfig({ message, isTop });
showToast();
};

/*
toastConfig: Toast 속성에 사용,
isToastVisible : Toast의 isVisible 속성에 사용
handleToastVisible : Toast를 사용하기 위한 함수
*/
return { toastConfig, isToastVisible, handleToastVisible };
};

export default useToastHandler;
2 changes: 1 addition & 1 deletion src/pages/book/components/paidBook/PaidBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const PaidBook = ({
</S.FloatingWrapper>
</S.Wrapper>
<S.DepositBox>
<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={52}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
</S.DepositBox>
Expand Down
1 change: 0 additions & 1 deletion src/pages/cancel/Cancel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const Cancel = () => {
};

confirmCancelAction(requestData);
alert("hi");
};

if (!state) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/gig/components/performanceIntroduce/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Contact = ({ contact }: ContactProps) => {
<S.IconCopy $width={24} $height={24} />
</S.Contact>
)}
<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={100}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
</S.ContactContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const PerformanceIntroduce = ({
<Contact contact={contact} />

<div style={{ width: "100%", display: "flex", justifyContent: "center" }}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={30}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/test/TestPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const TestPage = () => {
<Button size="medium" variant="primary" onClick={showToast}>
토스트 보이기
</Button>
<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={30}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
<Spacing marginBottom="3" />
Expand Down
2 changes: 1 addition & 1 deletion src/pages/test/modalTest/BankAccount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const BankAccount = ({ bankName, number, accountName, accountNumber, price }: Ba
</Button>
</BtnWrapper>

<Toast icon={<IconCheck />} isVisible={isToastVisible} toastBottom={30}>
<Toast icon={<IconCheck />} isVisible={isToastVisible} isTop={true}>
클립보드에 복사되었습니다!
</Toast>
</Wrapper>
Expand Down
18 changes: 3 additions & 15 deletions src/pages/ticketholderlist/TicketHolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import SelectedChips from "./components/selectedChips/SelectedChips";
import { convertingBookingStatus } from "@constants/convertingBookingStatus";
import { IconCheck } from "@assets/svgs";
import Toast from "@components/commons/toast/Toast";
import { useToast } from "@hooks";
import NonExistent from "./components/nonExistent/NonExistent.";
import { getUA, isChrome } from "react-device-detect";
import { useToastHandler } from "@hooks";

export type PaymentType =
| "CHECKING_PAYMENT"
Expand Down Expand Up @@ -66,10 +66,7 @@ const headers = [
];

const TicketHolderList = () => {
const [toastConfig, setToastConfig] = useState<ToastConfigProps>({
message: "클립보드에 복사되었습니다!",
isTop: false,
});
const { toastConfig, isToastVisible, handleToastVisible } = useToastHandler();
const [paymentData, setPaymentData] = useState<BookingListProps[]>();
const [allBookings, setAllBookings] = useState<BookingListProps[]>([]); // 전체 예매자 정보 (필터 적용 안 된)

Expand Down Expand Up @@ -102,9 +99,7 @@ const TicketHolderList = () => {
filterList
);
const { openConfirm, closeConfirm } = useModal();

const [checkedBookingId, setCheckedBookingId] = useState<number[]>([]);
const { showToast, isToastVisible } = useToast();
// 체크된 리스트 확인
const handleBookingIdCheck = (bookingId: number) => {
setCheckedBookingId((prev) =>
Expand All @@ -114,13 +109,6 @@ const TicketHolderList = () => {

const { mutate: updateMutate, isPending: updateIsPending } = useTicketUpdate();

//토스트 메세지, 위치를 정하는 유틸 함수
const handleToastVisible = (message: string, position: "top" | "bottom") => {
const isTop = position === "top" ? true : false;
setToastConfig({ message, isTop });
showToast();
};

const handlePaymentFixAxiosFunc = () => {
if (updateIsPending) {
return;
Expand Down Expand Up @@ -477,7 +465,7 @@ const TicketHolderList = () => {

const handleCopyClipBoard = (text: string) => {
navigator.clipboard.writeText(text);
handleToastVisible("클립보드에 복사되었습니다!", "bottom");
handleToastVisible("클립보드에 복사되었습니다!", "top");
};

return (
Expand Down
Loading