working on actions page

This commit is contained in:
2025-01-05 12:51:53 +03:30
parent bc3db055b1
commit 499bc21de9
6 changed files with 187 additions and 37 deletions

View File

@@ -1,6 +1,6 @@
"use client"; "use client";
import React from "react"; import React, {useState} from "react";
import dynamic from "next/dynamic"; import dynamic from "next/dynamic";
import MapLoading from "@/core/components/MapLayer/Loading"; import MapLoading from "@/core/components/MapLayer/Loading";
import { import {
@@ -10,60 +10,146 @@ import {
CardContent, CardContent,
CardHeader, CardHeader,
Chip, Chip,
Collapse,
Divider, Divider,
IconButton, IconButton,
Stack, Stack,
Typography Typography
} from "@mui/material"; } from "@mui/material";
import {styled} from '@mui/material/styles';
import HandymanIcon from '@mui/icons-material/Handyman'; import HandymanIcon from '@mui/icons-material/Handyman';
import DeleteIcon from "@mui/icons-material/Delete"; import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
import moment from "jalali-moment"; import moment from "jalali-moment";
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
import WatchLaterIcon from '@mui/icons-material/WatchLater'; import WatchLaterIcon from '@mui/icons-material/WatchLater';
import CalendarMonthIcon from "@mui/icons-material/CalendarMonth";
import DirectionsCarIcon from '@mui/icons-material/DirectionsCar';
import PersonIcon from '@mui/icons-material/Person';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import DesignServicesIcon from '@mui/icons-material/DesignServices';
import EditActionDuringPatrol from "./EditActionDuringPatrol";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), { const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => <MapLoading/>, loading: () => <MapLoading/>,
ssr: false, ssr: false,
}); });
const ActionInfo = ({action, deleteAction}) => { const ActionInfo = ({action, index, deleteAction}) => {
console.log("action", action) const [expanded, setExpanded] = useState(false);
const handleExpandClick = () => {
setExpanded(!expanded);
};
const ExpandMore = styled((props) => {
const {expand, ...other} = props;
return <IconButton {...other} />;
})(({theme}) => ({
marginLeft: 'auto',
transition: theme.transitions.create('transform', {
duration: theme.transitions.duration.shortest,
}),
variants: [
{
props: ({expand}) => !expand,
style: {
transform: 'rotate(0deg)',
},
},
{
props: ({expand}) => !!expand,
style: {
transform: 'rotate(180deg)',
},
},
],
}));
return ( return (
<Card sx={{maxWidth: 300}}> <Card sx={{maxWidth: 300}}>
<CardHeader <CardHeader
avatar={ avatar={
<HandymanIcon color="primary" sx={{width: "30px", height: "30px"}}/> <HandymanIcon color="primary" sx={{width: "30px", height: "30px"}}/>
} }
title={"متن تست"} title={<Typography sx={{fontSize: "14px", fontWeight: 500}}>{action.data.item_name}</Typography>}
subheader={"ساب آیتم تست"} subheader={action.data.sub_item_name}
/> />
<CardContent> <CardContent>
<Stack sx={{gap: 2}}> <Stack sx={{gap: 1}}>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", gap: 1}}>
<Chip size="small" label="تاریخ" icon={<CalendarMonthIcon/>}/> <CalendarMonthIcon/>
<Divider sx={{flex: 1, mx: 2}}/> <Typography variant="button">
<Typography sx={{fontSize: "12px", fontWeight: 500, textDecoration: "underline"}}> تاریخ:
{moment(action.start_date).locale("fa").format("YYYY/MM/DD")} </Typography>
<Typography variant="button">
{moment(action.data.activity_date).locale("fa").format("YYYY/MM/DD")}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", gap: 1}}>
<Chip size="small" label="ساعت" icon={<WatchLaterIcon/>}/> <WatchLaterIcon/>
<Divider sx={{flex: 1, mx: 2}}/> <Typography variant="button">
<Typography sx={{fontSize: "12px", fontWeight: 500, textDecoration: "underline"}}> ساعت:
{action.action_date} </Typography>
<Typography variant="button">
{action.data.activity_time}
</Typography>
</Box>
<Box sx={{display: "flex", alignItems: "center", gap: 1}}>
<DesignServicesIcon/>
<Typography variant="button">
میزان فعالیت انجام شده:
</Typography>
<Typography variant="button">
{action.data.amount}
{/*({action.data.unit_fa})*/}
</Typography> </Typography>
</Box> </Box>
</Stack> </Stack>
</CardContent> </CardContent>
<CardActions disableSpacing> <CardActions disableSpacing>
<IconButton aria-label="حذف فعالیت" color="error"> <Box>
<DeleteIcon/> <IconButton aria-label="حذف فعالیت" color="error" onClick={deleteAction}>
</IconButton> <DeleteIcon/>
<IconButton aria-label="ویرایش فعالیت" color="primary"> </IconButton>
<EditIcon/> <EditActionDuringPatrol action={action}/>
</IconButton> </Box>
<ExpandMore
expand={expanded}
onClick={handleExpandClick}
aria-expanded={expanded}
aria-label="show more"
>
<ExpandMoreIcon/>
</ExpandMore>
</CardActions> </CardActions>
<Collapse in={expanded} timeout="auto" unmountOnExit sx={{p: 2}}>
<Stack sx={{gap: 1}}>
<Box>
<Divider sx={{mb: 1}}>
<Chip size="small" label="خودرو ها" icon={<DirectionsCarIcon/>}/>
</Divider>
<Stack>
{action.data.cmms_machines.map((cmms_machine, index) => (
<Typography variant="button" key={index}>
{index + 1}: {cmms_machine.car_name}
</Typography>
))}
</Stack>
</Box>
<Box>
<Divider sx={{mb: 1}}>
<Chip size="small" label="راهداران" icon={<PersonIcon/>}/>
</Divider>
<Stack>
{action.data.rahdaran_id.map((rahdar, index) => (
<Typography variant="button" key={index}>
{index + 1}: {rahdar.name}
</Typography>
))}
</Stack>
</Box>
</Stack>
</Collapse>
</Card> </Card>
); );
}; };

