'use client'; import { FC, Fragment, useCallback } from 'react'; import { useFetch } from '@gitroom/helpers/utils/custom.fetch'; import useSWR from 'swr'; import { Button } from '@gitroom/react/form/button'; import { useToaster } from '@gitroom/react/toaster/toaster'; import { deleteDialog } from '@gitroom/react/helpers/delete.dialog'; import { useT } from '@gitroom/react/translation/get.transation.service.client'; const useApprovedApps = () => { const fetch = useFetch(); const load = useCallback(async () => { return (await fetch('/user/approved-apps')).json(); }, []); return useSWR('approved-apps', load, { revalidateOnFocus: false, revalidateOnReconnect: false, revalidateIfStale: false, }); }; export const ApprovedAppsComponent: FC = () => { const fetch = useFetch(); const toaster = useToaster(); const t = useT(); const { data: apps, mutate } = useApprovedApps(); const revokeApp = useCallback( (app: any) => async () => { if ( await deleteDialog( t( 'are_you_sure_revoke_access', `Are you sure you want to revoke access for ${app.oauthApp?.name}?`, { name: app.oauthApp?.name } ) ) ) { try { await fetch(`/user/approved-apps/${app.id}`, { method: 'DELETE', }); toaster.show( t('access_revoked', 'Access revoked successfully'), 'success' ); mutate(); } catch { toaster.show(t('failed_to_revoke', 'Failed to revoke access'), 'warning'); } } }, [] ); if (apps === undefined) { return null; } return (