import { SyntheticEvent, useCallback } from 'react' import { PageTitle, AuthMenu } from '@app/components/general' import { useFeaturesData, useUserData } from '@app/data' import { metaSetter } from '@app/utils' import { useWebsiteContext } from '@app/components/providers/website' import { Header2 } from '@app/components/general/header' import { AppManager, UserManager } from '@app/managers' import { useAuthContext } from '@app/components/providers/auth' import { NotificationSettings } from '@app/components/settings/notifications' import { HistoryView } from '@app/components/settings/history-view' import { CoreVitalsView } from '@app/components/settings/core-vitals-view' import { RemoveDataView } from '@app/components/settings/remove-data-view' import { LighthouseView } from '@app/components/settings/lighthouse-view' import { ActionsViewView } from '@app/components/settings/actions-view' import { useInteractiveContext } from '@app/components/providers/interactive' import { ThemesView } from '@app/components/settings/themes-view' import { LazyMount } from '@app/components/lazy/lazymount' import { ApiView } from '@app/components/settings/api-view' import { fetcher } from '@app/utils/fetcher' function Settings() { const { settings: data, // user loading, onConfirmLighthouse, filterEmailDatesData: filterEmailDates, onFilterEmailDates, } = useUserData(true, 'settings') const { toggleAlert } = useFeaturesData() const { account, setAccountType } = useAuthContext() const { removeWebsite, setLighthouseVisibility, lighthouseVisible } = useWebsiteContext() const { setSelectedWebsite } = useInteractiveContext() const { alertEnabled, activeSubscription } = account const user = data?.user const filterEmailDatesData = filterEmailDates ?? user?.emailFilteredDates const onRemoveAllWebsitePress = useCallback(async () => { if (window.confirm('Are you sure you want to remove all websites?')) { try { await removeWebsite({ variables: { url: '', deleteMany: true, }, }) setSelectedWebsite('') } catch (e) { console.error(e) } } }, [removeWebsite, setSelectedWebsite]) const onDeleteAccountPress = useCallback(async () => { if ( window.confirm( 'Are you sure you want to delete your account and all data?' ) ) { try { await fetcher('/user', null, 'DELETE') window.location.href = '/' } catch (e) { console.error(e) } } }, []) const onLighthouseToggle = useCallback(() => { setLighthouseVisibility((visible: boolean) => { AppManager.toggleSnack( true, `Lighthouse display ${!visible ? 'hidden' : 'visible'}` ) return !visible }) }, [setLighthouseVisibility]) const onAlertToggle = async (e?: SyntheticEvent) => { if (e && typeof e.stopPropagation === 'function') { e?.stopPropagation() } try { const nextValue = !alertEnabled setAccountType({ authed: account.authed, activeSubscription, alertEnabled: nextValue, inited: true, }) // todo: remove local storage usage for network + memory UserManager.setAlertsEnabled(nextValue) await toggleAlert({ variables: { alertEnabled: nextValue, }, }) } catch (e) { console.error(e) } } if (!data && !loading) { return (
} />
Authentication required for Settings. Please login to continue.
) } return (
} /> Configuration to maximize the output for you
) } export default metaSetter( { Settings }, { gql: true, description: 'Settings that you can configure to build custom workflows and enhance your report insight.', } )