|
|
@@ -0,0 +1,89 @@
|
|
|
+import React, { useEffect, useState } from 'react';
|
|
|
+import {Link} from "react-router-dom";
|
|
|
+
|
|
|
+interface PopupModalProps {
|
|
|
+ imageSrc: string;
|
|
|
+ button1Text: string;
|
|
|
+ button1Link: string;
|
|
|
+ button2Text: string;
|
|
|
+ button2Link: string;
|
|
|
+ popupKey: string;
|
|
|
+ offsetRightPx?: number;
|
|
|
+}
|
|
|
+
|
|
|
+const PopupModal: React.FC<PopupModalProps> = ({
|
|
|
+ imageSrc,
|
|
|
+ button1Text,
|
|
|
+ button1Link,
|
|
|
+ button2Text,
|
|
|
+ button2Link,
|
|
|
+ popupKey,
|
|
|
+ offsetRightPx = 24,
|
|
|
+ }) => {
|
|
|
+ const [visible, setVisible] = useState(false);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const hiddenUntil = localStorage.getItem(popupKey);
|
|
|
+ if (!hiddenUntil || Date.now() > Number(hiddenUntil)) {
|
|
|
+ setVisible(true);
|
|
|
+ }
|
|
|
+ }, []);
|
|
|
+
|
|
|
+ const handleClose = () => setVisible(false);
|
|
|
+
|
|
|
+ const handleCloseFor24Hours = () => {
|
|
|
+ const later = Date.now() + 24 * 60 * 60 * 1000;
|
|
|
+ localStorage.setItem(popupKey, later.toString());
|
|
|
+ setVisible(false);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (!visible) return null;
|
|
|
+
|
|
|
+ return (
|
|
|
+ <div
|
|
|
+ className="fixed bottom-6 z-50 bg-white shadow-2xl rounded-lg p-4 text-center w-[400px] md:w-[480px]"
|
|
|
+ style={{ right: `${offsetRightPx}px` }}
|
|
|
+ >
|
|
|
+ {/* 닫기 버튼 */}
|
|
|
+ <button
|
|
|
+ onClick={handleClose}
|
|
|
+ className="absolute top-2 right-2 text-gray-500 hover:text-gray-700 text-xl cursor-pointer"
|
|
|
+ >
|
|
|
+ ×
|
|
|
+ </button>
|
|
|
+
|
|
|
+ {/* 이미지 */}
|
|
|
+ <img
|
|
|
+ src={imageSrc}
|
|
|
+ alt="popup"
|
|
|
+ className="w-full h-auto min-h-[200px] rounded mb-4 object-contain"
|
|
|
+ />
|
|
|
+
|
|
|
+ {/* 버튼 영역 */}
|
|
|
+ <div className="flex gap-2 mb-4">
|
|
|
+ <Link
|
|
|
+ to={button1Link}
|
|
|
+ className="flex-1 bg-blue-600 text-white px-3 py-2 rounded text-sm hover:bg-blue-700"
|
|
|
+ >
|
|
|
+ {button1Text}
|
|
|
+ </Link>
|
|
|
+ <Link
|
|
|
+ to={button2Link}
|
|
|
+ className="flex-1 bg-green-600 text-white px-3 py-2 rounded text-sm hover:bg-green-700"
|
|
|
+ >
|
|
|
+ {button2Text}
|
|
|
+ </Link>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ {/* 24시간 숨기기 */}
|
|
|
+ {/*<button*/}
|
|
|
+ {/* onClick={handleCloseFor24Hours}*/}
|
|
|
+ {/* className="text-xs text-gray-500 hover:underline cursor-pointer"*/}
|
|
|
+ {/*>*/}
|
|
|
+ {/* 24시간 동안 다시 열람하지 않습니다.*/}
|
|
|
+ {/*</button>*/}
|
|
|
+ </div>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+export default PopupModal;
|