Skip to content

Commit 9f7f6d6

Browse files
committed
feat: more cautious redeploy dialog
1 parent 0fdf79a commit 9f7f6d6

File tree

3 files changed

+92
-55
lines changed

3 files changed

+92
-55
lines changed

apps/postgres-new/components/deploy/redeploy-alert-dialog.tsx

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { TriangleAlert } from 'lucide-react'
2+
import { useState } from 'react'
3+
import {
4+
Dialog,
5+
DialogContent,
6+
DialogDescription,
7+
DialogFooter,
8+
DialogHeader,
9+
DialogTitle,
10+
} from '~/components/ui/dialog'
11+
import { Input } from '~/components/ui/input'
12+
import { Database } from '~/lib/db'
13+
import { Button } from '../ui/button'
14+
15+
export type RedeployDialogProps = {
16+
database: Database
17+
isOpen: boolean
18+
onOpenChange: (open: boolean) => void
19+
onConfirm: () => void
20+
onCancel: () => void
21+
}
22+
23+
export function RedeployDialog({
24+
database,
25+
isOpen,
26+
onOpenChange,
27+
onConfirm,
28+
onCancel,
29+
}: RedeployDialogProps) {
30+
const [confirmedValue, setConfirmedValue] = useState('')
31+
return (
32+
<Dialog open={isOpen} onOpenChange={onOpenChange}>
33+
<DialogContent showCloseButton={false}>
34+
<DialogHeader>
35+
<DialogTitle className="mb-4">Confirm redeploy of {database.name}</DialogTitle>
36+
<DialogDescription className="flex flex-col gap-4">
37+
<div className="flex gap-2 items-center rounded-md border-destructive bg-destructive/25 p-2">
38+
<TriangleAlert size={16} />
39+
This action cannot be undone.
40+
</div>
41+
<p>
42+
Redeploying will completely overwrite the existing deployed database with the latest
43+
version of your browser database. Existing schema and data in the deployed database
44+
will be lost.
45+
</p>
46+
<div className="my-1 border-b" />
47+
<div className="flex flex-col gap-3">
48+
<p>
49+
Type <strong>{database.name}</strong> to confirm.
50+
</p>
51+
<Input
52+
className="placeholder:text-primary/25"
53+
placeholder="Type the database name here"
54+
value={confirmedValue}
55+
onChange={(e) => setConfirmedValue(e.target.value)}
56+
/>
57+
</div>
58+
</DialogDescription>
59+
</DialogHeader>
60+
<DialogFooter className="mt-1">
61+
<Button
62+
variant="secondary"
63+
onClick={() => {
64+
onOpenChange(false)
65+
onCancel()
66+
}}
67+
>
68+
Cancel
69+
</Button>
70+
<Button
71+
className="bg-destructive text-primary hover:text-secondary"
72+
onClick={() => {
73+
onConfirm()
74+
}}
75+
disabled={confirmedValue !== database.name}
76+
>
77+
I understand, overwrite the database
78+
</Button>
79+
</DialogFooter>
80+
</DialogContent>
81+
</Dialog>
82+
)
83+
}

apps/postgres-new/components/sidebar.tsx

+9-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { cn } from '~/lib/utils'
3535
import { useApp } from './app-provider'
3636
import { DeployDialog } from './deploy/deploy-dialog'
3737
import { IntegrationDialog } from './deploy/integration-dialog'
38-
import { RedeployAlertDialog } from './deploy/redeploy-alert-dialog'
38+
import { RedeployDialog } from './deploy/redeploy-dialog'
3939
import { LiveShareIcon } from './live-share-icon'
4040
import SignInButton from './sign-in-button'
4141
import { SupabaseIcon } from './supabase-icon'
@@ -330,7 +330,7 @@ function DatabaseMenuItem({ database, isActive }: DatabaseMenuItemProps) {
330330

331331
const [isIntegrationDialogOpen, setIsIntegrationDialogOpen] = useState(false)
332332
const [isDeployDialogOpen, setIsDeployDialogOpen] = useState(false)
333-
const [isRedeployAlertDialogOpen, setIsRedeployAlertDialogOpen] = useState(false)
333+
const [isRedeployDialogOpen, setIsRedeployDialogOpen] = useState(false)
334334
const [deployUrl, setDeployUrl] = useState<string | null>(null)
335335

336336
const [isDeploying, setIsDeploying] = useState(false)
@@ -366,9 +366,10 @@ function DatabaseMenuItem({ database, isActive }: DatabaseMenuItemProps) {
366366
router.push(deployUrl)
367367
}}
368368
/>
369-
<RedeployAlertDialog
370-
isOpen={isRedeployAlertDialogOpen}
371-
onOpenChange={setIsRedeployAlertDialogOpen}
369+
<RedeployDialog
370+
database={database}
371+
isOpen={isRedeployDialogOpen}
372+
onOpenChange={setIsRedeployDialogOpen}
372373
onConfirm={() => {
373374
router.push(deployUrl!)
374375
}}
@@ -526,8 +527,10 @@ function DatabaseMenuItem({ database, isActive }: DatabaseMenuItemProps) {
526527
e.preventDefault()
527528
if (!supabaseIntegration) {
528529
setIsIntegrationDialogOpen(true)
529-
} else {
530+
} else if (!database.isDeployed) {
530531
setIsDeployDialogOpen(true)
532+
} else {
533+
setIsRedeployDialogOpen(true)
531534
}
532535
}}
533536
>

0 commit comments

Comments
 (0)