-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84c60ec
commit 83d6b7a
Showing
4 changed files
with
433 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 60 additions & 57 deletions
117
src/components/communitySettings/communityPlatforms/TcTelegram/TcTelegram.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,78 @@ | ||
import React, { useState } from 'react'; | ||
import { CircularProgress } from '@mui/material'; | ||
import React, { useState } from "react"; | ||
import { CircularProgress } from "@mui/material"; | ||
|
||
import useAppStore from '@/store/useStore'; | ||
import useAppStore from "@/store/useStore"; | ||
|
||
import { StorageService } from '@/services/StorageService'; | ||
import { IntegrationPlatform } from '@/utils/enums'; | ||
import { IDiscordModifiedCommunity, IPlatformProps } from '@/utils/interfaces'; | ||
import { StorageService } from "@/services/StorageService"; | ||
import { IntegrationPlatform } from "@/utils/enums"; | ||
import { IDiscordModifiedCommunity, IPlatformProps } from "@/utils/interfaces"; | ||
|
||
import TcConnectedTelegram from './TcConnectedTelegram'; | ||
import TcTelegramIntegrationDialog from './TcTelegramIntegrationDialog'; | ||
import TcConnectPlatformButton from '../TcConnectPlatformButton'; | ||
import TcConnectedTelegram from "./TcConnectedTelegram"; | ||
import TcTelegramIntegrationDialog from "./TcTelegramIntegrationDialog"; | ||
import TcConnectPlatformButton from "../TcConnectPlatformButton"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
interface TcTelegramIntegrationProps { | ||
isLoading: boolean; | ||
connectedPlatforms: IPlatformProps[]; | ||
handleUpdateCommunityPlatform: () => void; | ||
isLoading: boolean; | ||
connectedPlatforms: IPlatformProps[]; | ||
handleUpdateCommunityPlatform: () => void; | ||
} | ||
|
||
function TcTelegram({ | ||
isLoading, | ||
connectedPlatforms, | ||
handleUpdateCommunityPlatform, | ||
isLoading, | ||
connectedPlatforms, | ||
handleUpdateCommunityPlatform, | ||
}: TcTelegramIntegrationProps) { | ||
const { telegram, generateToken } = useAppStore(); | ||
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false); | ||
const router = useRouter(); | ||
const { telegram, generateToken } = useAppStore(); | ||
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false); | ||
|
||
const communityId = | ||
StorageService.readLocalStorage<IDiscordModifiedCommunity>('community')?.id; | ||
const communityId = | ||
StorageService.readLocalStorage<IDiscordModifiedCommunity>("community")?.id; | ||
|
||
const handleConnectPlatform = async () => { | ||
try { | ||
await generateToken({ | ||
type: 'telegram_verification', | ||
communityId: communityId as string, | ||
}); | ||
const handleConnectPlatform = async () => { | ||
try { | ||
await generateToken({ | ||
type: "telegram_verification", | ||
communityId: communityId as string, | ||
}); | ||
|
||
setIsDialogOpen(true); | ||
} catch (error) { | ||
console.error('Failed to generate token:', error); | ||
} | ||
}; | ||
setIsDialogOpen(true); | ||
} catch (error) { | ||
console.error("Failed to generate token:", error); | ||
} | ||
}; | ||
|
||
const handleClose = () => { | ||
setIsDialogOpen(false); | ||
}; | ||
const handleClose = () => { | ||
setIsDialogOpen(false); | ||
router.push('/community-settings/?managePlatform=telegram') | ||
}; | ||
|
||
return ( | ||
<div className='flex items-center space-x-3 rounded-sm bg-secondary bg-opacity-5 p-5'> | ||
<TcConnectPlatformButton | ||
platform={IntegrationPlatform.Telegram} | ||
connectedPlatforms={connectedPlatforms} | ||
handleConnectPlatform={handleConnectPlatform} | ||
/> | ||
{isLoading ? ( | ||
<CircularProgress size={30} /> | ||
) : ( | ||
<TcConnectedTelegram | ||
platforms={connectedPlatforms} | ||
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform} | ||
/> | ||
)} | ||
return ( | ||
<div className="flex items-center space-x-3 rounded-sm bg-secondary bg-opacity-5 p-5"> | ||
<TcConnectPlatformButton | ||
platform={IntegrationPlatform.Telegram} | ||
connectedPlatforms={connectedPlatforms} | ||
handleConnectPlatform={handleConnectPlatform} | ||
/> | ||
{isLoading ? ( | ||
<CircularProgress size={30} /> | ||
) : ( | ||
<TcConnectedTelegram | ||
platforms={connectedPlatforms} | ||
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform} | ||
/> | ||
)} | ||
|
||
<TcTelegramIntegrationDialog | ||
isOpen={isDialogOpen} | ||
handleClose={handleClose} | ||
telegram={telegram} | ||
generateToken={handleConnectPlatform} | ||
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform} | ||
/> | ||
</div> | ||
); | ||
<TcTelegramIntegrationDialog | ||
isOpen={isDialogOpen} | ||
handleClose={handleClose} | ||
telegram={telegram} | ||
generateToken={handleConnectPlatform} | ||
handleUpdateCommunityPlatform={handleUpdateCommunityPlatform} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default TcTelegram; |
Oops, something went wrong.