feat: Enhance EditProjectPage with translation support and refactor ProjectForm to use forwardRef
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user