@@ -17,38 +17,24 @@ import { useAction } from 'next-safe-action/hooks';
1717import { useQueryState } from 'nuqs' ;
1818import { useForm } from 'react-hook-form' ;
1919import { toast } from 'sonner' ;
20+ import { useSWRConfig } from 'swr' ;
2021import type { z } from 'zod' ;
2122
2223export function CreateRisk ( { assignees } : { assignees : ( Member & { user : User } ) [ ] } ) {
23- // Get the same query parameters as the table
24- const [ search ] = useQueryState ( 'search' ) ;
25- const [ page ] = useQueryState ( 'page' , {
26- defaultValue : 1 ,
27- parse : Number . parseInt ,
28- } ) ;
29- const [ pageSize ] = useQueryState ( 'pageSize' , {
30- defaultValue : 10 ,
31- parse : Number ,
32- } ) ;
33- const [ status ] = useQueryState < RiskStatus | null > ( 'status' , {
34- defaultValue : null ,
35- parse : ( value ) => value as RiskStatus | null ,
36- } ) ;
37- const [ department ] = useQueryState < Departments | null > ( 'department' , {
38- defaultValue : null ,
39- parse : ( value ) => value as Departments | null ,
40- } ) ;
41- const [ assigneeId ] = useQueryState < string | null > ( 'assigneeId' , {
42- defaultValue : null ,
43- parse : ( value ) => value ,
44- } ) ;
24+ const { mutate } = useSWRConfig ( ) ;
4525
4626 const [ _ , setCreateRiskSheet ] = useQueryState ( 'create-risk-sheet' ) ;
4727
4828 const createRisk = useAction ( createRiskAction , {
4929 onSuccess : async ( ) => {
5030 toast . success ( 'Risk created successfully' ) ;
5131 setCreateRiskSheet ( null ) ;
32+ // Invalidate all risks SWR caches (any key starting with 'risks')
33+ mutate (
34+ ( key ) => Array . isArray ( key ) && key [ 0 ] === 'risks' ,
35+ undefined ,
36+ { revalidate : true } ,
37+ ) ;
5238 } ,
5339 onError : ( ) => {
5440 toast . error ( 'Failed to create risk' ) ;
0 commit comments