diff --git a/lib/utils/url-utils.js b/lib/utils/url-utils.js index b7cb97ca4..a42beb63a 100644 --- a/lib/utils/url-utils.js +++ b/lib/utils/url-utils.js @@ -1,70 +1,75 @@ // @flow import urlParseLax from 'url-parse-lax'; export type URLInfo = { +year?: number, +month?: number, // 1-indexed +verify?: string, +calendar?: boolean, +chat?: boolean, +apps?: boolean, +thread?: string, - +settings?: 'account', + +settings?: 'account' | 'danger-zone', ... }; const yearRegex = new RegExp('(/|^)year/([0-9]+)(/|$)', 'i'); const monthRegex = new RegExp('(/|^)month/([0-9]+)(/|$)', 'i'); const threadRegex = new RegExp('(/|^)thread/([0-9]+)(/|$)', 'i'); const verifyRegex = new RegExp('(/|^)verify/([a-f0-9]+)(/|$)', 'i'); const calendarRegex = new RegExp('(/|^)calendar(/|$)', 'i'); const chatRegex = new RegExp('(/|^)chat(/|$)', 'i'); const appsRegex = new RegExp('(/|^)apps(/|$)', 'i'); const accountSettingsRegex = new RegExp('(/|^)settings/account(/|$)', 'i'); +const dangerZoneRegex = new RegExp('(/|^)settings/danger-zone(/|$)', 'i'); function infoFromURL(url: string): URLInfo { const yearMatches = yearRegex.exec(url); const monthMatches = monthRegex.exec(url); const threadMatches = threadRegex.exec(url); const verifyMatches = verifyRegex.exec(url); const calendarTest = calendarRegex.test(url); const chatTest = chatRegex.test(url); const appsTest = appsRegex.test(url); const accountSettingsTest = accountSettingsRegex.test(url); + const dangerZoneTest = dangerZoneRegex.test(url); + const returnObj = {}; if (yearMatches) { returnObj.year = parseInt(yearMatches[2], 10); } if (monthMatches) { const month = parseInt(monthMatches[2], 10); if (month < 1 || month > 12) { throw new Error('invalid_month'); } returnObj.month = month; } if (threadMatches) { returnObj.thread = threadMatches[2]; } if (verifyMatches) { returnObj.verify = verifyMatches[2]; } if (calendarTest) { returnObj.calendar = true; } else if (chatTest) { returnObj.chat = true; } else if (appsTest) { returnObj.apps = true; } else if (accountSettingsTest) { returnObj.settings = 'account'; + } else if (dangerZoneTest) { + returnObj.settings = 'danger-zone'; } return returnObj; } function normalizeURL(url: string): string { return urlParseLax(url).href; } const setURLPrefix = 'SET_URL_PREFIX'; export { infoFromURL, normalizeURL, setURLPrefix }; diff --git a/web/sidebar/settings-switcher.react.js b/web/sidebar/settings-switcher.react.js index 60e4c30d1..871cb36ce 100644 --- a/web/sidebar/settings-switcher.react.js +++ b/web/sidebar/settings-switcher.react.js @@ -1,42 +1,64 @@ // @flow import * as React from 'react'; import { useDispatch } from 'react-redux'; import { navSettingsSectionSelector } from '../selectors/nav-selectors.js'; import { updateNavInfoActionType } from '../types/nav-types'; import css from './left-layout-aside.css'; import NavigationPanel from './navigation-panel.react'; function SettingsSwitcher(): React.Node { const dispatch = useDispatch(); + const onClickAccountSettings = React.useCallback( (event: SyntheticEvent) => { event.preventDefault(); dispatch({ type: updateNavInfoActionType, payload: { tab: 'settings', settingsSection: 'account' }, }); }, [dispatch], ); - const accountSettingsNavigationItem = React.useMemo( () => (

My Account

), [onClickAccountSettings], ); + const onClickDangerZone = React.useCallback( + (event: SyntheticEvent) => { + event.preventDefault(); + dispatch({ + type: updateNavInfoActionType, + payload: { tab: 'settings', settingsSection: 'danger-zone' }, + }); + }, + [dispatch], + ); + const dangerZoneNavigationItem = React.useMemo( + () => ( +
+

Danger Zone

+
+ ), + [onClickDangerZone], + ); + return ( {accountSettingsNavigationItem} + + {dangerZoneNavigationItem} + ); } export default SettingsSwitcher; diff --git a/web/types/nav-types.js b/web/types/nav-types.js index 8e4835b69..b7645b59c 100644 --- a/web/types/nav-types.js +++ b/web/types/nav-types.js @@ -1,18 +1,18 @@ // @flow import type { BaseNavInfo } from 'lib/types/nav-types'; import type { ThreadInfo } from 'lib/types/thread-types'; export type NavigationTab = 'calendar' | 'chat' | 'apps' | 'settings'; -export type NavigationSettingsSection = 'account'; +export type NavigationSettingsSection = 'account' | 'danger-zone'; export type NavInfo = { ...$Exact, +tab: NavigationTab, +activeChatThreadID: ?string, +pendingThread?: ThreadInfo, +settingsSection?: NavigationSettingsSection, }; export const updateNavInfoActionType = 'UPDATE_NAV_INFO';