1
1
"use client" ;
2
2
3
- import { deletePasswordItem } from "@/app/actions" ;
3
+ import { deletePasswordItem , getPasswords } from "@/app/actions" ;
4
4
import { Button } from "@/components/ui/button" ;
5
5
import { Input } from "@/components/ui/input" ;
6
6
import { ScrollArea } from "@/components/ui/scroll-area" ;
@@ -63,13 +63,14 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
63
63
const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
64
64
const [ filteredEntries , setFilteredEntries ] = useState < PasswordEntry [ ] > ( [ ] ) ;
65
65
const [ passwords , setPasswords ] = useState < PasswordEntry [ ] > ( [ ] ) ;
66
+ const [ passwordItems , setPasswordItems ] = useState ( user ?. passwordItems )
66
67
67
68
useEffect ( ( ) => {
68
69
if ( ! clerkUser ) return ;
69
70
70
- if ( ! user ?. passwordItems ) return ;
71
+ if ( ! user ?. passwordItems || ! passwordItems ) return ;
71
72
72
- const decryptedPasswords = user . passwordItems
73
+ const decryptedPasswords = passwordItems
73
74
. map ( ( item ) => ( {
74
75
id : item . id ,
75
76
name : decrypt ( item . username , clerkUser ) ,
@@ -85,7 +86,7 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
85
86
) ;
86
87
87
88
setPasswords ( decryptedPasswords ) ;
88
- } , [ user ?. passwordItems , clerkUser ] ) ;
89
+ } , [ user ?. passwordItems , clerkUser , passwordItems ] ) ;
89
90
90
91
const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
91
92
setSearchQuery ( e . target . value ) ;
@@ -211,8 +212,8 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
211
212
onClick = { async ( ) => {
212
213
try {
213
214
await deletePasswordItem ( password . id ) ;
214
- router . refresh ( ) ;
215
-
215
+ const updatedItems = await getPasswords ( user ?. id as string )
216
+ setPasswordItems ( updatedItems ?. passwordItems ) ;
216
217
if ( selectedEntry ?. id === password . id ) {
217
218
setSelectedEntry ( null ) ;
218
219
}
@@ -281,10 +282,11 @@ export const VaultPage: React.FC<VaultPageProps> = ({ user }) => {
281
282
) }
282
283
< CreatePasswordDialog
283
284
open = { isCreateDialogOpen }
284
- onClose = { ( ) => {
285
+ onClose = { async ( ) => {
285
286
setIsCreateDialogOpen ( false ) ;
286
- router . refresh ( ) ;
287
287
setSelectedEntry ( null ) ;
288
+ const userWithPasswords = await getPasswords ( user ?. id as string )
289
+ setPasswordItems ( userWithPasswords ?. passwordItems )
288
290
} }
289
291
/>
290
292
</ div >
0 commit comments