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
6 changes: 6 additions & 0 deletions frontend/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
ClientWalletsListPage,
ClientJoinPage,
NotFound,
ClientChatHidden,
} from '@pages'
import { Route, Routes } from 'react-router-dom'

Expand All @@ -26,6 +27,7 @@ export const ROUTES_NAME = {
CLIENT_WALLETS_LIST: '/client/:clientChatSlug/wallets-list',
CLIENT_JOIN: '/client/:clientChatSlug/join',
NOT_FOUND: '/not-found',
CLIENT_CHAT_HIDDEN: '/chat-hidden',
}

export default (
Expand Down Expand Up @@ -57,5 +59,9 @@ export default (
/>
<Route path={ROUTES_NAME.CLIENT_JOIN} element={<ClientJoinPage />} />
<Route path={ROUTES_NAME.NOT_FOUND} element={<NotFound />} />
<Route
path={ROUTES_NAME.CLIENT_CHAT_HIDDEN}
element={<ClientChatHidden />}
/>
</Routes>
)
43 changes: 28 additions & 15 deletions frontend/src/pages/admin/ChatPage/ChatPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { useAppNavigation, useError } from '@hooks'
import { ROUTES_NAME } from '@routes'
import { goTo } from '@utils'
import { useEffect } from 'react'
import { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'

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

const { isLoading } = useApp()
const { toggleIsLoadingAction } = useAppActions()
const { showToast } = useToast()
const [updateChatVisibilityLoading, setUpdateChatVisibilityLoading] =
useState(false)

const { adminChatNotFound } = useError()

const { rules, chat } = useChat()
const { fetchChatAction } = useChatActions()
const { fetchChatAction, updateChatVisibilityAction } = useChatActions()

const isChatVisible = true
const { showToast } = useToast()

const fetchChat = async () => {
if (!chatSlug) return
Expand All @@ -43,6 +44,24 @@ export const ChatPage = () => {
}
}

const updateChatVisibility = async () => {
if (!chatSlug) return
try {
setUpdateChatVisibilityLoading(true)
await updateChatVisibilityAction(chatSlug, {
isEnabled: !chat?.isEnabled,
})
} catch (error) {
console.error(error)
} finally {
setUpdateChatVisibilityLoading(false)
showToast({
message: 'Chat visibility updated',
type: 'success',
})
}
}

useEffect(() => {
toggleIsLoadingAction(true)
fetchChat()
Expand All @@ -58,13 +77,6 @@ export const ChatPage = () => {
goTo(chat?.joinUrl)
}

const handleChatVisibility = () => {
showToast({
message: 'Chat visibility is not available yet',
type: 'error',
})
}

return (
<PageLayout>
<TelegramBackButton
Expand All @@ -80,14 +92,15 @@ export const ChatPage = () => {
<Block margin="top" marginValue={24}>
<Block margin="bottom" marginValue={24}>
<ListItem
disabled={updateChatVisibilityLoading}
text={
<Text type="text" color={isChatVisible ? 'danger' : 'accent'}>
{isChatVisible ? 'Hide Bot From Chat' : 'Show Bot in Chat'}
<Text type="text" color={chat?.isEnabled ? 'danger' : 'accent'}>
{chat?.isEnabled ? 'Hide Bot From Chat' : 'Show Bot in Chat'}
</Text>
}
onClick={handleChatVisibility}
onClick={updateChatVisibility}
before={
<Icon name={isChatVisible ? 'eyeCrossed' : 'eye'} size={28} />
<Icon name={chat?.isEnabled ? 'eyeCrossed' : 'eye'} size={28} />
}
/>
</Block>
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/pages/admin/ConditionPage/ConditionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export const ConditionPage = () => {
})
}

if (!conditionIdParam)
const isNewCondition = !conditionIdParam

if (isNewCondition)
return (
<PageLayout>
<TelegramBackButton onClick={navigateToChatPage} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Jettons = ({

prefetchJetton(address)
}, 150),
[]
[conditionState?.address, conditionState?.blockchainAddress]
)

const fetchConditionCategories = async () => {
Expand All @@ -73,10 +73,14 @@ export const Jettons = ({
}

useEffect(() => {
if (!isNewCondition && conditionState?.blockchainAddress) {
if (
!isNewCondition &&
conditionState?.blockchainAddress &&
!prefetchedConditionData
) {
prefetchJetton(conditionState?.blockchainAddress)
}
}, [conditionState])
}, [conditionState, isNewCondition])

useEffect(() => {
fetchConditionCategories()
Expand All @@ -86,7 +90,7 @@ export const Jettons = ({
}, [])

useEffect(() => {
if (categories?.length && (isNewCondition || condition)) {
if (categories?.length) {
let updatedConditionState: Partial<Condition> = {
type: 'jetton',
asset: condition?.asset || categories[0].asset,
Expand All @@ -104,7 +108,7 @@ export const Jettons = ({

setInitialState(updatedConditionState as Partial<Condition>)
}
}, [categories?.length, condition])
}, [categories?.length, condition, isNewCondition])

if (!categories?.length || !conditionState?.type) return null

Expand Down
10 changes: 6 additions & 4 deletions frontend/src/pages/admin/ConditionPage/components/NFT/NFT.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ export const NFT = ({
useEffect(() => {
if (
!isNewCondition &&
(conditionState?.blockchainAddress || conditionState?.address)
(conditionState?.blockchainAddress || conditionState?.address) &&
!prefetchedConditionData &&
!conditionState.asset &&
!conditionState.category
) {
prefetchNFTCollection(
conditionState?.blockchainAddress || conditionState?.address || ''
Expand All @@ -82,9 +85,8 @@ export const NFT = ({
}, [])

useEffect(() => {
if (categories?.length && (isNewCondition || condition)) {
if (categories?.length) {
let updatedConditionState: Partial<Condition> = {
// ...conditionState,
type: 'nft_collection',
asset: condition?.asset || undefined,
category: condition?.category || undefined,
Expand All @@ -101,7 +103,7 @@ export const NFT = ({

setInitialState(updatedConditionState as Partial<Condition>)
}
}, [categories?.length, condition])
}, [categories?.length, condition, isNewCondition])

if (!categories?.length || !conditionState?.type) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const Premium = ({
isEnabled: isNewCondition ? true : !!condition?.isEnabled,
}
setInitialState(updatedConditionState as Partial<Condition>)
}, [condition])
}, [condition, isNewCondition])

if (!conditionState?.type) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const Toncoin = ({

setInitialState(updatedConditionState as Partial<Condition>)
}
}, [categories?.length, condition])
}, [categories?.length, condition, isNewCondition])

if (!categories?.length || !conditionState?.type) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ export const Whitelist = ({
const { showToast } = useToast()

useEffect(() => {
if (isNewCondition || condition) {
if (isNewCondition) {
let updatedConditionState: Partial<Condition> = {
// ...conditionState,
type: 'whitelist',
description: condition?.description || '',
name: condition?.name || '',
Expand All @@ -35,7 +34,7 @@ export const Whitelist = ({

setInitialState(updatedConditionState as Partial<Condition>)
}
}, [condition])
}, [condition, isNewCondition])

if (!conditionState?.type) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,9 @@ export const NewConditionModule = () => {
})
}

const setInitialState = useCallback(
(value: Partial<Condition>) => {
setConditionState(value)
},
[conditionState?.type]
)
const setInitialState = (value: Partial<Condition>) => {
setConditionState(value)
}

const payload: ConditionComponentProps = {
isNewCondition: true,
Expand Down
36 changes: 36 additions & 0 deletions frontend/src/pages/client/ClientChatHidden/ClientChatHidden.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sneezeLottie from '@assets/sneeze.json'
import {
Block,
StickerPlayer,
TelegramBackButton,
TelegramMainButton,
Text,
} from '@components'
import { PageLayout } from '@components'

const webApp = window.Telegram.WebApp

export const ClientChatHidden = () => {
const handleCloseApp = () => {
webApp.close()
}

return (
<PageLayout center>
<TelegramBackButton />
<TelegramMainButton text="Close" onClick={handleCloseApp} />
<StickerPlayer lottie={sneezeLottie} />
<Block margin="top" marginValue={16}>
<Text type="title" align="center" weight="bold">
Chat or Channel Access Is Temporarily Disabled
</Text>
</Block>
<Block margin="top" marginValue={12}>
<Text type="text" align="center">
The admin has temporarily hidden this chat or channel. Please try
again later or contact them directly.
</Text>
</Block>
</PageLayout>
)
}
1 change: 1 addition & 0 deletions frontend/src/pages/client/ClientChatHidden/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ClientChatHidden'
8 changes: 8 additions & 0 deletions frontend/src/pages/client/ClientTasksPage/ClientTasksPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export const ClientTasksPage = () => {
}, [clientChatSlug])

useEffect(() => {
if (!chat?.isEnabled) {
appNavigate({
path: ROUTES_NAME.CLIENT_CHAT_HIDDEN,
params: { clientChatSlug },
})
return
}

if (chat?.isEligible) {
appNavigate({
path: ROUTES_NAME.CLIENT_JOIN,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './ClientChatHidden'
export * from './ClientTasksPage'
export * from './ClientConnectedWalletPage'
export * from './ClientWalletsListPage'
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/not-found/NotFound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const NotFound = () => {
</Block>
<Block margin="top" marginValue={12}>
<Text type="text" align="center">
The page youre looking for doesnt exist or the link is broken. But
dont worry — youre still in the right universe.
The page you`re looking for doesn`t exist or the link is broken. But
don`t worry — you`re still in the right universe.
</Text>
</Block>
</PageLayout>
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/store/chat/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,15 @@ export const fetchUserChatAPI = async (

return response
}

export const updateChatVisibilityAPI = async (
slug: string,
data: Partial<ChatInstance>
): Promise<ApiServiceResponse<ChatInstance>> => {
const response = await ApiService.put<ChatInstance>({
endpoint: `/admin/chats/${slug}/visibility`,
data,
})

return response
}
18 changes: 18 additions & 0 deletions frontend/src/store/chat/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fetchChatAPI,
fetchUserChatAPI,
updateChatAPI,
updateChatVisibilityAPI,
} from './api'
import { AdminChat, ChatInstance } from './types'

Expand All @@ -26,6 +27,10 @@ interface ChatActions {
updateChatAction: (slug: string, data: Partial<ChatInstance>) => void
fetchAdminUserChatsAction: () => Promise<AdminChat[]>
fetchUserChatAction: (slug: string) => void
updateChatVisibilityAction: (
slug: string,
data: Partial<ChatInstance>
) => void
}
}

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

set({ chat: data?.chat, rules: data?.rules, chatWallet: data?.wallet })
},
updateChatVisibilityAction: async (slug, values) => {
const { data, ok, error } = await updateChatVisibilityAPI(slug, values)

if (!ok) {
throw new Error(error)
}

if (!data) {
throw new Error('Chat data not found')
}

set({ chat: data })
},
},
}))

Expand Down
1 change: 1 addition & 0 deletions frontend/src/store/chat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ChatInstance {
title: string
username: string | null
membersCount: number
isEnabled: boolean
}

export interface ChatRuleAttribute {
Expand Down
Loading