'use client'; import clsx from 'clsx'; import ImageWithFallback from '@gitroom/react/helpers/image.with.fallback'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; import { ThirdPartyListComponent } from '@gitroom/frontend/components/third-parties/third-party.list.component'; import React, { FC, useCallback, useState } from 'react'; import useSWR from 'swr'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import { useToaster } from '@gitroom/react/toaster/toaster'; import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; import useCookie from 'react-use-cookie'; import { SVGLine } from '@gitroom/frontend/components/launches/launches.component'; export const ThirdPartyMenuComponent: FC<{ reload: () => void; tParty: { id: string }; }> = (props) => { const { tParty, reload } = props; const fetch = useFetch(); const [show, setShow] = useState(false); const t = useT(); const toaster = useToaster(); const changeShow = () => { setShow((prev) => !prev); }; const deleteChannel = (id: string) => async () => { setShow(false); if ( !(await deleteDialog('Are you sure you want to delete this integration?')) ) { return; } const res = await fetch(`/third-party/${id}`, { method: 'DELETE', }); if (res.ok) { toaster.show('Integration deleted successfully', 'success'); reload(); } else { const error = await res.json(); console.error('Error deleting integration:', error); } }; return (
{show && (
e.stopPropagation()} className={`absolute top-[100%] start-0 p-[8px] px-[20px] bg-fifth flex flex-col gap-[16px] z-[100] rounded-[8px] border border-tableBorder text-nowrap`} >
{t('delete_integration', 'Delete Integration')}
)}
); }; export const ThirdPartyComponent = () => { const t = useT(); const fetch = useFetch(); const integrations = useCallback(async () => { return (await fetch('/third-party')).json(); }, []); const { data, isLoading, mutate } = useSWR('third-party', integrations, { revalidateOnFocus: false, revalidateOnReconnect: false, revalidateIfStale: false, revalidateOnMount: true, refreshWhenHidden: false, refreshWhenOffline: false, }); const [collapseMenu, setCollapseMenu] = useCookie('collapseMenu', '0'); return ( <>

{t('integrations')}

setCollapseMenu(collapseMenu === '1' ? '0' : '1')} className="group-[.sidebar]:rotate-[180deg] group-[.sidebar]:mx-auto text-btnText bg-btnSimple rounded-[6px] w-[24px] h-[24px] flex items-center justify-center cursor-pointer select-none" >
{!isLoading && !data?.length ? (
No Integrations Yet
) : ( data?.map((p: any) => (
{p.name}
)) )}
); };