View File

@@ -5,6 +5,7 @@ import AddCircleIcon from '@mui/icons-material/AddCircle';
import React, {useState} from "react"; import React, {useState} from "react";
import ModalActionsDuringPatrol from "./ModalActionsDuringPatrol"; import ModalActionsDuringPatrol from "./ModalActionsDuringPatrol";
import ActionInfo from "./ActionInfo"; import ActionInfo from "./ActionInfo";
import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
const ActionsDuringPatrol = ({tabState, setTabState}) => { const ActionsDuringPatrol = ({tabState, setTabState}) => {
const [ActionsList, setActionsList] = useState([]); const [ActionsList, setActionsList] = useState([]);
@@ -39,6 +40,7 @@ const ActionsDuringPatrol = ({tabState, setTabState}) => {
<Grid key={index} item xs={12} sm={6} lg={4}> <Grid key={index} item xs={12} sm={6} lg={4}>
<ActionInfo <ActionInfo
action={action} action={action}
index={index}
deleteAction={() => deleteAction(index)} deleteAction={() => deleteAction(index)}
/> />
</Grid> </Grid>
@@ -51,6 +53,14 @@ const ActionsDuringPatrol = ({tabState, setTabState}) => {
</Typography> </Typography>
</Box> </Box>
} }
<Box>
<Box sx={{display: "flex", gap: 1, justifyContent: "center"}}>
<Button variant="contained" color="primary" onClick={() => setTabState(tabState + 1)}
endIcon={<KeyboardDoubleArrowLeftIcon/>} sx={{mt: 2}}>
نهایی کردن درخواست
</Button>
</Box>
</Box>
</Box> </Box>
); );
}; };

View File

@@ -0,0 +1,52 @@
"use client";
import React, {useState} from "react";
import dynamic from "next/dynamic";
import MapLoading from "@/core/components/MapLayer/Loading";
import {Dialog, DialogTitle, IconButton} from "@mui/material";
import EditIcon from "@mui/icons-material/Edit";
import EditFormContent from "@/components/dashboard/roadItems/operator/RowActions/EditForm/EditFormContent";
const MapLayer = dynamic(() => import("@/core/components/MapLayer"), {
loading: () => <MapLoading/>,
ssr: false,
});
const EditActionDuringPatrol = ({action}) => {
console.log("action", action)
const [open, setOpen] = useState(false);
const handleOpen = () => {
setOpen(true);
};
const HandleSubmit = async (data, result) => {
setActionsList((prev) => [...prev, data]);
setOpen(false);
}
return (
<>
<IconButton aria-label="ویرایش فعالیت" color="primary" onClick={handleOpen}>
<EditIcon/>
</IconButton>
<Dialog
maxWidth="sm"
fullWidth
open={open}
PaperProps={{
sx: {
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
},
}}
>
<DialogTitle>ویرایش اطلاعات</DialogTitle>
<EditFormContent setOpenEditDialog={setOpen} onSubmit={HandleSubmit} defaultData={action.data}/>
</Dialog>
</>
);
};
export default EditActionDuringPatrol;

View File

