Skip to content
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
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Outlet } from "react-router-dom";

import { useChannelTalk } from "@/hooks/common/useChannelTalk";
import useHotjar from "@/hooks/common/useHotjar";

const App = () => {
useHotjar();
useChannelTalk();

return (
<main>
Expand Down
41 changes: 0 additions & 41 deletions src/assets/svg/ic-logo.svg

This file was deleted.

1 change: 1 addition & 0 deletions src/assets/svg/ic-share.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
251 changes: 251 additions & 0 deletions src/components/ChannelTalk/channelTalk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/* eslint-disable prefer-rest-params */
/* eslint-disable @typescript-eslint/no-explicit-any */
declare global {
interface Window {
ChannelIO?: IChannelIO;

ChannelIOInitialized?: boolean;
}
}

interface IChannelIO {
c?: (...args: any) => void;

q?: [methodName: string, ...args: any[]][];

(...args: any): void;
}

interface BootOption {
appearance?: string;

customLauncherSelector?: string;

hideChannelButtonOnBoot?: boolean;

hidePopup?: boolean;

language?: string;

memberHash?: string;

memberId?: string;

pluginKey: string;

profile?: Profile;

trackDefaultEvent?: boolean;

trackUtmSource?: boolean;

unsubscribe?: boolean;

unsubscribeEmail?: boolean;

unsubscribeTexting?: boolean;

zIndex?: number;
}

interface Callback {
(error: Error | null, user: CallbackUser | null): void;
}

interface CallbackUser {
alert: number;

avatarUrl: string;

id: string;

language: string;

memberId: string;

name?: string;

profile?: Profile | null;

tags?: string[] | null;

unsubscribeEmail: boolean;

unsubscribeTexting: boolean;
}

interface UpdateUserInfo {
language?: string;

profile?: Profile | null;

profileOnce?: Profile;

tags?: string[] | null;

unsubscribeEmail?: boolean;

unsubscribeTexting?: boolean;
}

interface Profile {
[key: string]: string | number | boolean | null | undefined;
}

interface FollowUpProfile {
name?: string | null;

mobileNumber?: string | null;

email?: string | null;
}

interface EventProperty {
[key: string]: string | number | boolean | null | undefined;
}

type Appearance = "light" | "dark" | "system" | null;

class ChannelService {
loadScript() {
(function () {
const w = window;

if (w.ChannelIO || w.ChannelIOInitialized) {
return;
}

if (w.ChannelIO) {
return w.console.error("ChannelIO script included twice.");
}

const ch: IChannelIO = function () {
ch.c?.(arguments);
};

ch.q = [];

ch.c = function (args) {
ch.q?.push(args);
};

w.ChannelIO = ch;

function l() {
if (w.ChannelIOInitialized) {
return;
}

w.ChannelIOInitialized = true;

const s = document.createElement("script");

s.type = "text/javascript";

s.async = true;

s.src = "https://cdn.channel.io/plugin/ch-plugin-web.js";

const x = document.getElementsByTagName("script")[0];

if (x.parentNode) {
x.parentNode.insertBefore(s, x);
}
}

if (document.readyState === "complete") {
l();
} else {
w.addEventListener("DOMContentLoaded", l);

w.addEventListener("load", l);
}
})();
}

boot(option: BootOption, callback?: Callback) {
window.ChannelIO?.("boot", option, callback);
}

shutdown() {
window.ChannelIO?.("shutdown");
}

showMessenger() {
window.ChannelIO?.("showMessenger");
}

hideMessenger() {
window.ChannelIO?.("hideMessenger");
}

openChat(chatId?: string | number, message?: string) {
window.ChannelIO?.("openChat", chatId, message);
}

track(eventName: string, eventProperty?: EventProperty) {
window.ChannelIO?.("track", eventName, eventProperty);
}

onShowMessenger(callback: () => void) {
window.ChannelIO?.("onShowMessenger", callback);
}

onHideMessenger(callback: () => void) {
window.ChannelIO?.("onHideMessenger", callback);
}

onBadgeChanged(callback: (unread: number, alert: number) => void) {
window.ChannelIO?.("onBadgeChanged", callback);
}

onChatCreated(callback: () => void) {
window.ChannelIO?.("onChatCreated", callback);
}

onFollowUpChanged(callback: (profile: FollowUpProfile) => void) {
window.ChannelIO?.("onFollowUpChanged", callback);
}

onUrlClicked(callback: (url: string) => void) {
window.ChannelIO?.("onUrlClicked", callback);
}

clearCallbacks() {
window.ChannelIO?.("clearCallbacks");
}

updateUser(userInfo: UpdateUserInfo, callback?: Callback) {
window.ChannelIO?.("updateUser", userInfo, callback);
}

addTags(tags: string[], callback?: Callback) {
window.ChannelIO?.("addTags", tags, callback);
}

removeTags(tags: string[], callback?: Callback) {
window.ChannelIO?.("removeTags", tags, callback);
}

setPage(page: string) {
window.ChannelIO?.("setPage", page);
}

resetPage() {
window.ChannelIO?.("resetPage");
}

showChannelButton() {
window.ChannelIO?.("showChannelButton");
}

hideChannelButton() {
window.ChannelIO?.("hideChannelButton");
}

setAppearance(appearance: Appearance) {
window.ChannelIO?.("setAppearance", appearance);
}
}

export default new ChannelService();
3 changes: 0 additions & 3 deletions src/components/Navbar/Navbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export const HomeNavbar: Story = {
name: "HomeNavbar",
render: () => (
<Navbar>
<Navbar.LeftButton>
<Icon name="logo" />
</Navbar.LeftButton>
<Navbar.RightButton>
<Text variant="bodySm" color="secondary">
앱 공유하기
Expand Down
6 changes: 3 additions & 3 deletions src/components/ui/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import CloseIcon from "@/assets/svg/ic-close.svg?react";
import EmptyCircleIcon from "@/assets/svg/ic-empty-circle.svg?react";
import GalleryIcon from "@/assets/svg/ic-gallery.svg?react";
import LeftArrowIcon from "@/assets/svg/ic-left-arrow.svg?react";
import LogoIcon from "@/assets/svg/ic-logo.svg?react";
import PasteIcon from "@/assets/svg/ic-paste.svg?react";
import PlusIcon from "@/assets/svg/ic-plus.svg?react";
import ShareIcon from "@/assets/svg/ic-share.svg?react";

export type IconNameType =
| "camera"
Expand All @@ -17,7 +17,7 @@ export type IconNameType =
| "plus"
| "checkCircle"
| "emptyCircle"
| "logo";
| "share";

export interface IconProps {
name: IconNameType;
Expand All @@ -32,7 +32,7 @@ export const ICONS = {
plus: PlusIcon,
checkCircle: CheckCircleIcon,
emptyCircle: EmptyCircleIcon,
logo: LogoIcon,
share: ShareIcon,
};

// 추후 사이즈, 컬러등 추가 가능
Expand Down
20 changes: 20 additions & 0 deletions src/hooks/common/useChannelTalk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from "react";

import ChannelService from "@/components/ChannelTalk/channelTalk";

export const useChannelTalk = () => {
const openChannelTalk = () => {
ChannelService.showMessenger();
};

useEffect(() => {
ChannelService.loadScript();

ChannelService.boot({
pluginKey: import.meta.env.VITE_CHANNEL_TALK_KEY || "",
hideChannelButtonOnBoot: true,
});
}, []);

return { openChannelTalk };
};
Loading