diff --git a/src/app/(dashboard)/(private)/fertilization-plan/page.tsx b/src/app/(dashboard)/(private)/fertilization-plan/page.tsx index 9d2a346..2f70606 100644 --- a/src/app/(dashboard)/(private)/fertilization-plan/page.tsx +++ b/src/app/(dashboard)/(private)/fertilization-plan/page.tsx @@ -1,6 +1,7 @@ "use client"; import { useCallback, useEffect, useMemo, useState } from "react"; +import { useRouter } from "next/navigation"; import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; @@ -78,6 +79,7 @@ const mapFertilizationPlanRow = ( }); const FertilizationPlanPage = () => { + const router = useRouter(); const { getFarmUuid } = useFarmHub(); const [plans, setPlans] = useState([]); const [minOutputTon, setMinOutputTon] = useState("0"); @@ -230,10 +232,31 @@ const FertilizationPlanPage = () => { } }; + const handleConfirmRelatedPlan = (relatedPlan: RelatedPlanItem) => { + if (!selectedPlan) return; + + setDetailsOpen(false); + + const query = new URLSearchParams({ + from: "fertilization-plan", + planType: "fertilization", + planId: String(selectedPlan.id), + planName: selectedPlan.planName, + relatedType: "irrigation", + relatedPlanId: String(relatedPlan.id), + relatedPlanName: relatedPlan.title, + }); + + router.push(`/yield-harvest?${query.toString()}`); + }; + return ( <> - + @@ -397,7 +420,7 @@ const FertilizationPlanPage = () => { relatedPlans={relatedPlans} selectedRelatedPlanId={selectedRelatedPlanId} onSelectRelatedPlan={(planId) => setSelectedRelatedPlanId(planId)} - onConfirm={() => setDetailsOpen(false)} + onConfirm={handleConfirmRelatedPlan} /> ) : null} diff --git a/src/views/dashboards/farm/fertilizationPlanParser/FertilizationPlanParserPage.tsx b/src/views/dashboards/farm/fertilizationPlanParser/FertilizationPlanParserPage.tsx index 7adfdd9..4b27698 100644 --- a/src/views/dashboards/farm/fertilizationPlanParser/FertilizationPlanParserPage.tsx +++ b/src/views/dashboards/farm/fertilizationPlanParser/FertilizationPlanParserPage.tsx @@ -1,6 +1,7 @@ "use client"; import { useMemo, useState } from "react"; +import { useRouter } from "next/navigation"; import Alert from "@mui/material/Alert"; import Box from "@mui/material/Box"; @@ -63,6 +64,8 @@ type FieldMeta = { type FertilizationPlanParserPageProps = { initialTab?: unknown; enabledTabs?: unknown; + selectedPlanId?: string | null; + selectedPlanName?: string | null; }; const FERTILIZATION_FIELD_LABELS: Record = { @@ -292,8 +295,12 @@ const normalizeAnswers = ( return acc; }, {}); -const FertilizationPlanParserPage = (_props: FertilizationPlanParserPageProps) => { +const FertilizationPlanParserPage = ({ + selectedPlanId = null, + selectedPlanName = null, +}: FertilizationPlanParserPageProps) => { const theme = useTheme(); + const router = useRouter(); const { farmHub } = useFarmHub(); const farmUuid = farmHub?.farm_uuid; const [state, setState] = useState(createInitialState()); @@ -462,6 +469,30 @@ const FertilizationPlanParserPage = (_props: FertilizationPlanParserPageProps) = } }; + const handleConfirmIrrigationPlan = (relatedPlan: RelatedPlanItem) => { + if (!selectedPlanId) { + setIrrigationDialogOpen(false); + updateState({ + requestError: + "برای ادامه، ابتدا یکی از برنامه‌های کودهی ذخیره‌شده را از جدول انتخاب کنید.", + }); + return; + } + + const query = new URLSearchParams({ + from: "fertilization-plan", + planType: "fertilization", + planId: String(selectedPlanId), + planName: selectedPlanName || planData?.crop_name || "برنامه کودهی", + relatedType: "irrigation", + relatedPlanId: String(relatedPlan.id), + relatedPlanName: relatedPlan.title, + }); + + setIrrigationDialogOpen(false); + router.push(`/yield-harvest?${query.toString()}`); + }; + return ( <> @@ -990,7 +1021,7 @@ const FertilizationPlanParserPage = (_props: FertilizationPlanParserPageProps) = relatedPlans={irrigationLoading ? [] : irrigationPlans} selectedRelatedPlanId={selectedIrrigationPlanId} onSelectRelatedPlan={(planId) => setSelectedIrrigationPlanId(planId)} - onConfirm={() => setIrrigationDialogOpen(false)} + onConfirm={handleConfirmIrrigationPlan} /> {irrigationDialogOpen && irrigationLoading ? : null}