From 5b6394ee54c2a424ba28c0cc2f83708d6948edee Mon Sep 17 00:00:00 2001 From: ameer2468 <33054370+ameer2468@users.noreply.github.com> Date: Wed, 16 Aug 2023 10:16:18 +0300 Subject: [PATCH] [ENG-967] Reset confirmation for db sd reset (#1221) Reset confirmation for db sd reset --- apps/desktop/src/App.tsx | 2 ++ interface/ErrorFallback.tsx | 25 ++++++++++++++++++------- interface/components/AlertDialog.tsx | 4 +++- packages/ui/src/Dialog.tsx | 19 +++++++++++++++++-- 4 files changed, 40 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src/App.tsx b/apps/desktop/src/App.tsx index eff207b5c..0ad90af20 100644 --- a/apps/desktop/src/App.tsx +++ b/apps/desktop/src/App.tsx @@ -16,6 +16,7 @@ import { routes } from '@sd/interface'; import { getSpacedropState } from '@sd/interface/hooks/useSpacedropState'; +import { Dialogs } from '@sd/ui'; import '@sd/ui/style'; import * as commands from './commands'; @@ -118,6 +119,7 @@ export default function App() { + diff --git a/interface/ErrorFallback.tsx b/interface/ErrorFallback.tsx index 99b727c31..b3b01ae0c 100644 --- a/interface/ErrorFallback.tsx +++ b/interface/ErrorFallback.tsx @@ -3,6 +3,7 @@ import { FallbackProps } from 'react-error-boundary'; import { useRouteError } from 'react-router'; import { useDebugState } from '@sd/client'; import { Button } from '@sd/ui'; +import { showAlertDialog } from './components'; import { useOperatingSystem, useTheme } from './hooks'; export function RouterErrorBoundary() { @@ -55,6 +56,21 @@ export function ErrorPage({ const debug = useDebugState(); const os = useOperatingSystem(); const isMacOS = os === 'macOS'; + + const resetHandler = () => { + showAlertDialog({ + title: 'Reset', + value: 'Are you sure you want to reset Spacedrive? Your database will be deleted.', + label: 'Confirm', + cancelBtn: true, + onSubmit: () => { + localStorage.clear(); + // @ts-expect-error + window.__TAURI_INVOKE__('reset_spacedrive'); + } + }); + }; + if (!submessage && debug.enabled) submessage = 'Check the console (CMD/CTRL + OPTION + i) for stack trace.'; @@ -98,13 +114,8 @@ export function ErrorPage({

diff --git a/interface/components/AlertDialog.tsx b/interface/components/AlertDialog.tsx index c547eb4c5..24e4fba45 100644 --- a/interface/components/AlertDialog.tsx +++ b/interface/components/AlertDialog.tsx @@ -10,6 +10,7 @@ interface Props extends UseDialogProps { value?: string; // value to be displayed as text or in an input box label?: string; // button label inputBox?: boolean; // whether the dialog should display the `value` in a disabled input box or as text + cancelBtn?: boolean; // whether the dialog should have a cancel button } const AlertDialog = (props: Props) => { @@ -20,6 +21,7 @@ const AlertDialog = (props: Props) => { form={useZodForm()} dialog={useDialog(props)} ctaLabel={props.label !== undefined ? props.label : 'Done'} + cancelBtn={props.cancelBtn} onCancelled={false} > {props.description &&
{props.description}
} @@ -37,7 +39,7 @@ const AlertDialog = (props: Props) => { }} size="icon" > - + } /> diff --git a/packages/ui/src/Dialog.tsx b/packages/ui/src/Dialog.tsx index 5c9eb2ea8..8bc1c73fd 100644 --- a/packages/ui/src/Dialog.tsx +++ b/packages/ui/src/Dialog.tsx @@ -118,6 +118,7 @@ export interface DialogProps children?: ReactNode; ctaDanger?: boolean; closeLabel?: string; + cancelBtn?: boolean; description?: string; onCancelled?: boolean | (() => void); submitDisabled?: boolean; @@ -187,7 +188,7 @@ export function Dialog({ {props.children} -
+
{form.formState.isSubmitting && } {props.buttonsSideContent && (
{props.buttonsSideContent}
@@ -209,7 +210,21 @@ export function Dialog({ )} - + {props.cancelBtn && ( + + + + )}