@@ -10,6 +10,7 @@ import WatchLaterIcon from '@mui/icons-material/WatchLater';
import QueryBuilderIcon from '@mui/icons-material/QueryBuilder'; import QueryBuilderIcon from '@mui/icons-material/QueryBuilder';
import AddRoadIcon from '@mui/icons-material/AddRoad'; import AddRoadIcon from '@mui/icons-material/AddRoad';
import ShareLocationIcon from '@mui/icons-material/ShareLocation'; import ShareLocationIcon from '@mui/icons-material/ShareLocation';
import ElectricCarIcon from '@mui/icons-material/ElectricCar';
import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft"; import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
import QrCode2Icon from '@mui/icons-material/QrCode2'; import QrCode2Icon from '@mui/icons-material/QrCode2';
import moment from "jalali-moment"; import moment from "jalali-moment";
@@ -36,65 +37,65 @@ const PatrolDetailInfo = ({patrolData, tabState, setTabState}) => {
}}> }}>
<Stack sx={{minWidth: {xs: "100%", lg: "300px"}, gap: 2}}> <Stack sx={{minWidth: {xs: "100%", lg: "300px"}, gap: 2}}>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="مدت زمان روشن بودن خودرو" icon={<DirectionsCarFilledIcon/>}/> <Chip size="small" label="مدت زمان روشن بودن خودرو" icon={<ElectricCarIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{Math.floor(patrolData.accOnDuration / 60)} دقیقه {Math.floor(patrolData.accOnDuration / 60)} دقیقه
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="نام خودرو" icon={<DirectionsCarFilledIcon/>}/> <Chip size="small" label="نام خودرو" icon={<DirectionsCarFilledIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{patrolData.roadPatrolMachinesId.car_name} {patrolData.roadPatrolMachinesId.car_name}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="کد خودرو" icon={<QrCode2Icon/>}/> <Chip size="small" label="کد خودرو" icon={<QrCode2Icon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{patrolData.roadPatrolMachinesId.machine_code} {patrolData.roadPatrolMachinesId.machine_code}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="پلاک خودرو" icon={<DirectionsCarFilledIcon/>}/> <Chip size="small" label="پلاک خودرو" icon={<DirectionsCarFilledIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{patrolData.roadPatrolMachinesId.plak_number} {patrolData.roadPatrolMachinesId.plak_number}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="زمان شروع گشت" icon={<QueryBuilderIcon/>}/> <Chip size="small" label="زمان شروع گشت" icon={<QueryBuilderIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{moment(patrolData.start_time).locale("fa").format("HH:mm | YYYY/MM/DD")} {moment(patrolData.start_time).locale("fa").format("HH:mm | YYYY/MM/DD")}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="زمان پایان گشت" icon={<WatchLaterIcon/>}/> <Chip size="small" label="زمان پایان گشت" icon={<WatchLaterIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{moment(patrolData.end_time).locale("fa").format("HH:mm | YYYY/MM/DD")} {moment(patrolData.end_time).locale("fa").format("HH:mm | YYYY/MM/DD")}
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="مسافت" icon={<AddRoadIcon/>}/> <Chip size="small" label="مسافت" icon={<AddRoadIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{(patrolData.mileage / 1000).toFixed(1)} کیلومتر {(patrolData.mileage / 1000).toFixed(1)} کیلومتر
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="میزان مصرف سوخت" icon={<LocalGasStationIcon/>}/> <Chip size="small" label="میزان مصرف سوخت" icon={<LocalGasStationIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{Math.round(patrolData.fuelConsumption * 10) / 10} لیتر {Math.round(patrolData.fuelConsumption * 10) / 10} لیتر
</Typography> </Typography>
</Box> </Box>
<Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}> <Box sx={{display: "flex", alignItems: "center", justifyContent: "space-between"}}>
<Chip size="small" label="تعداد توقف در مسیر" icon={<ShareLocationIcon/>}/> <Chip size="small" label="تعداد توقف در مسیر" icon={<ShareLocationIcon/>}/>
<Divider sx={{flex: 1, mx: 2}}/> <Divider sx={{flex: 1, mx: 2}}/>
<Typography sx={{fontSize: "13px", fontWeight: 400, textDecoration: "underline"}}> <Typography sx={{fontSize: "13px", fontWeight: 400}}>
{patrolData.stopPoints.length} مورد {patrolData.stopPoints.length} مورد
</Typography> </Typography>
</Box> </Box>

View File

@@ -55,7 +55,7 @@ const PatrolForms = ({mutate}) => {
const requestServer = useRequest({notificationSuccess: true}); const requestServer = useRequest({notificationSuccess: true});
const theme = useTheme(); const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down("md")); const isMobile = useMediaQuery(theme.breakpoints.down("md"));
const [tabState, setTabState] = useState(0); const [tabState, setTabState] = useState(2);
const [activeUpTo, setActiveUpTo] = useState(0); const [activeUpTo, setActiveUpTo] = useState(0);
const handleChangeTab = (event, newValue) => { const handleChangeTab = (event, newValue) => {

View File

@@ -44,10 +44,11 @@ const SuperVisorsDetail = ({control, watch, setValue, tabState, setTabState}) =>
<Controller <Controller
control={control} control={control}
render={({field, fieldState: {error}}) => { render={({field, fieldState: {error}}) => {
console.log("field.value", field.value)
return ( return (
<RahdarCode <RahdarCode
rahdarsCode={field.value || []} rahdarsCode={field.value}
setRahdarsCode={(value) => field.onChange(value || [])} setRahdarsCode={(value) => field.onChange(value)}
error={error} error={error}
multiple={false} multiple={false}
/> />