'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 (

{t('approved_apps', 'Approved Apps')}

{t( 'apps_you_have_authorized', 'Applications you have authorized to access your Postiz account.' )}
{!apps?.length ? (
{t('no_approved_apps', 'No approved apps yet.')}
) : (
{apps.map((app: any) => (
{app.oauthApp?.picture?.path ? ( {app.oauthApp.name} ) : (
{app.oauthApp?.name?.[0]?.toUpperCase() || '?'}
)}
{app.oauthApp?.name}
{app.oauthApp?.description && (
{app.oauthApp.description}
)}
{t('authorized_on', 'Authorized on')}{' '} {new Date(app.createdAt).toLocaleDateString()}
))}
)}
); };