70 lines
2 KiB
TypeScript
70 lines
2 KiB
TypeScript
|
|
import type { Blocker } from "react-router";
|
||
|
|
import {
|
||
|
|
AlertDialog,
|
||
|
|
AlertDialogAction,
|
||
|
|
AlertDialogCancel,
|
||
|
|
AlertDialogContent,
|
||
|
|
AlertDialogDescription,
|
||
|
|
AlertDialogFooter,
|
||
|
|
AlertDialogHeader,
|
||
|
|
AlertDialogTitle,
|
||
|
|
} from "~/components/ui/alert-dialog";
|
||
|
|
|
||
|
|
export function LeaveSettingsDialog({ blocker }: { blocker: Blocker }) {
|
||
|
|
if (blocker.state !== "blocked") return null;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<AlertDialog open>
|
||
|
|
<AlertDialogContent>
|
||
|
|
<AlertDialogHeader>
|
||
|
|
<AlertDialogTitle>Leave without saving?</AlertDialogTitle>
|
||
|
|
<AlertDialogDescription>
|
||
|
|
You have unsaved settings changes. If you leave this page, those changes will be lost.
|
||
|
|
</AlertDialogDescription>
|
||
|
|
</AlertDialogHeader>
|
||
|
|
<AlertDialogFooter>
|
||
|
|
<AlertDialogCancel onClick={() => blocker.reset?.()}>
|
||
|
|
Stay
|
||
|
|
</AlertDialogCancel>
|
||
|
|
<AlertDialogAction onClick={() => blocker.proceed?.()}>
|
||
|
|
Leave without saving
|
||
|
|
</AlertDialogAction>
|
||
|
|
</AlertDialogFooter>
|
||
|
|
</AlertDialogContent>
|
||
|
|
</AlertDialog>
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
export function SwitchSettingsSectionDialog({
|
||
|
|
open,
|
||
|
|
onOpenChange,
|
||
|
|
onStay,
|
||
|
|
onDiscard,
|
||
|
|
}: {
|
||
|
|
open: boolean;
|
||
|
|
onOpenChange: (open: boolean) => void;
|
||
|
|
onStay: () => void;
|
||
|
|
onDiscard: () => void;
|
||
|
|
}) {
|
||
|
|
return (
|
||
|
|
<AlertDialog open={open} onOpenChange={onOpenChange}>
|
||
|
|
<AlertDialogContent>
|
||
|
|
<AlertDialogHeader>
|
||
|
|
<AlertDialogTitle>Switch sections without saving?</AlertDialogTitle>
|
||
|
|
<AlertDialogDescription>
|
||
|
|
You have unsaved settings changes. Save before switching sections, or discard your edits to continue.
|
||
|
|
</AlertDialogDescription>
|
||
|
|
</AlertDialogHeader>
|
||
|
|
<AlertDialogFooter>
|
||
|
|
<AlertDialogCancel onClick={onStay}>
|
||
|
|
Stay
|
||
|
|
</AlertDialogCancel>
|
||
|
|
<AlertDialogAction onClick={onDiscard}>
|
||
|
|
Discard changes
|
||
|
|
</AlertDialogAction>
|
||
|
|
</AlertDialogFooter>
|
||
|
|
</AlertDialogContent>
|
||
|
|
</AlertDialog>
|
||
|
|
);
|
||
|
|
}
|