Skip to content

Commit

Permalink
chore: 모달 닫기 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
kingyong9169 committed Aug 3, 2024
1 parent 6a0f88e commit a80ff42
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
15 changes: 4 additions & 11 deletions apps/web/src/components/app-download-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { useRouter } from "next/navigation";
import { createPortal } from "react-dom";
import { RemoveScroll } from "react-remove-scroll";
import { create } from "zustand";
import { AOS_APP_LINK } from "~/constants";
import { detectDevice } from "~/libs/detect-device";
import { modalCloseEvent } from "~/libs/clarity";
import {
ModalStatusStore,
getModalStatusStore,
} from "~/libs/store/modal-status";
import { onAppDownloadClick } from "~/libs/utils";
import { cn } from "~/libs/utils";

export const useAppDownloadModalStore =
Expand All @@ -21,19 +21,12 @@ export default function AppDownloadModal() {

const onClickDownloadApp = () => {
close();
// TODO: 앱이 있으면 앱 열기, 없으면 playstore로 이동
const device = detectDevice();
if (device === "android") window.open(AOS_APP_LINK);
else if (device !== null) router.push("/ios-not-supported");
if (device !== null) window.clarity?.("event", `install-modal-${device}`);
onAppDownloadClick(router.push);
};

const onClickClose = (isButtonClick: boolean) => {
close();
window.clarity?.(
"event",
isButtonClick ? "install-modal-close-button" : "install-modal-dim-close",
);
modalCloseEvent(isButtonClick);
};

if (status === "unmounted") {
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/libs/clarity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const modalCloseEvent = (isButtonClick: boolean) => {
window.clarity?.(
"event",
isButtonClick ? "install-modal-close-button" : "install-modal-dim-close",
);
};
10 changes: 10 additions & 0 deletions apps/web/src/libs/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { AOS_APP_LINK } from "~/constants";
import { detectDevice } from "./detect-device";

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
Expand All @@ -23,3 +25,11 @@ export function getAspectRatio(str: string) {
const [w, h] = getAspectRatioArray(str);
return w / h;
}

export const onAppDownloadClick = (navigate: (route: string) => void) => {
// TODO: 앱이 있으면 앱 열기, 없으면 playstore로 이동
const device = detectDevice();
if (device === "android") window.open(AOS_APP_LINK);
else if (device !== null) navigate("/ios-not-supported");
if (device !== null) window.clarity?.("event", `install-modal-${device}`);
};

0 comments on commit a80ff42

Please sign in to comment.