diff --git a/src/app/projects/[id]/edit/page.js b/src/app/projects/[id]/edit/page.js
index 5857a1d..0bff6de 100644
--- a/src/app/projects/[id]/edit/page.js
+++ b/src/app/projects/[id]/edit/page.js
@@ -1,6 +1,6 @@
"use client";
-import { useEffect, useState } from "react";
+import { useEffect, useState, useRef } from "react";
import { useParams } from "next/navigation";
import ProjectForm from "@/components/ProjectForm";
import PageContainer from "@/components/ui/PageContainer";
@@ -8,6 +8,7 @@ import PageHeader from "@/components/ui/PageHeader";
import Button from "@/components/ui/Button";
import Link from "next/link";
import { LoadingState } from "@/components/ui/States";
+import { useTranslation } from "@/lib/i18n";
export default function EditProjectPage() {
const params = useParams();
@@ -15,6 +16,8 @@ export default function EditProjectPage() {
const [project, setProject] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
+ const { t } = useTranslation();
+ const formRef = useRef();
useEffect(() => {
const fetchProject = async () => {
@@ -62,10 +65,30 @@ export default function EditProjectPage() {
return (
+
@@ -99,14 +122,14 @@ export default function EditProjectPage() {
d="M15 19l-7-7 7-7"
/>
- Back to Projects
+ {t('projects.backToProjects')}
}
/>
);
diff --git a/src/components/ProjectForm.js b/src/components/ProjectForm.js
index 41d73b6..e0373d4 100644
--- a/src/components/ProjectForm.js
+++ b/src/components/ProjectForm.js
@@ -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 (
@@ -438,4 +447,6 @@ export default function ProjectForm({ initialData = null }) {
);
-}
+});
+
+export default ProjectForm;
diff --git a/src/lib/i18n.js b/src/lib/i18n.js
index 09328c4..2904848 100644
--- a/src/lib/i18n.js
+++ b/src/lib/i18n.js
@@ -135,6 +135,8 @@ const translations = {
newProject: "Nowy projekt",
editProject: "Edytuj projekt",
deleteProject: "Usuń projekt",
+ editing: "Edycja",
+ backToProjects: "Powrót do projektów",
projectName: "Nazwa projektu",
city: "Miasto",
address: "Adres",
@@ -687,6 +689,8 @@ const translations = {
newProject: "New Project",
editProject: "Edit Project",
deleteProject: "Delete Project",
+ editing: "Editing",
+ backToProjects: "Back to Projects",
projectName: "Project Name",
city: "City",
address: "Address",