Skip to content

Commit d30bee4

Browse files
committed
feat: hidden chat
1 parent 02ad264 commit d30bee4

File tree

10 files changed

+113
-17
lines changed

10 files changed

+113
-17
lines changed

frontend/src/Routes.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ClientWalletsListPage,
1111
ClientJoinPage,
1212
NotFound,
13+
ClientChatHidden,
1314
} from '@pages'
1415
import { Route, Routes } from 'react-router-dom'
1516

@@ -26,6 +27,7 @@ export const ROUTES_NAME = {
2627
CLIENT_WALLETS_LIST: '/client/:clientChatSlug/wallets-list',
2728
CLIENT_JOIN: '/client/:clientChatSlug/join',
2829
NOT_FOUND: '/not-found',
30+
CLIENT_CHAT_HIDDEN: '/chat-hidden',
2931
}
3032

3133
export default (
@@ -57,5 +59,9 @@ export default (
5759
/>
5860
<Route path={ROUTES_NAME.CLIENT_JOIN} element={<ClientJoinPage />} />
5961
<Route path={ROUTES_NAME.NOT_FOUND} element={<NotFound />} />
62+
<Route
63+
path={ROUTES_NAME.CLIENT_CHAT_HIDDEN}
64+
element={<ClientChatHidden />}
65+
/>
6066
</Routes>
6167
)

frontend/src/pages/admin/ChatPage/ChatPage.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { useAppNavigation, useError } from '@hooks'
1212
import { ROUTES_NAME } from '@routes'
1313
import { goTo } from '@utils'
14-
import { useEffect } from 'react'
14+
import { useEffect, useState } from 'react'
1515
import { useParams } from 'react-router-dom'
1616

1717
import { useApp, useAppActions, useChat, useChatActions } from '@store'
@@ -24,14 +24,15 @@ export const ChatPage = () => {
2424

2525
const { isLoading } = useApp()
2626
const { toggleIsLoadingAction } = useAppActions()
27-
const { showToast } = useToast()
27+
const [updateChatVisibilityLoading, setUpdateChatVisibilityLoading] =
28+
useState(false)
2829

2930
const { adminChatNotFound } = useError()
3031

3132
const { rules, chat } = useChat()
32-
const { fetchChatAction } = useChatActions()
33+
const { fetchChatAction, updateChatVisibilityAction } = useChatActions()
3334

34-
const isChatVisible = true
35+
const { showToast } = useToast()
3536

3637
const fetchChat = async () => {
3738
if (!chatSlug) return
@@ -43,6 +44,24 @@ export const ChatPage = () => {
4344
}
4445
}
4546

47+
const updateChatVisibility = async () => {
48+
if (!chatSlug) return
49+
try {
50+
setUpdateChatVisibilityLoading(true)
51+
await updateChatVisibilityAction(chatSlug, {
52+
isEnabled: !chat?.isEnabled,
53+
})
54+
} catch (error) {
55+
console.error(error)
56+
} finally {
57+
setUpdateChatVisibilityLoading(false)
58+
showToast({
59+
message: 'Chat visibility updated',
60+
type: 'success',
61+
})
62+
}
63+
}
64+
4665
useEffect(() => {
4766
toggleIsLoadingAction(true)
4867
fetchChat()
@@ -58,13 +77,6 @@ export const ChatPage = () => {
5877
goTo(chat?.joinUrl)
5978
}
6079

61-
const handleChatVisibility = () => {
62-
showToast({
63-
message: 'Chat visibility is not available yet',
64-
type: 'error',
65-
})
66-
}
67-
6880
return (
6981
<PageLayout>
7082
<TelegramBackButton
@@ -80,14 +92,15 @@ export const ChatPage = () => {
8092
<Block margin="top" marginValue={24}>
8193
<Block margin="bottom" marginValue={24}>
8294
<ListItem
95+
disabled={updateChatVisibilityLoading}
8396
text={
84-
<Text type="text" color={isChatVisible ? 'danger' : 'accent'}>
85-
{isChatVisible ? 'Hide Bot From Chat' : 'Show Bot in Chat'}
97+
<Text type="text" color={chat?.isEnabled ? 'danger' : 'accent'}>
98+
{chat?.isEnabled ? 'Hide Bot From Chat' : 'Show Bot in Chat'}
8699
</Text>
87100
}
88-
onClick={handleChatVisibility}
101+
onClick={updateChatVisibility}
89102
before={
90-
<Icon name={isChatVisible ? 'eyeCrossed' : 'eye'} size={28} />
103+
<Icon name={chat?.isEnabled ? 'eyeCrossed' : 'eye'} size={28} />
91104
}
92105
/>
93106
</Block>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sneezeLottie from '@assets/sneeze.json'
2+
import {
3+
Block,
4+
StickerPlayer,
5+
TelegramBackButton,
6+
TelegramMainButton,
7+
Text,
8+
} from '@components'
9+
import { PageLayout } from '@components'
10+
11+
const webApp = window.Telegram.WebApp
12+
13+
export const ClientChatHidden = () => {
14+
const handleCloseApp = () => {
15+
webApp.close()
16+
}
17+
18+
return (
19+
<PageLayout center>
20+
<TelegramBackButton />
21+
<TelegramMainButton text="Close" onClick={handleCloseApp} />
22+
<StickerPlayer lottie={sneezeLottie} />
23+
<Block margin="top" marginValue={16}>
24+
<Text type="title" align="center" weight="bold">
25+
Chat or Channel Access Is Temporarily Disabled
26+
</Text>
27+
</Block>
28+
<Block margin="top" marginValue={12}>
29+
<Text type="text" align="center">
30+
The admin has temporarily hidden this chat or channel. Please try
31+
again later or contact them directly.
32+
</Text>
33+
</Block>
34+
</PageLayout>
35+
)
36+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './ClientChatHidden'

frontend/src/pages/client/ClientTasksPage/ClientTasksPage.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export const ClientTasksPage = () => {
4545
}, [clientChatSlug])
4646

4747
useEffect(() => {
48+
if (!chat?.isEnabled) {
49+
appNavigate({
50+
path: ROUTES_NAME.CLIENT_CHAT_HIDDEN,
51+
params: { clientChatSlug },
52+
})
53+
return
54+
}
55+
4856
if (chat?.isEligible) {
4957
appNavigate({
5058
path: ROUTES_NAME.CLIENT_JOIN,

frontend/src/pages/client/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './ClientChatHidden'
12
export * from './ClientTasksPage'
23
export * from './ClientConnectedWalletPage'
34
export * from './ClientWalletsListPage'

frontend/src/pages/not-found/NotFound.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const NotFound = () => {
2727
</Block>
2828
<Block margin="top" marginValue={12}>
2929
<Text type="text" align="center">
30-
The page youre looking for doesnt exist or the link is broken. But
31-
dont worry — youre still in the right universe.
30+
The page you`re looking for doesn`t exist or the link is broken. But
31+
don`t worry — you`re still in the right universe.
3232
</Text>
3333
</Block>
3434
</PageLayout>

frontend/src/store/chat/api.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,15 @@ export const fetchUserChatAPI = async (
4343

4444
return response
4545
}
46+
47+
export const updateChatVisibilityAPI = async (
48+
slug: string,
49+
data: Partial<ChatInstance>
50+
): Promise<ApiServiceResponse<ChatInstance>> => {
51+
const response = await ApiService.put<ChatInstance>({
52+
endpoint: `/admin/chats/${slug}/visibility`,
53+
data,
54+
})
55+
56+
return response
57+
}

frontend/src/store/chat/chat.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
fetchChatAPI,
88
fetchUserChatAPI,
99
updateChatAPI,
10+
updateChatVisibilityAPI,
1011
} from './api'
1112
import { AdminChat, ChatInstance } from './types'
1213

@@ -26,6 +27,10 @@ interface ChatActions {
2627
updateChatAction: (slug: string, data: Partial<ChatInstance>) => void
2728
fetchAdminUserChatsAction: () => Promise<AdminChat[]>
2829
fetchUserChatAction: (slug: string) => void
30+
updateChatVisibilityAction: (
31+
slug: string,
32+
data: Partial<ChatInstance>
33+
) => void
2934
}
3035
}
3136

@@ -81,6 +86,19 @@ const useChatStore = create<ChatStore & ChatActions>((set) => ({
8186

8287
set({ chat: data?.chat, rules: data?.rules, chatWallet: data?.wallet })
8388
},
89+
updateChatVisibilityAction: async (slug, values) => {
90+
const { data, ok, error } = await updateChatVisibilityAPI(slug, values)
91+
92+
if (!ok) {
93+
throw new Error(error)
94+
}
95+
96+
if (!data) {
97+
throw new Error('Chat data not found')
98+
}
99+
100+
set({ chat: data })
101+
},
84102
},
85103
}))
86104

frontend/src/store/chat/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ChatInstance {
1919
title: string
2020
username: string | null
2121
membersCount: number
22+
isEnabled: boolean
2223
}
2324

2425
export interface ChatRuleAttribute {

0 commit comments

Comments
 (0)