Skip to content

Commit e56dfd2

Browse files
committed
fix: chat
1 parent 8df4221 commit e56dfd2

3 files changed

Lines changed: 7685 additions & 7643 deletions

File tree

apps/shopify-app/embeded/chat.tsx

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,53 @@
1+
import { createRoot } from "react-dom/client";
12
import Sprite from "app/components/SpriteIcon/Sprite";
23
import PublicChat from "app/components/publicChat/PublicChat";
3-
import ReactDOM from "react-dom";
44

5-
const renderComponent = () => {
5+
function getOrCreateUserId(): string {
6+
let userId = localStorage.getItem("chat-user-id");
7+
if (!userId) {
8+
userId = Date.now().toString();
9+
localStorage.setItem("chat-user-id", userId);
10+
}
11+
return userId;
12+
}
13+
14+
function renderChat() {
615
const container = document.getElementById("support-ai-chat-place");
7-
if (container) {
8-
const shopName = container?.getAttribute("data-shopName");
9-
const position = container.getAttribute("data-position");
10-
const localChatId = localStorage.getItem("supportAiChatId");
16+
if (!container) return;
1117

12-
let userId = localStorage.getItem("chat-user-id");
13-
if (!userId) {
14-
userId = Date.now().toString();
15-
localStorage.setItem("chat-user-id", userId);
16-
}
18+
const shopName = container.getAttribute("data-shopName") ?? "";
19+
const position = container.getAttribute("data-position") ?? "right";
20+
const localChatId = localStorage.getItem("supportAiChatId");
21+
const userId = getOrCreateUserId();
1722

18-
ReactDOM.render(
19-
<>
20-
<div
21-
style={{
22-
width: 0,
23-
height: 0,
24-
overflow: "hidden",
25-
visibility: "hidden",
26-
}}
27-
>
28-
<Sprite />
29-
</div>
30-
<PublicChat
31-
shopName={shopName}
32-
userId={userId}
33-
position={position || "right"}
34-
chatId={
35-
localChatId && localChatId !== "undefined" ? localChatId : null
36-
}
37-
/>
38-
</>,
39-
container,
40-
);
41-
}
42-
};
23+
const chatId =
24+
localChatId && localChatId !== "undefined" ? localChatId : null;
25+
26+
const root = createRoot(container);
27+
root.render(
28+
<>
29+
<div
30+
style={{
31+
width: 0,
32+
height: 0,
33+
overflow: "hidden",
34+
visibility: "hidden",
35+
}}
36+
>
37+
<Sprite />
38+
</div>
39+
<PublicChat
40+
shopName={shopName}
41+
userId={userId}
42+
position={position}
43+
chatId={chatId}
44+
/>
45+
</>,
46+
);
47+
}
4348

4449
if (document.readyState === "loading") {
45-
document.addEventListener("DOMContentLoaded", renderComponent);
50+
document.addEventListener("DOMContentLoaded", renderChat);
4651
} else {
47-
renderComponent();
52+
renderChat();
4853
}

apps/shopify-app/extensions/chat/assets/chat.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* ../../../../../../../../../private/var/folders/d8/kn6sfphj67n572x21m44vz4r0000gn/T/tmp-22136-SqNW8n4P73ek/Users/ruslan/my/shopify/apps/ai-assistant/shopify-ai-bot/apps/shopify-app/app/components/publicChat/styles.css */
1+
/* ../../../../../../../../../private/var/folders/d8/kn6sfphj67n572x21m44vz4r0000gn/T/tmp-22932-KKj3Rfnf7BsO/Users/ruslan/my/shopify/apps/ai-assistant/shopify-ai-bot/apps/shopify-app/app/components/publicChat/styles.css */
22
*,
33
::after,
44
::before {

0 commit comments

Comments
 (0)