749 lines
28 KiB
TypeScript
749 lines
28 KiB
TypeScript
import { ArrowRight, Check, Leaf, Plus, Save, Trash2 } from "lucide-react";
|
||
import { useEffect, useMemo, useState, type FormEvent } from "react";
|
||
import { Link, useNavigate, useParams } from "react-router";
|
||
import {
|
||
Button,
|
||
Card,
|
||
ErrorBanner,
|
||
Field,
|
||
Input,
|
||
PageTitle,
|
||
Select,
|
||
} from "../components/Ui";
|
||
import { ApiError, api } from "../lib/api";
|
||
import type { ProjectDetails, ReferenceItem } from "../types";
|
||
import {
|
||
buildInnovationPayload,
|
||
InnovationDetailsFields,
|
||
} from "../components/InnovationDetailsFields";
|
||
import { isMoneyField, unitHint } from "../lib/fieldUnits";
|
||
import { ProjectChildrenPage } from "./ProjectChildrenPage";
|
||
import { FormTabs } from "../components/FormTabs";
|
||
import { useDeploymentProfile } from "../deployment/DeploymentProfileContext";
|
||
|
||
const greenFields = [
|
||
["pollutionBefore", "آلایندگی قبل"],
|
||
["pollutionAfter", "آلایندگی بعد"],
|
||
["wasteBefore", "ضایعات قبل"],
|
||
["wasteAfter", "ضایعات بعد"],
|
||
["waterRecoveryBefore", "بازیابی آب قبل"],
|
||
["waterRecoveryAfter", "بازیابی آب بعد"],
|
||
["feedConsumptionBefore", "مصرف خوراک قبل"],
|
||
["feedConsumptionAfter", "مصرف خوراک بعد"],
|
||
["electricityConsumptionBefore", "مصرف برق قبل"],
|
||
["electricityConsumptionAfter", "مصرف برق بعد"],
|
||
["fuelConsumptionBefore", "مصرف سوخت قبل"],
|
||
["fuelConsumptionAfter", "مصرف سوخت بعد"],
|
||
] as const;
|
||
|
||
export function ProjectFormPage() {
|
||
const navigate = useNavigate();
|
||
const { profile } = useDeploymentProfile();
|
||
const { id } = useParams();
|
||
const editing = Boolean(id);
|
||
const [themes, setThemes] = useState<ReferenceItem[]>([]);
|
||
const [allValues, setAllValues] = useState<ReferenceItem[]>([]);
|
||
const [values, setValues] = useState<ReferenceItem[]>([]);
|
||
const [themeId, setThemeId] = useState("");
|
||
const [valueId, setValueId] = useState("");
|
||
const [status, setStatus] = useState("0");
|
||
const [innovationType, setInnovationType] = useState("4");
|
||
const [innovationDetails, setInnovationDetails] = useState<
|
||
Record<string, string>
|
||
>({});
|
||
const [technologyParameters, setTechnologyParameters] = useState<
|
||
Array<{ title: string; domesticValue: string; foreignValue: string }>
|
||
>([]);
|
||
const [exports, setExports] = useState<
|
||
Array<{
|
||
persianYear: string;
|
||
season: string;
|
||
exportVolume: string;
|
||
exportedCapacity: string;
|
||
importVolumeBefore: string;
|
||
importVolumeAfter: string;
|
||
pricePerUnit: string;
|
||
exportRevenueBefore: string;
|
||
exportRevenueAfter: string;
|
||
}>
|
||
>([]);
|
||
const [green, setGreen] = useState<Record<string, string>>({});
|
||
const [busy, setBusy] = useState(false);
|
||
const [error, setError] = useState("");
|
||
const [fieldErrors, setFieldErrors] = useState<Record<string, string>>({});
|
||
const [details, setDetails] = useState<ProjectDetails | null>(null);
|
||
const [loading, setLoading] = useState(editing);
|
||
const [activeTab, setActiveTab] = useState("base");
|
||
|
||
useEffect(() => {
|
||
void Promise.all([
|
||
api<ReferenceItem[]>("/api/v1/strategic-themes"),
|
||
api<ReferenceItem[]>("/api/v1/innovation-values"),
|
||
]).then(([themeItems, valueItems]) => { setThemes(themeItems); setAllValues(valueItems); })
|
||
.catch((e) => setError(e.message));
|
||
}, []);
|
||
useEffect(() => {
|
||
if (!editing) return;
|
||
setLoading(true);
|
||
void api<ProjectDetails>(`/api/v1/projects/${id}`)
|
||
.then((project) => {
|
||
setDetails(project);
|
||
setThemeId(project.strategicThemeId);
|
||
setValueId(project.innovationValueId);
|
||
setStatus(String(project.status));
|
||
setInnovationType(String(project.innovationType));
|
||
const detail =
|
||
project.digitalDetails ??
|
||
project.processDetails ??
|
||
project.productDetails ??
|
||
project.domesticDetails ??
|
||
{};
|
||
setInnovationDetails(stringValues(detail));
|
||
setGreen(
|
||
stringValues(project.greenDetails ?? {}, "standardRegulations"),
|
||
);
|
||
})
|
||
.catch((e) => setError(e.message))
|
||
.finally(() => setLoading(false));
|
||
}, [editing, id]);
|
||
useEffect(() => {
|
||
setValues(themeId ? allValues.filter(x => x.strategicThemeId === themeId) : []);
|
||
}, [themeId, allValues]);
|
||
const progress = useMemo(
|
||
() =>
|
||
[themeId, valueId].filter(Boolean).length +
|
||
Object.values(green).filter(Boolean).length,
|
||
[themeId, valueId, green],
|
||
);
|
||
|
||
async function submit(event: FormEvent<HTMLFormElement>) {
|
||
event.preventDefault();
|
||
setBusy(true);
|
||
setError("");
|
||
setFieldErrors({});
|
||
const form = new FormData(event.currentTarget);
|
||
const greenDetails = Object.fromEntries(
|
||
greenFields.map(([key]) => [key, green[key] || null]),
|
||
);
|
||
const general = Object.fromEntries(
|
||
[
|
||
"investment",
|
||
"operationalCost",
|
||
"innovationDegree",
|
||
"executingPerson",
|
||
"excellentObserver",
|
||
"projectType",
|
||
"observer",
|
||
"executor",
|
||
"executivePhase",
|
||
"businessStatus",
|
||
"plannedProgressPercent",
|
||
"actualProgressPercent",
|
||
"renewedDurationDays",
|
||
"importance",
|
||
"relatedCompany",
|
||
"preInnovationCost",
|
||
"innovationCost",
|
||
"productionCapacityBefore",
|
||
"productionCapacityAfter",
|
||
"incomeBefore",
|
||
"incomeAfter",
|
||
"doneDate",
|
||
].map((key) => {
|
||
const value = form.get(key);
|
||
return [
|
||
key,
|
||
[
|
||
"plannedProgressPercent",
|
||
"actualProgressPercent",
|
||
"renewedDurationDays",
|
||
].includes(key) && value
|
||
? Number(value)
|
||
: value || null,
|
||
];
|
||
}),
|
||
);
|
||
try {
|
||
const data = {
|
||
projectNumber: form.get("projectNumber"),
|
||
title: form.get("title"),
|
||
description: form.get("description") || null,
|
||
innovationType: Number(innovationType),
|
||
startDate: form.get("startDate"),
|
||
endDate: form.get("endDate") || null,
|
||
approvedBudget: form.get("approvedBudget") || null,
|
||
budgetSpent: form.get("budgetSpent") || null,
|
||
rating: form.get("rating") ? Number(form.get("rating")) : null,
|
||
strategicThemeId: themeId,
|
||
innovationValueId: valueId,
|
||
status: Number(status),
|
||
general,
|
||
greenDetails:
|
||
innovationType === "4"
|
||
? {
|
||
...greenDetails,
|
||
standardRegulations: form.get("standardRegulations") || null,
|
||
}
|
||
: null,
|
||
...buildInnovationPayload(Number(innovationType), innovationDetails),
|
||
...(editing
|
||
? {}
|
||
: {
|
||
technologyParameters: technologyParameters.map((x) => ({ ...x })),
|
||
exports: exports.map((x) => ({
|
||
...x,
|
||
persianYear: Number(x.persianYear),
|
||
exportVolume: Number(x.exportVolume),
|
||
})),
|
||
}),
|
||
...(editing ? { rowVersion: details?.rowVersion } : {}),
|
||
};
|
||
await api(editing ? `/api/v1/projects/${id}` : "/api/v1/projects", {
|
||
method: editing ? "PUT" : "POST",
|
||
body: JSON.stringify(data),
|
||
});
|
||
navigate("/admin/projects", { replace: true });
|
||
} catch (reason) {
|
||
if (reason instanceof ApiError) {
|
||
setError(reason.message);
|
||
setFieldErrors(
|
||
Object.fromEntries(
|
||
(reason.problem.errors ?? []).map((x) => [x.fieldCode, x.message]),
|
||
),
|
||
);
|
||
} else setError("ذخیره پروژه ناموفق بود.");
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}
|
||
|
||
const rootValue = (key: keyof ProjectDetails) =>
|
||
details?.[key] == null ? "" : String(details[key]);
|
||
const generalValue = (key: string) =>
|
||
details?.general?.[key] == null ? "" : String(details.general[key]);
|
||
if (loading)
|
||
return (
|
||
<Card>
|
||
<p>در حال دریافت پروژه…</p>
|
||
</Card>
|
||
);
|
||
return (
|
||
<>
|
||
<PageTitle
|
||
title={editing ? "ویرایش پروژه" : "پروژه جدید"}
|
||
description="اطلاعات عمومی و جزئیات typed پروژه با کنترل همزمانی ذخیره میشوند"
|
||
action={
|
||
<Link to="/admin/projects" className="text-link">
|
||
<ArrowRight size={17} />
|
||
بازگشت
|
||
</Link>
|
||
}
|
||
/>
|
||
{error && <ErrorBanner message={error} />}
|
||
{editing && <FormTabs active={activeTab} onChange={setActiveTab} tabs={[
|
||
{ id: "base", label: "اطلاعات پایه" },
|
||
{ id: "general", label: "اطلاعات تکمیلی" },
|
||
{ id: "details", label: "جزئیات نوآوری" },
|
||
{ id: "children", label: "اطلاعات وابسته" },
|
||
]}/>}
|
||
<form onSubmit={submit} className="form-stack" key={id ?? "new"}>
|
||
<Card className={editing && activeTab !== "base" ? "tab-hidden" : ""}>
|
||
<div className="section-heading">
|
||
<span>۰۱</span>
|
||
<div>
|
||
<h3>اطلاعات پایه پروژه</h3>
|
||
<p>شناسهها و روابط مرجع با ID ذخیره میشوند، نه عنوان.</p>
|
||
</div>
|
||
</div>
|
||
<div className="form-grid cols-3">
|
||
<Field label="شماره پروژه" error={fieldErrors.projectNumber}>
|
||
<Input
|
||
name="projectNumber"
|
||
required
|
||
placeholder="PRJ-1405-001"
|
||
defaultValue={rootValue("projectNumber")}
|
||
/>
|
||
</Field>
|
||
<Field label="عنوان پروژه" error={fieldErrors.title}>
|
||
<Input name="title" required defaultValue={rootValue("title")} />
|
||
</Field>
|
||
<Field
|
||
label="نوع نوآوری"
|
||
hint={
|
||
editing ? "نوع نوآوری پس از ایجاد قابل تغییر نیست" : undefined
|
||
}
|
||
>
|
||
<Select
|
||
value={innovationType}
|
||
disabled={editing}
|
||
onChange={(e) => {
|
||
setInnovationType(e.target.value);
|
||
setInnovationDetails({});
|
||
}}
|
||
>
|
||
<option value="1">نوآوری دیجیتال</option>
|
||
<option value="2">نوآوری در فرآیند</option>
|
||
<option value="3">نوآوری در محصول</option>
|
||
<option value="4">نوآوری سبز</option>
|
||
<option value="5">نوآوری ساخت داخل</option>
|
||
<option value="6">نوآوری در کسبوکار</option>
|
||
<option value="7">نوآوری نرم</option>
|
||
<option value="8">نوآوری اجتماعی</option>
|
||
</Select>
|
||
</Field>
|
||
<Field label="مضمون راهبردی">
|
||
<Select
|
||
value={themeId}
|
||
onChange={(e) => {
|
||
setThemeId(e.target.value);
|
||
setValueId("");
|
||
}}
|
||
required
|
||
>
|
||
<option value="">انتخاب کنید</option>
|
||
{themes.map((x) => (
|
||
<option key={x.id} value={x.id}>
|
||
{x.title}
|
||
</option>
|
||
))}
|
||
</Select>
|
||
</Field>
|
||
<Field
|
||
label="ارزش فناوری و نوآوری"
|
||
error={fieldErrors.innovationValueId}
|
||
>
|
||
<Select
|
||
value={valueId}
|
||
onChange={(e) => setValueId(e.target.value)}
|
||
disabled={!themeId}
|
||
required
|
||
>
|
||
<option value="">انتخاب کنید</option>
|
||
{values.map((x) => (
|
||
<option key={x.id} value={x.id}>
|
||
{x.title}
|
||
</option>
|
||
))}
|
||
</Select>
|
||
</Field>
|
||
<Field label="وضعیت ثبت">
|
||
<Select
|
||
value={status}
|
||
onChange={(e) => setStatus(e.target.value)}
|
||
>
|
||
<option value="0">پیشنویس</option>
|
||
<option value="1">انتشار</option>
|
||
</Select>
|
||
</Field>
|
||
<Field label="تاریخ شروع" hint="تقویم هجری شمسی؛ قالب yyyy/MM/dd">
|
||
<Input
|
||
name="startDate"
|
||
type="date"
|
||
required
|
||
defaultValue={rootValue("startDate")}
|
||
/>
|
||
</Field>
|
||
<Field label="تاریخ پایان">
|
||
<Input
|
||
name="endDate"
|
||
type="date"
|
||
defaultValue={rootValue("endDate")}
|
||
/>
|
||
</Field>
|
||
<Field label="امتیاز پروژه" hint="۰ تا ۱۰۰">
|
||
<Input
|
||
name="rating"
|
||
type="number"
|
||
min="0"
|
||
max="100"
|
||
step="0.01"
|
||
defaultValue={rootValue("rating")}
|
||
/>
|
||
</Field>
|
||
<Field
|
||
label="بودجه مصوب"
|
||
hint={unitHint("project", "approvedBudget")}
|
||
>
|
||
<Input
|
||
name="approvedBudget"
|
||
groupDigits
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
defaultValue={rootValue("approvedBudget")}
|
||
/>
|
||
</Field>
|
||
<Field
|
||
label="بودجه مصرفشده"
|
||
hint={unitHint("project", "budgetSpent")}
|
||
>
|
||
<Input
|
||
name="budgetSpent"
|
||
groupDigits
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
defaultValue={rootValue("budgetSpent")}
|
||
/>
|
||
</Field>
|
||
<Field label="شرح پروژه">
|
||
<Input
|
||
name="description"
|
||
defaultValue={rootValue("description")}
|
||
/>
|
||
</Field>
|
||
</div>
|
||
</Card>
|
||
<Card className={editing && activeTab !== "general" ? "tab-hidden" : ""}>
|
||
<div className="section-heading">
|
||
<span>۰۲</span>
|
||
<div>
|
||
<h3>اطلاعات تکمیلی عمومی</h3>
|
||
<p>فیلدهای عمومی مستند پروژه، مستقل از نوع نوآوری</p>
|
||
</div>
|
||
</div>
|
||
<div className="form-grid cols-3">
|
||
{generalFields.map(([key, label, kind]) => (
|
||
<Field
|
||
key={key}
|
||
label={label}
|
||
hint={key === "relatedCompany" ? "از واحدهای تعریفشده در تنظیمات استقرار" : unitHint("general", key)}
|
||
>
|
||
{key === "relatedCompany" ? (
|
||
<Select name={key} defaultValue={generalValue(key)} required>
|
||
<option value="">انتخاب واحد</option>
|
||
{generalValue(key) && !profile.dashboard.units.some(unit => unit.dataKey === generalValue(key)) && (
|
||
<option value={generalValue(key)}>{generalValue(key)} (مقدار قدیمی)</option>
|
||
)}
|
||
{profile.dashboard.units.map(unit => (
|
||
<option key={unit.dataKey} value={unit.dataKey}>
|
||
{unit.title}{unit.title !== unit.dataKey ? ` (${unit.dataKey})` : ""}
|
||
</option>
|
||
))}
|
||
</Select>
|
||
) : (
|
||
<Input
|
||
name={key}
|
||
groupDigits={isMoneyField("general", key)}
|
||
defaultValue={generalValue(key)}
|
||
type={
|
||
kind === "integer"
|
||
? "number"
|
||
: kind === "date"
|
||
? "date"
|
||
: "text"
|
||
}
|
||
inputMode={kind === "decimal" ? "decimal" : undefined}
|
||
dir={kind === "decimal" ? "ltr" : undefined}
|
||
min={kind === "integer" ? 0 : undefined}
|
||
max={key.includes("ProgressPercent") ? 100 : undefined}
|
||
/>
|
||
)}
|
||
</Field>
|
||
))}
|
||
</div>
|
||
</Card>
|
||
{innovationType === "4" && (
|
||
<Card className={editing && activeTab !== "details" ? "tab-hidden" : ""}>
|
||
<div className="section-heading green-heading">
|
||
<span>
|
||
<Leaf size={18} />
|
||
</span>
|
||
<div>
|
||
<h3>جزئیات نوآوری سبز</h3>
|
||
<p>
|
||
عدد خالی با صفر یکسان نیست؛ واحدها بدون تبدیل ذخیره میشوند.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div className="paired-grid">
|
||
{greenFields.map(([key, label]) => (
|
||
<Field key={key} label={label} hint={unitHint("green", key)}>
|
||
<Input
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
value={green[key] ?? ""}
|
||
onChange={(e) =>
|
||
setGreen((old) => ({ ...old, [key]: e.target.value }))
|
||
}
|
||
/>
|
||
</Field>
|
||
))}
|
||
</div>
|
||
<Field label="استانداردها و مقررات">
|
||
<textarea
|
||
className="input textarea"
|
||
name="standardRegulations"
|
||
rows={3}
|
||
defaultValue={String(
|
||
details?.greenDetails?.standardRegulations ?? "",
|
||
)}
|
||
/>
|
||
</Field>
|
||
</Card>
|
||
)}
|
||
{[1, 2, 3, 5].includes(Number(innovationType)) && (
|
||
<Card className={editing && activeTab !== "details" ? "tab-hidden" : ""}>
|
||
<div className="section-heading green-heading">
|
||
<span>۰۳</span>
|
||
<div>
|
||
<h3>جزئیات اختصاصی نوع نوآوری</h3>
|
||
<p>
|
||
شرطهای نمایش و required مطابق نوع انتخابشده اعمال میشوند.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<InnovationDetailsFields
|
||
type={Number(innovationType)}
|
||
values={innovationDetails}
|
||
setValues={setInnovationDetails}
|
||
/>
|
||
</Card>
|
||
)}
|
||
{!editing && innovationType === "5" && (
|
||
<Card className="nested-section">
|
||
<div className="card-heading">
|
||
<div>
|
||
<h3>پارامترهای فناوری</h3>
|
||
<p>پارامترهای فناوری با شناسه پروژه و در همان تراکنش ثبت میشوند.</p>
|
||
</div>
|
||
<Button
|
||
type="button"
|
||
className="secondary"
|
||
onClick={() =>
|
||
setTechnologyParameters([
|
||
...technologyParameters,
|
||
{ title: "", domesticValue: "", foreignValue: "" },
|
||
])
|
||
}
|
||
>
|
||
<Plus size={16} />
|
||
افزودن پارامتر
|
||
</Button>
|
||
</div>
|
||
{technologyParameters.map((x, i) => (
|
||
<div className="child-row tech-row" key={i}>
|
||
<Input
|
||
required
|
||
placeholder="عنوان پارامتر"
|
||
value={x.title}
|
||
onChange={(e) =>
|
||
setTechnologyParameters(
|
||
technologyParameters.map((r, j) =>
|
||
j === i ? { ...r, title: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<Input
|
||
required
|
||
placeholder="مقدار داخلی"
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
value={x.domesticValue}
|
||
onChange={(e) =>
|
||
setTechnologyParameters(
|
||
technologyParameters.map((r, j) =>
|
||
j === i ? { ...r, domesticValue: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<Input
|
||
required
|
||
placeholder="مقدار خارجی"
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
value={x.foreignValue}
|
||
onChange={(e) =>
|
||
setTechnologyParameters(
|
||
technologyParameters.map((r, j) =>
|
||
j === i ? { ...r, foreignValue: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<button
|
||
type="button"
|
||
className="icon-remove"
|
||
onClick={() =>
|
||
setTechnologyParameters(
|
||
technologyParameters.filter((_, j) => j !== i),
|
||
)
|
||
}
|
||
>
|
||
<Trash2 size={17} />
|
||
</button>
|
||
</div>
|
||
))}
|
||
</Card>
|
||
)}
|
||
{!editing && innovationType === "3" && (
|
||
<Card className="nested-section">
|
||
<div className="card-heading">
|
||
<div>
|
||
<h3>صادرات محصول</h3>
|
||
<p>سال/فصل و مقادیر صادرات برای همین پروژه ثبت میشوند.</p>
|
||
</div>
|
||
<Button
|
||
type="button"
|
||
className="secondary"
|
||
onClick={() =>
|
||
setExports([
|
||
...exports,
|
||
{
|
||
persianYear: "1405",
|
||
season: "بهار",
|
||
exportVolume: "",
|
||
exportedCapacity: "",
|
||
importVolumeBefore: "",
|
||
importVolumeAfter: "",
|
||
pricePerUnit: "",
|
||
exportRevenueBefore: "",
|
||
exportRevenueAfter: "",
|
||
},
|
||
])
|
||
}
|
||
>
|
||
<Plus size={16} />
|
||
افزودن فصل
|
||
</Button>
|
||
</div>
|
||
{exports.map((x, i) => (
|
||
<div className="export-child" key={i}>
|
||
<div className="form-grid cols-3">
|
||
<Field label="سال">
|
||
<Input
|
||
required
|
||
type="number"
|
||
value={x.persianYear}
|
||
onChange={(e) =>
|
||
setExports(
|
||
exports.map((r, j) =>
|
||
j === i ? { ...r, persianYear: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="فصل">
|
||
<Select
|
||
value={x.season}
|
||
onChange={(e) =>
|
||
setExports(
|
||
exports.map((r, j) =>
|
||
j === i ? { ...r, season: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
>
|
||
<option>بهار</option>
|
||
<option>تابستان</option>
|
||
<option>پاییز</option>
|
||
<option>زمستان</option>
|
||
</Select>
|
||
</Field>
|
||
{(
|
||
[
|
||
"exportVolume",
|
||
"exportedCapacity",
|
||
"importVolumeBefore",
|
||
"importVolumeAfter",
|
||
"pricePerUnit",
|
||
"exportRevenueBefore",
|
||
"exportRevenueAfter",
|
||
] as const
|
||
).map((key) => (
|
||
<Field
|
||
key={key}
|
||
hint={unitHint("export", key)}
|
||
label={
|
||
{
|
||
exportVolume: "تعداد صادرات",
|
||
exportedCapacity: "ظرفیت صادرشده",
|
||
importVolumeBefore: "واردات قبل",
|
||
importVolumeAfter: "واردات بعد",
|
||
pricePerUnit: "قیمت واحد",
|
||
exportRevenueBefore: "درآمد صادرات قبل",
|
||
exportRevenueAfter: "درآمد صادرات بعد",
|
||
}[key]
|
||
}
|
||
>
|
||
<Input
|
||
required
|
||
groupDigits={isMoneyField("export", key)}
|
||
inputMode="decimal"
|
||
dir="ltr"
|
||
value={x[key]}
|
||
onChange={(e) =>
|
||
setExports(
|
||
exports.map((r, j) =>
|
||
j === i ? { ...r, [key]: e.target.value } : r,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
))}
|
||
</div>
|
||
<button
|
||
type="button"
|
||
className="icon-remove"
|
||
onClick={() => setExports(exports.filter((_, j) => j !== i))}
|
||
>
|
||
<Trash2 size={17} />
|
||
</button>
|
||
</div>
|
||
))}
|
||
</Card>
|
||
)}
|
||
<div className={`form-actions${editing && activeTab === "children" ? " tab-hidden" : ""}`}>
|
||
<span>
|
||
<Check size={17} />
|
||
{progress} مقدار تکمیل شده
|
||
</span>
|
||
<Button type="submit" disabled={busy}>
|
||
<Save size={18} />
|
||
{busy ? "در حال ذخیره…" : editing ? "ذخیره تغییرات" : "ثبت پروژه"}
|
||
</Button>
|
||
</div>
|
||
</form>
|
||
{editing && id && activeTab === "children" && <ProjectChildrenPage embeddedProjectId={id} />}
|
||
</>
|
||
);
|
||
}
|
||
|
||
const generalFields: Array<
|
||
[string, string, "text" | "decimal" | "integer" | "date"]
|
||
> = [
|
||
["investment", "سرمایهگذاری", "decimal"],
|
||
["operationalCost", "هزینه عملیاتی", "decimal"],
|
||
["innovationDegree", "میزان نوآوری", "text"],
|
||
["executingPerson", "مسئول اجرا", "text"],
|
||
["excellentObserver", "ناظر عالی", "text"],
|
||
["projectType", "نوع پروژه", "text"],
|
||
["observer", "ناظر", "text"],
|
||
["executor", "مجری", "text"],
|
||
["executivePhase", "فاز اجرایی", "text"],
|
||
["businessStatus", "وضعیت کسبوکار پروژه", "text"],
|
||
["plannedProgressPercent", "پیشرفت برنامهای", "integer"],
|
||
["actualProgressPercent", "پیشرفت واقعی", "integer"],
|
||
["renewedDurationDays", "تمدید مدت (روز)", "integer"],
|
||
["doneDate", "تاریخ انجام", "date"],
|
||
["importance", "اهمیت پروژه", "text"],
|
||
["relatedCompany", "شرکت مرتبط", "text"],
|
||
["preInnovationCost", "هزینه پیش از نوآوری", "decimal"],
|
||
["innovationCost", "هزینه نوآوری", "decimal"],
|
||
["productionCapacityBefore", "ظرفیت تولید قبل", "decimal"],
|
||
["productionCapacityAfter", "ظرفیت تولید بعد", "decimal"],
|
||
["incomeBefore", "درآمد قبل", "decimal"],
|
||
["incomeAfter", "درآمد بعد", "decimal"],
|
||
];
|
||
function stringValues(source: Record<string, unknown>, excluded?: string) {
|
||
return Object.fromEntries(
|
||
Object.entries(source)
|
||
.filter(([key]) => key !== excluded)
|
||
.map(([key, value]) => [key, value == null ? "" : String(value)]),
|
||
);
|
||
}
|
||
|
||
|