- Integrated `next-intl` for toast messages and locale handling in various components, including `Providers`, `CanvasUserMenu`, and `CreditOverview`. - Replaced hardcoded strings with translation keys to enhance localization capabilities. - Updated `RootLayout` to dynamically set the language attribute based on the user's locale. - Ensured consistent user feedback through localized toast messages in actions such as sign-out, canvas operations, and billing notifications.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import { authClient } from "@/lib/auth-client";
|
|
import { useMutation } from "convex/react";
|
|
import { useAuthQuery } from "@/hooks/use-auth-query";
|
|
import { api } from "@/convex/_generated/api";
|
|
import { useEffect, useRef } from "react";
|
|
import { useTranslations } from "next-intl";
|
|
import { toast } from "@/lib/toast";
|
|
|
|
/**
|
|
* Initialisiert die Credit-Balance für neue User.
|
|
* Wird einmal im Layout eingebunden und sorgt dafür,
|
|
* dass jeder eingeloggte User eine Balance + Free-Subscription hat.
|
|
*/
|
|
export function InitUser() {
|
|
const t = useTranslations('toasts');
|
|
const { data: session } = authClient.useSession();
|
|
|
|
const balance = useAuthQuery(api.credits.getBalance);
|
|
const initBalance = useMutation(api.credits.initBalance);
|
|
const initStartedRef = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (
|
|
!session?.user ||
|
|
!balance ||
|
|
balance.balance !== 0 ||
|
|
balance.monthlyAllocation !== 0
|
|
) {
|
|
return;
|
|
}
|
|
if (initStartedRef.current) return;
|
|
initStartedRef.current = true;
|
|
|
|
void initBalance()
|
|
.then(() => {
|
|
toast.success(t('auth.initialSetupTitle'), t('auth.initialSetupDesc'));
|
|
})
|
|
.catch(() => {
|
|
initStartedRef.current = false;
|
|
});
|
|
}, [t, session?.user, balance, initBalance]);
|
|
|
|
return null;
|
|
}
|