Files
Frontend/src/app/(dashboard)/(private)/yield-harvest/page.tsx
T

133 lines
4.0 KiB
TypeScript
Raw Normal View History

2026-05-02 06:23:34 +03:30
"use client";
import { useMemo } from "react";
import { useRouter, useSearchParams } from "next/navigation";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Card from "@mui/material/Card";
import CardContent from "@mui/material/CardContent";
import Chip from "@mui/material/Chip";
import Stack from "@mui/material/Stack";
import Typography from "@mui/material/Typography";
import PlantProductionPage from "@views/dashboards/farm/PlantProductionPage";
2026-04-11 03:50:23 +03:30
2026-04-18 01:23:37 +03:30
const YieldHarvestPage = () => {
2026-05-02 06:23:34 +03:30
const router = useRouter();
const searchParams = useSearchParams();
const selectionSummary = useMemo(() => {
const from = searchParams.get("from");
const planType = searchParams.get("planType");
2026-05-02 16:31:23 +03:30
const planId = searchParams.get("planId");
2026-05-02 06:23:34 +03:30
const planName = searchParams.get("planName");
const relatedType = searchParams.get("relatedType");
2026-05-02 16:31:23 +03:30
const relatedPlanId = searchParams.get("relatedPlanId");
2026-05-02 06:23:34 +03:30
const relatedPlanName = searchParams.get("relatedPlanName");
2026-05-02 16:31:23 +03:30
if (!from || !planType || !planId || !planName || !relatedType || !relatedPlanId || !relatedPlanName) {
2026-05-02 06:23:34 +03:30
return null;
}
return {
from,
planType,
2026-05-02 16:31:23 +03:30
planId,
2026-05-02 06:23:34 +03:30
planName,
relatedType,
2026-05-02 16:31:23 +03:30
relatedPlanId,
2026-05-02 06:23:34 +03:30
relatedPlanName,
};
}, [searchParams]);
2026-05-02 16:31:23 +03:30
const planContext = useMemo(() => {
if (!selectionSummary) return undefined;
const context: {
irrigationPlanId?: string;
fertilizationPlanId?: string;
} = {};
if (selectionSummary.planType === "irrigation") {
context.irrigationPlanId = selectionSummary.planId;
} else {
context.fertilizationPlanId = selectionSummary.planId;
}
if (selectionSummary.relatedType === "irrigation") {
context.irrigationPlanId = selectionSummary.relatedPlanId;
} else {
context.fertilizationPlanId = selectionSummary.relatedPlanId;
}
return context;
}, [selectionSummary]);
2026-05-02 06:23:34 +03:30
const handleBack = () => {
const from = selectionSummary?.from;
if (from === "irrigation-plan") {
router.push("/irrigation-plan");
return;
}
if (from === "fertilization-plan") {
router.push("/fertilization-plan");
return;
}
router.back();
};
return (
<Stack spacing={6}>
{selectionSummary ? (
<Card variant="outlined">
<CardContent>
<Stack
direction={{ xs: "column", md: "row" }}
spacing={2}
alignItems={{ xs: "stretch", md: "center" }}
justifyContent="space-between"
>
<Box>
<Typography variant="h5">تحلیل عملکرد و برداشت</Typography>
<Typography color="text.secondary">
بر اساس انتخاب برنامهها وارد این صفحه شدهاید.
</Typography>
</Box>
<Button
variant="outlined"
color="secondary"
startIcon={<i className="tabler-arrow-right text-[18px]" />}
onClick={handleBack}
>
بازگشت به صفحه قبل
</Button>
</Stack>
<Stack direction={{ xs: "column", md: "row" }} spacing={1.5} useFlexGap flexWrap="wrap" sx={{ mt: 3 }}>
<Chip
variant="tonal"
color="primary"
label={`برنامه ${selectionSummary.planType === "irrigation" ? "آبیاری" : "کوددهی"}: ${selectionSummary.planName}`}
/>
<Chip
variant="tonal"
color="success"
label={`برنامه ${selectionSummary.relatedType === "irrigation" ? "آبیاری" : "کوددهی"} انتخاب‌شده: ${selectionSummary.relatedPlanName}`}
/>
</Stack>
</CardContent>
</Card>
) : null}
2026-05-02 16:31:23 +03:30
<PlantProductionPage planContext={planContext} />
2026-05-02 06:23:34 +03:30
</Stack>
);
};
2026-04-11 03:50:23 +03:30
2026-05-02 06:23:34 +03:30
export default YieldHarvestPage;