@@ -14,6 +14,7 @@ import { useToast } from '@/hooks/use-toast';
1414import { Loader2 } from 'lucide-react' ;
1515import type { CompanyWithDetails } from '@/lib/actions/companies' ;
1616import { investInCompany } from '@/lib/actions/companies' ;
17+ import { useRouter } from 'next/navigation' ;
1718
1819interface InvestDialogProps {
1920 company : CompanyWithDetails ;
@@ -26,8 +27,9 @@ const formSchema = z.object({
2627
2728export function InvestDialog ( { company, children } : InvestDialogProps ) {
2829 const [ open , setOpen ] = useState ( false ) ;
29- const { cash } = usePortfolio ( ) ;
30+ const { cash, refreshPortfolio } = usePortfolio ( ) ;
3031 const { toast } = useToast ( ) ;
32+ const router = useRouter ( ) ;
3133 const form = useForm < z . infer < typeof formSchema > > ( {
3234 resolver : zodResolver ( formSchema ) ,
3335 defaultValues : {
@@ -44,6 +46,8 @@ export function InvestDialog({ company, children }: InvestDialogProps) {
4446 toast ( { variant : 'destructive' , title : 'Erreur' , description : result . error } ) ;
4547 } else if ( result . success ) {
4648 toast ( { title : 'Succès' , description : result . success } ) ;
49+ await refreshPortfolio ( ) ;
50+ router . refresh ( ) ;
4751 setOpen ( false ) ;
4852 form . reset ( ) ;
4953 }
@@ -97,7 +101,7 @@ export function InvestDialog({ company, children }: InvestDialogProps) {
97101 < Button type = "button" variant = "secondary" onClick = { ( ) => setOpen ( false ) } > Annuler</ Button >
98102 < Button type = "submit" disabled = { form . formState . isSubmitting || amount > cash || ! form . formState . isValid } >
99103 { form . formState . isSubmitting && < Loader2 className = "mr-2 h-4 w-4 animate-spin" /> }
100- Investir ${ amount . toFixed ( 2 ) }
104+ Investir ${ amount > 0 ? amount . toFixed ( 2 ) : '0.00' }
101105 </ Button >
102106 </ DialogFooter >
103107 </ form >
0 commit comments