Skip to content

Commit 77cd541

Browse files
par contre dans une bonnes parties des fonctionalitée et pages, la Valeu
1 parent 6ae1a90 commit 77cd541

File tree

7 files changed

+26
-9
lines changed

7 files changed

+26
-9
lines changed

src/components/add-company-cash-dialog.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { usePortfolio } from '@/context/portfolio-context';
1212
import { useToast } from '@/hooks/use-toast';
1313
import { Loader2 } from 'lucide-react';
1414
import { addCashToCompany } from '@/lib/actions/companies';
15+
import { useRouter } from 'next/navigation';
1516

1617
interface AddCompanyCashDialogProps {
1718
companyId: number;
@@ -24,8 +25,9 @@ const formSchema = z.object({
2425

2526
export function AddCompanyCashDialog({ companyId, children }: AddCompanyCashDialogProps) {
2627
const [open, setOpen] = useState(false);
27-
const { cash } = usePortfolio();
28+
const { cash, refreshPortfolio } = usePortfolio();
2829
const { toast } = useToast();
30+
const router = useRouter();
2931
const form = useForm<z.infer<typeof formSchema>>({
3032
resolver: zodResolver(formSchema),
3133
defaultValues: {
@@ -41,6 +43,8 @@ export function AddCompanyCashDialog({ companyId, children }: AddCompanyCashDial
4143
toast({ variant: 'destructive', title: 'Erreur', description: result.error });
4244
} else if (result.success) {
4345
toast({ title: 'Succès', description: result.success });
46+
await refreshPortfolio();
47+
router.refresh();
4448
setOpen(false);
4549
form.reset();
4650
}

src/components/create-company-dialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const companyFormSchema = z.object({
3939
export function CreateCompanyDialog() {
4040
const [open, setOpen] = useState(false);
4141
const { toast } = useToast();
42-
const { cash } = usePortfolio();
42+
const { cash, refreshPortfolio } = usePortfolio();
4343
const router = useRouter();
4444
const creationCost = 1000;
4545

@@ -59,6 +59,7 @@ export function CreateCompanyDialog() {
5959
toast({ variant: 'destructive', title: "Échec de la création", description: result.error });
6060
} else if (result.success) {
6161
toast({ title: "Succès", description: result.success });
62+
await refreshPortfolio();
6263
setOpen(false);
6364
form.reset();
6465
router.refresh();

src/components/invest-dialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { useToast } from '@/hooks/use-toast';
1414
import { Loader2 } from 'lucide-react';
1515
import type { CompanyWithDetails } from '@/lib/actions/companies';
1616
import { investInCompany } from '@/lib/actions/companies';
17+
import { useRouter } from 'next/navigation';
1718

1819
interface InvestDialogProps {
1920
company: CompanyWithDetails;
@@ -26,8 +27,9 @@ const formSchema = z.object({
2627

2728
export 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>

src/components/place-bet-dialog.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { placeBet } from '@/lib/actions/markets';
1515
import { useToast } from '@/hooks/use-toast';
1616
import { Loader2 } from 'lucide-react';
1717
import type { MarketWithOutcomes } from '@/lib/actions/markets';
18+
import { useRouter } from 'next/navigation';
1819

1920
interface PlaceBetDialogProps {
2021
market: MarketWithOutcomes;
@@ -28,8 +29,9 @@ const formSchema = z.object({
2829

2930
export function PlaceBetDialog({ market, children }: PlaceBetDialogProps) {
3031
const [open, setOpen] = useState(false);
31-
const { cash } = usePortfolio();
32+
const { cash, refreshPortfolio } = usePortfolio();
3233
const { toast } = useToast();
34+
const router = useRouter();
3335
const form = useForm<z.infer<typeof formSchema>>({
3436
resolver: zodResolver(formSchema),
3537
defaultValues: {
@@ -46,6 +48,8 @@ export function PlaceBetDialog({ market, children }: PlaceBetDialogProps) {
4648
toast({ variant: 'destructive', title: 'Erreur', description: result.error });
4749
} else if (result.success) {
4850
toast({ title: 'Succès', description: result.success });
51+
await refreshPortfolio();
52+
router.refresh();
4953
setOpen(false);
5054
form.reset();
5155
}
@@ -119,7 +123,7 @@ export function PlaceBetDialog({ market, children }: PlaceBetDialogProps) {
119123
<Button type="button" variant="secondary" onClick={() => setOpen(false)}>Annuler</Button>
120124
<Button type="submit" disabled={form.formState.isSubmitting || amount > cash || !form.formState.isValid}>
121125
{form.formState.isSubmitting && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
122-
Parier ${amount.toFixed(2)}
126+
Parier ${amount > 0 ? amount.toFixed(2) : '0.00'}
123127
</Button>
124128
</DialogFooter>
125129
</form>

src/context/portfolio-context.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ interface PortfolioContextType {
7474
updateUserProfile: (data: ProfileUpdateInput) => Promise<void>;
7575
buyMiningRig: (rigId: string) => Promise<void>;
7676
claimRewardsNow: () => Promise<void>;
77+
refreshPortfolio: () => Promise<void>;
7778
}
7879

7980
const PortfolioContext = createContext<PortfolioContextType | undefined>(undefined);
@@ -213,6 +214,7 @@ export const PortfolioProvider = ({ children }: { children: ReactNode }) => {
213214
loading: authLoading || loading,
214215
buyAsset, sellAsset, getHoldingQuantity, updateUserProfile, buyMiningRig,
215216
claimRewardsNow,
217+
refreshPortfolio: fetchPortfolio,
216218
};
217219

218220
return (

src/lib/actions/companies.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ export async function createCompany(values: z.infer<typeof createCompanySchema>)
6464

6565
revalidatePath('/companies');
6666
revalidatePath('/portfolio');
67+
revalidatePath('/profile');
68+
revalidatePath('/');
6769
return result;
6870
} catch (error: any) {
6971
// Check for unique constraint violation
@@ -429,6 +431,7 @@ export async function addCashToCompany(companyId: number, amount: number): Promi
429431
revalidatePath(`/companies/${companyId}`);
430432
revalidatePath('/portfolio');
431433
revalidatePath('/profile');
434+
revalidatePath('/');
432435
return result;
433436

434437
} catch (error: any) {

src/lib/actions/markets.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ export async function ensureAiMarkets() {
6565
);
6666
});
6767
}
68-
// This was causing an error because it was called during render.
69-
// The page is dynamic anyway, so it will get fresh data on the next request.
70-
// revalidatePath('/markets');
68+
revalidatePath('/markets');
7169
} catch (error) {
7270
console.error("Error ensuring AI markets:", error);
7371
// Don't throw, just log the error. The page can still render with fewer markets.
@@ -186,6 +184,7 @@ export async function placeBet(outcomeId: number, marketId: number, amount: numb
186184
revalidatePath('/markets');
187185
revalidatePath('/portfolio'); // For cash update
188186
revalidatePath('/profile'); // For cash update
187+
revalidatePath('/'); // For cash update in dashboard
189188
return result;
190189

191190
} catch (error: any) {

0 commit comments

Comments
 (0)