@@ -11,7 +11,7 @@ import {
1111import { useAppNavigation , useError } from '@hooks'
1212import { ROUTES_NAME } from '@routes'
1313import { goTo } from '@utils'
14- import { useEffect } from 'react'
14+ import { useEffect , useState } from 'react'
1515import { useParams } from 'react-router-dom'
1616
1717import { 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 >
0 commit comments