feat: Enhance EditProjectPage with translation support and refactor ProjectForm to use forwardRef

This commit is contained in:
2025-09-29 19:32:08 +02:00
parent e68b185aeb
commit fc5f0fd39a
3 changed files with 49 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
"use client";
import { useState, useEffect } from "react";
import { useState, useEffect, forwardRef, useImperativeHandle } from "react";
import { useRouter } from "next/navigation";
import { Card, CardHeader, CardContent } from "@/components/ui/Card";
import Button from "@/components/ui/Button";
@@ -8,7 +8,7 @@ import { Input } from "@/components/ui/Input";
import { formatDateForInput } from "@/lib/utils";
import { useTranslation } from "@/lib/i18n";
export default function ProjectForm({ initialData = null }) {
const ProjectForm = forwardRef(function ProjectForm({ initialData = null }, ref) {
const { t } = useTranslation();
const [form, setForm] = useState({
contract_id: "",
@@ -81,8 +81,7 @@ export default function ProjectForm({ initialData = null }) {
setForm({ ...form, [e.target.name]: e.target.value });
}
async function handleSubmit(e) {
e.preventDefault();
async function saveProject() {
setLoading(true);
try {
@@ -112,6 +111,16 @@ export default function ProjectForm({ initialData = null }) {
setLoading(false);
}
}
async function handleSubmit(e) {
e.preventDefault();
await saveProject();
}
// Expose save function to parent component
useImperativeHandle(ref, () => ({
saveProject
}));
return (
<Card>
<CardHeader>
@@ -438,4 +447,6 @@ export default function ProjectForm({ initialData = null }) {
</CardContent>
</Card>
);
}
});
export default ProjectForm;