feat: connect channel

This commit is contained in:
Nevo David 2024-12-20 12:00:37 +07:00
parent 7ca48dfc43
commit 1a2937b518
1 changed files with 18 additions and 5 deletions

View File

@ -9,16 +9,13 @@ import clsx from 'clsx';
import Image from 'next/image';
import { Menu } from '@gitroom/frontend/components/launches/menu/menu';
import {
AddProviderComponent,
ApiModal,
CustomVariables,
UrlModal,
} from '@gitroom/frontend/components/launches/add.provider.component';
import { useRouter } from 'next/navigation';
import { useVariables } from '@gitroom/react/helpers/variable.context';
import { string } from 'yup';
import { useToaster } from '@gitroom/react/toaster/toaster';
import { useModals } from '@mantine/modals';
import { Integration } from '@prisma/client';
export const ConnectChannels: FC = () => {
const fetch = useFetch();
@ -27,7 +24,6 @@ export const ConnectChannels: FC = () => {
const [identifier, setIdentifier] = useState<any>(undefined);
const [popup, setPopups] = useState<undefined | string[]>(undefined);
const toaster = useToaster();
const modal = useModals();
const [showCustom, setShowCustom] = useState<any>(undefined);
const getIntegrations = useCallback(async () => {
@ -47,6 +43,22 @@ export const ConnectChannels: FC = () => {
// []
// );
const refreshChannel = useCallback(
(integration: Integration & { identifier: string }) => async () => {
const { url } = await (
await fetch(
`/integrations/social/${integration.identifier}?refresh=${integration.internalId}`,
{
method: 'GET',
}
)
).json();
window.location.href = url;
},
[]
);
const addMessage = useCallback(
(event: MessageEvent<{ msg: string; success: boolean }>) => {
if (!event.data.msg) {
@ -346,6 +358,7 @@ export const ConnectChannels: FC = () => {
mutate={mutate}
onChange={update}
id={integration.id}
refreshChannel={refreshChannel}
canEnable={
user?.totalChannels! > totalNonDisabledChannels &&
integration.disabled