UPDATE
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import Alert from "@mui/material/Alert";
|
import Alert from "@mui/material/Alert";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
@@ -78,6 +79,7 @@ const mapFertilizationPlanRow = (
|
|||||||
});
|
});
|
||||||
|
|
||||||
const FertilizationPlanPage = () => {
|
const FertilizationPlanPage = () => {
|
||||||
|
const router = useRouter();
|
||||||
const { getFarmUuid } = useFarmHub();
|
const { getFarmUuid } = useFarmHub();
|
||||||
const [plans, setPlans] = useState<FertilizationPlanRow[]>([]);
|
const [plans, setPlans] = useState<FertilizationPlanRow[]>([]);
|
||||||
const [minOutputTon, setMinOutputTon] = useState("0");
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack spacing={6}>
|
<Stack spacing={6}>
|
||||||
<FertilizationPlanParserPage />
|
<FertilizationPlanParserPage
|
||||||
|
selectedPlanId={selectedPlan?.id ?? null}
|
||||||
|
selectedPlanName={selectedPlan?.planName ?? null}
|
||||||
|
/>
|
||||||
|
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
@@ -397,7 +420,7 @@ const FertilizationPlanPage = () => {
|
|||||||
relatedPlans={relatedPlans}
|
relatedPlans={relatedPlans}
|
||||||
selectedRelatedPlanId={selectedRelatedPlanId}
|
selectedRelatedPlanId={selectedRelatedPlanId}
|
||||||
onSelectRelatedPlan={(planId) => setSelectedRelatedPlanId(planId)}
|
onSelectRelatedPlan={(planId) => setSelectedRelatedPlanId(planId)}
|
||||||
onConfirm={() => setDetailsOpen(false)}
|
onConfirm={handleConfirmRelatedPlan}
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo, useState } from "react";
|
import { useMemo, useState } from "react";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
import Alert from "@mui/material/Alert";
|
import Alert from "@mui/material/Alert";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
@@ -63,6 +64,8 @@ type FieldMeta = {
|
|||||||
type FertilizationPlanParserPageProps = {
|
type FertilizationPlanParserPageProps = {
|
||||||
initialTab?: unknown;
|
initialTab?: unknown;
|
||||||
enabledTabs?: unknown;
|
enabledTabs?: unknown;
|
||||||
|
selectedPlanId?: string | null;
|
||||||
|
selectedPlanName?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const FERTILIZATION_FIELD_LABELS: Record<string, string> = {
|
const FERTILIZATION_FIELD_LABELS: Record<string, string> = {
|
||||||
@@ -292,8 +295,12 @@ const normalizeAnswers = (
|
|||||||
return acc;
|
return acc;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const FertilizationPlanParserPage = (_props: FertilizationPlanParserPageProps) => {
|
const FertilizationPlanParserPage = ({
|
||||||
|
selectedPlanId = null,
|
||||||
|
selectedPlanName = null,
|
||||||
|
}: FertilizationPlanParserPageProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const router = useRouter();
|
||||||
const { farmHub } = useFarmHub();
|
const { farmHub } = useFarmHub();
|
||||||
const farmUuid = farmHub?.farm_uuid;
|
const farmUuid = farmHub?.farm_uuid;
|
||||||
const [state, setState] = useState<ParserState>(createInitialState());
|
const [state, setState] = useState<ParserState>(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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Grid container spacing={4}>
|
<Grid container spacing={4}>
|
||||||
@@ -990,7 +1021,7 @@ const FertilizationPlanParserPage = (_props: FertilizationPlanParserPageProps) =
|
|||||||
relatedPlans={irrigationLoading ? [] : irrigationPlans}
|
relatedPlans={irrigationLoading ? [] : irrigationPlans}
|
||||||
selectedRelatedPlanId={selectedIrrigationPlanId}
|
selectedRelatedPlanId={selectedIrrigationPlanId}
|
||||||
onSelectRelatedPlan={(planId) => setSelectedIrrigationPlanId(planId)}
|
onSelectRelatedPlan={(planId) => setSelectedIrrigationPlanId(planId)}
|
||||||
onConfirm={() => setIrrigationDialogOpen(false)}
|
onConfirm={handleConfirmIrrigationPlan}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{irrigationDialogOpen && irrigationLoading ? <LinearProgress sx={{ borderRadius: 999 }} /> : null}
|
{irrigationDialogOpen && irrigationLoading ? <LinearProgress sx={{ borderRadius: 999 }} /> : null}
|
||||||
|
|||||||
Reference in New Issue
Block a user