"use client"; import { FC, useEffect } from "react"; import { UserProfile } from "../lib/db-types"; import { updateUserProfile } from "../lib/actions/userProfileActions"; import { useFormState, useFormStatus } from "react-dom"; import { useLocale, useTranslations } from "next-intl"; import Link from "next/link"; export type AccountFormProps = { profile: UserProfile | null; } type FormFieldsProps = { profile: UserProfile | null; errors: any; success: boolean; message: string | null; } const FormFields: FC = ({ profile, errors, success, message }) => { const { pending } = useFormStatus(); const t = useTranslations("account-form"); const locale = useLocale(); return ( <>
{errors?.firstName && errors.firstName.map((error: string) => (

{error}

))}
{errors?.lastName && errors.lastName.map((error: string) => (

{error}

))}
{errors?.address && errors.address.map((error: string) => (

{error}

))}
{errors?.iban && errors.iban.map((error: string) => (

{error}

))}
{message && !success && (

{message}

)} {success && (

{t("success-message")}

)}
{t("cancel-button")}
); }; export const AccountForm: FC = ({ profile }) => { const initialState = { message: null, errors: {}, success: false }; const [state, dispatch] = useFormState(updateUserProfile, initialState); const t = useTranslations("account-form"); useEffect(() => { if (state.success) { // Show success message or toast notification // For now, we'll just log it console.log("Profile updated successfully"); } }, [state.success]); return (

{t("title")}

); }; export const AccountFormSkeleton: FC = () => { return (
); };