Files
Frontend/src/app/(dashboard)/(private)/yield-harvest/page.tsx
T
2026-05-02 16:31:23 +03:30

133 lines
4.0 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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";
const YieldHarvestPage = () => {
const router = useRouter();
const searchParams = useSearchParams();
const selectionSummary = useMemo(() => {
const from = searchParams.get("from");
const planType = searchParams.get("planType");
const planId = searchParams.get("planId");
const planName = searchParams.get("planName");
const relatedType = searchParams.get("relatedType");
const relatedPlanId = searchParams.get("relatedPlanId");
const relatedPlanName = searchParams.get("relatedPlanName");
if (!from || !planType || !planId || !planName || !relatedType || !relatedPlanId || !relatedPlanName) {
return null;
}
return {
from,
planType,
planId,
planName,
relatedType,
relatedPlanId,
relatedPlanName,
};
}, [searchParams]);
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]);
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}
<PlantProductionPage planContext={planContext} />
</Stack>
);
};
export default YieldHarvestPage;