add mutate on row actions
This commit is contained in:
@@ -1,18 +1,18 @@
|
|||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
id : 1,
|
id: 1,
|
||||||
name : "تهران"
|
name: "تهران",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 2,
|
id: 2,
|
||||||
name : "ری"
|
name: "ری",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 3,
|
id: 3,
|
||||||
name : "اندیشه"
|
name: "اندیشه",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
return Response.json({ data });
|
return Response.json({ data });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,41 @@
|
|||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
id : 1,
|
id: 1,
|
||||||
aplication_number : 1,
|
aplication_number: 1,
|
||||||
application_date : "1",
|
application_date: "1",
|
||||||
province:"tehran",
|
province: "tehran",
|
||||||
city:"tehran"
|
city: "tehran",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 2,
|
id: 2,
|
||||||
aplication_number : 2,
|
aplication_number: 2,
|
||||||
application_date : "1",
|
application_date: "1",
|
||||||
province:"tehran",
|
province: "tehran",
|
||||||
city:"tehran"
|
city: "tehran",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 3,
|
id: 3,
|
||||||
aplication_number : 3,
|
aplication_number: 3,
|
||||||
application_date : "1",
|
application_date: "1",
|
||||||
province:"tehran",
|
province: "tehran",
|
||||||
city:"tehran"
|
city: "tehran",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 4,
|
id: 4,
|
||||||
aplication_number : 4,
|
aplication_number: 4,
|
||||||
application_date : "1",
|
application_date: "1",
|
||||||
province:"tehran",
|
province: "tehran",
|
||||||
city:"tehran"
|
city: "tehran",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 5,
|
id: 5,
|
||||||
aplication_number : 5,
|
aplication_number: 5,
|
||||||
application_date : "1",
|
application_date: "1",
|
||||||
province:"tehran",
|
province: "tehran",
|
||||||
city:"tehran"
|
city: "tehran",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
return Response.json({ data });
|
return Response.json({ data });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
const data = [
|
const data = [
|
||||||
{
|
{
|
||||||
id : 1,
|
id: 1,
|
||||||
name : "تهران"
|
name: "تهران",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 2,
|
id: 2,
|
||||||
name : "مشهد"
|
name: "مشهد",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id : 3,
|
id: 3,
|
||||||
name : "اصفهان"
|
name: "اصفهان",
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
return Response.json({ data });
|
return Response.json({ data });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export async function POST() {
|
export async function POST() {
|
||||||
return Response.json({message : "Done"});
|
return Response.json({ message: "Done" });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const TaskList = () => {
|
|||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -114,10 +114,7 @@ const TaskList = () => {
|
|||||||
positionActionsColumn={"last"}
|
positionActionsColumn={"last"}
|
||||||
renderRowActions={({ row, table }) => (
|
renderRowActions={({ row, table }) => (
|
||||||
<Tooltip arrow title="نمایش جزئیات" placement="right">
|
<Tooltip arrow title="نمایش جزئیات" placement="right">
|
||||||
<IconButton
|
<IconButton color="success" onClick={() => console.log("next part")}>
|
||||||
color="success"
|
|
||||||
onClick={() => console.log("next part")}
|
|
||||||
>
|
|
||||||
<AssignmentIcon />
|
<AssignmentIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@@ -1,58 +1,66 @@
|
|||||||
import {
|
import {
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Button, CircularProgress,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
FormControl, FormHelperText,
|
FormControl,
|
||||||
InputLabel, OutlinedInput,
|
FormHelperText,
|
||||||
|
InputLabel,
|
||||||
|
OutlinedInput,
|
||||||
Stack,
|
Stack,
|
||||||
TextField, Typography
|
TextField,
|
||||||
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {Controller, useForm} from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import {yupResolver} from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import {object, string} from "yup";
|
import { object, string } from "yup";
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import useCities from "@/lib/hooks/useCities";
|
import useCities from "@/lib/hooks/useCities";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import {REFER_ADMIN_CITY} from "@/core/utils/routes";
|
import { REFER_ADMIN_CITY } from "@/core/utils/routes";
|
||||||
|
|
||||||
const validationSchema = object({
|
const validationSchema = object({
|
||||||
description: string().required("وارد کردن توضیحات الزامیست!"),
|
description: string().required("وارد کردن توضیحات الزامیست!"),
|
||||||
city: string().required("وارد کردن شهرستان الزامیست!"),
|
city: string().required("وارد کردن شهرستان الزامیست!"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
const ReferFormContext = ({ setOpenReferDialog, rowId, mutate }) => {
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
description: "",
|
description: "",
|
||||||
city: "",
|
city: "",
|
||||||
};
|
};
|
||||||
const { cities, loadingCities, errorCities } = useCities()
|
const { cities, loadingCities, errorCities } = useCities();
|
||||||
const requestServer = useRequest({auth: true})
|
const requestServer = useRequest({ auth: true });
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: {isSubmitting, errors, touchedFields},
|
formState: { isSubmitting, errors, touchedFields },
|
||||||
} = useForm({defaultValues, resolver: yupResolver(validationSchema), mode : "onBlur"})
|
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("description", data.description);
|
formData.append("description", data.description);
|
||||||
formData.append("cityId", data.city);
|
formData.append("cityId", data.city);
|
||||||
requestServer(`${REFER_ADMIN_CITY}/${rowId}`, 'post', {
|
requestServer(`${REFER_ADMIN_CITY}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
}).then(() => {
|
})
|
||||||
setOpenReferDialog(false)
|
.then(() => {
|
||||||
mutate()
|
setOpenReferDialog(false);
|
||||||
}).catch(() => {})
|
mutate();
|
||||||
}
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Stack spacing={2}>
|
<Stack spacing={2}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<FormControl error={!!errors.description} size="small" fullWidth variant="outlined">
|
<FormControl error={!!errors.description} size="small" fullWidth variant="outlined">
|
||||||
<InputLabel sx={{pt : 1}} htmlFor="description">توضیحات</InputLabel>
|
<InputLabel sx={{ pt: 1 }} htmlFor="description">
|
||||||
|
توضیحات
|
||||||
|
</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="description"
|
id="description"
|
||||||
label={"توضیحات"}
|
label={"توضیحات"}
|
||||||
@@ -62,53 +70,53 @@ const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
|||||||
{...register("description")}
|
{...register("description")}
|
||||||
size="small"
|
size="small"
|
||||||
fullWidth
|
fullWidth
|
||||||
sx={{mt: 1}}
|
sx={{ mt: 1 }}
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
<FormHelperText
|
<FormHelperText id="description">
|
||||||
id="description">{errors.description ? errors.description.message : null}</FormHelperText>
|
{errors.description ? errors.description.message : null}
|
||||||
|
</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Controller
|
<Controller
|
||||||
name="city"
|
name="city"
|
||||||
control={control}
|
control={control}
|
||||||
render={({field: {onChange, value}, fieldState : {error }}) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<FormControl error={!!error} size="small" fullWidth variant="outlined">
|
<FormControl error={!!error} size="small" fullWidth variant="outlined">
|
||||||
<InputLabel htmlFor="city"/>
|
<InputLabel htmlFor="city" />
|
||||||
{errorCities ? (
|
{errorCities ? (
|
||||||
<Typography color={"red"}>خطایی در دریافت شهرستان ها رخ داده است!</Typography>
|
<Typography color={"red"}>خطایی در دریافت شهرستان ها رخ داده است!</Typography>
|
||||||
) :
|
) : loadingCities ? (
|
||||||
loadingCities ? (
|
<Typography sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||||
<Typography sx={{display : 'flex', alignItems : "center", gap : 2}}>
|
<CircularProgress size={20} />
|
||||||
<CircularProgress size={20} />
|
درحال دریافت لیست شهرستان ها
|
||||||
درحال دریافت لیست شهرستان ها
|
</Typography>
|
||||||
</Typography>
|
) : (
|
||||||
) : (
|
<Autocomplete
|
||||||
<Autocomplete
|
id="city"
|
||||||
id="city"
|
size="small"
|
||||||
size="small"
|
value={cities.find((city) => city.id === value) || null}
|
||||||
value={cities.find(city => city.id === value) || null}
|
disablePortal
|
||||||
disablePortal
|
options={cities}
|
||||||
options={cities}
|
getOptionLabel={(city) => city.name}
|
||||||
getOptionLabel={(city) => city.name}
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
onChange={(event, newValue) => {
|
||||||
onChange={(event, newValue) => {
|
onChange(newValue ? newValue.id : "");
|
||||||
onChange(newValue ? newValue.id : "");
|
}}
|
||||||
}}
|
renderInput={(params) => (
|
||||||
renderInput={(params) => (
|
<TextField
|
||||||
<TextField
|
{...params}
|
||||||
{...params}
|
autoComplete="off"
|
||||||
autoComplete="off"
|
error={!!errors.city}
|
||||||
error={!!errors.city}
|
fullWidth
|
||||||
fullWidth
|
label="شهرستان"
|
||||||
label="شهرستان"
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
|
||||||
<FormHelperText id="city">
|
<FormHelperText id="city">
|
||||||
{errors.city ? errors.city.message : null}
|
{errors.city ? errors.city.message : null}
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
@@ -117,24 +125,14 @@ const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button onClick={() => setOpenReferDialog(false)} variant="outlined" color="secondary" autoFocus>
|
||||||
onClick={() => setOpenReferDialog(false)}
|
|
||||||
variant="outlined"
|
|
||||||
color="secondary"
|
|
||||||
autoFocus
|
|
||||||
>
|
|
||||||
{"انصراف"}
|
{"انصراف"}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button variant="contained" color="primary" type={"submit"} disabled={isSubmitting}>
|
||||||
variant="contained"
|
{isSubmitting ? "در حال اسال" : "ارجاع"}
|
||||||
color="primary"
|
|
||||||
type={"submit"}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
>
|
|
||||||
{isSubmitting ? "در حال اسال" :"ارجاع"}
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default ReferFormContext
|
export default ReferFormContext;
|
||||||
|
|||||||
@@ -1,36 +1,41 @@
|
|||||||
import {Dialog, DialogTitle, IconButton, Stack, Tooltip} from "@mui/material";
|
import { Dialog, DialogTitle, IconButton, Stack, Tooltip } from "@mui/material";
|
||||||
import ReplyIcon from '@mui/icons-material/Reply';
|
import ReplyIcon from "@mui/icons-material/Reply";
|
||||||
import DialogTransition from "@/core/components/DialogTransition";
|
import DialogTransition from "@/core/components/DialogTransition";
|
||||||
import ReferFormContext from "@/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext";
|
import ReferFormContext from "@/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer/ReferFormContext";
|
||||||
import {useState} from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const ReferForm = ({rowId, mutate}) => {
|
const ReferForm = ({ rowId, mutate }) => {
|
||||||
const [openReferDialog, setOpenReferDialog] = useState(false)
|
const [openReferDialog, setOpenReferDialog] = useState(false);
|
||||||
return(
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Tooltip title="ارجاع به شهرستان دیگر" arrow placement="right">
|
<Tooltip title="ارجاع به شهرستان دیگر" arrow placement="right">
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
sx={{textTransform: "unset", alignSelf: "center"}}
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpenReferDialog(true)
|
setOpenReferDialog(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ReplyIcon/>
|
<ReplyIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog PaperProps={{
|
<Dialog
|
||||||
sx: {
|
PaperProps={{
|
||||||
transition: 'all .3s',
|
sx: {
|
||||||
boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'
|
transition: "all .3s",
|
||||||
}
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
}} open={openReferDialog} fullWidth TransitionComponent={DialogTransition}>
|
},
|
||||||
|
}}
|
||||||
|
open={openReferDialog}
|
||||||
|
fullWidth
|
||||||
|
TransitionComponent={DialogTransition}
|
||||||
|
>
|
||||||
<DialogTitle sx={{ m: 0, p: 2, borderBottom: 1, borderColor: "divider" }} id="create-dialog">
|
<DialogTitle sx={{ m: 0, p: 2, borderBottom: 1, borderColor: "divider" }} id="create-dialog">
|
||||||
ارجاع به شهرستان دیگر
|
ارجاع به شهرستان دیگر
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<ReferFormContext rowId={rowId} mutate={mutate} setOpenReferDialog={setOpenReferDialog} />
|
<ReferFormContext rowId={rowId} mutate={mutate} setOpenReferDialog={setOpenReferDialog} />
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default ReferForm
|
export default ReferForm;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import ReferForm from "@/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer";
|
import ReferForm from "@/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions/Refer";
|
||||||
|
|
||||||
const RowActions = ({row, mutate}) => {
|
const RowActions = ({ row, mutate }) => {
|
||||||
return(
|
return (
|
||||||
<ReferForm mutate={mutate} rowId={row.getValue("id")} /> //rowId should pass
|
<ReferForm mutate={mutate} rowId={row.getValue("id")} /> //rowId should pass
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default RowActions
|
export default RowActions;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { Box, IconButton, Tooltip } from "@mui/material";
|
import { Box } from "@mui/material";
|
||||||
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
import DataTableWithAuth from "@/core/components/DataTableWithAuth";
|
||||||
import AssignmentIcon from "@mui/icons-material/Assignment";
|
import RowActions from "./RowActions";
|
||||||
import RowActions from "@/components/dashboard/inquiryPrivacy/cityAdmin/zaminGov/RowActions";
|
|
||||||
|
|
||||||
const TaskList = () => {
|
const TaskList = () => {
|
||||||
const columns = useMemo(
|
const columns = useMemo(
|
||||||
@@ -106,7 +105,7 @@ const TaskList = () => {
|
|||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -121,7 +120,7 @@ const TaskList = () => {
|
|||||||
table_name={"cityAdminZaminGovList"}
|
table_name={"cityAdminZaminGovList"}
|
||||||
enableRowActions
|
enableRowActions
|
||||||
positionActionsColumn={"last"}
|
positionActionsColumn={"last"}
|
||||||
renderRowActions={({ row, table }) => <RowActions row={row}/>}
|
RowActions={RowActions}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import { Stack } from "@mui/material";
|
|||||||
import TaskList from "./TaskList";
|
import TaskList from "./TaskList";
|
||||||
|
|
||||||
const CityAdminZaminGovComponent = () => {
|
const CityAdminZaminGovComponent = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={1}>
|
<Stack spacing={1}>
|
||||||
<PageTitle title={"استعلام حرائم پنجره واحد"} />
|
<PageTitle title={"استعلام حرائم پنجره واحد"} />
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const TaskList = () => {
|
|||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -114,10 +114,7 @@ const TaskList = () => {
|
|||||||
positionActionsColumn={"last"}
|
positionActionsColumn={"last"}
|
||||||
renderRowActions={({ row, table }) => (
|
renderRowActions={({ row, table }) => (
|
||||||
<Tooltip arrow title="نمایش جزئیات" placement="right">
|
<Tooltip arrow title="نمایش جزئیات" placement="right">
|
||||||
<IconButton
|
<IconButton color="success" onClick={() => console.log("next part")}>
|
||||||
color="success"
|
|
||||||
onClick={() => console.log("next part")}
|
|
||||||
>
|
|
||||||
<AssignmentIcon />
|
<AssignmentIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@@ -1,59 +1,67 @@
|
|||||||
import {
|
import {
|
||||||
Autocomplete,
|
Autocomplete,
|
||||||
Button, CircularProgress,
|
Button,
|
||||||
|
CircularProgress,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
FormControl, FormHelperText,
|
FormControl,
|
||||||
InputLabel, OutlinedInput,
|
FormHelperText,
|
||||||
|
InputLabel,
|
||||||
|
OutlinedInput,
|
||||||
Stack,
|
Stack,
|
||||||
TextField, Typography
|
TextField,
|
||||||
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {Controller, useForm} from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import {yupResolver} from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import {object, string} from "yup";
|
import { object, string } from "yup";
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import useProvinces from "@/lib/hooks/useProvince";
|
import useProvinces from "@/lib/hooks/useProvince";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import {REFER_ADMIN_PROVINCE} from "@/core/utils/routes";
|
import { REFER_ADMIN_PROVINCE } from "@/core/utils/routes";
|
||||||
|
|
||||||
const validationSchema = object({
|
const validationSchema = object({
|
||||||
description: string().required("وارد کردن توضیحات الزامیست!"),
|
description: string().required("وارد کردن توضیحات الزامیست!"),
|
||||||
province: string().required("وارد کردن استان الزامیست!"),
|
province: string().required("وارد کردن استان الزامیست!"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
const ReferFormContext = ({ setOpenReferDialog, rowId, mutate }) => {
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
description: "",
|
description: "",
|
||||||
province: "",
|
province: "",
|
||||||
};
|
};
|
||||||
const { provinces, loadingProvinces, errorProvinces } = useProvinces()
|
const { provinces, loadingProvinces, errorProvinces } = useProvinces();
|
||||||
const requestServer = useRequest({auth: true})
|
const requestServer = useRequest({ auth: true });
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: {isSubmitting, errors, touchedFields},
|
formState: { isSubmitting, errors, touchedFields },
|
||||||
} = useForm({defaultValues, resolver: yupResolver(validationSchema), mode : "onBlur"})
|
} = useForm({ defaultValues, resolver: yupResolver(validationSchema), mode: "onBlur" });
|
||||||
|
|
||||||
const onSubmit = async (data) => {
|
const onSubmit = async (data) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("description", data.description);
|
formData.append("description", data.description);
|
||||||
formData.append("provinceId", data.province);
|
formData.append("provinceId", data.province);
|
||||||
|
|
||||||
requestServer(`${REFER_ADMIN_PROVINCE}/${rowId}`, 'post', {
|
requestServer(`${REFER_ADMIN_PROVINCE}/${rowId}`, "post", {
|
||||||
data: formData,
|
data: formData,
|
||||||
}).then(() => {
|
})
|
||||||
setOpenReferDialog(false)
|
.then(() => {
|
||||||
mutate()
|
setOpenReferDialog(false);
|
||||||
}).catch(() => {})
|
mutate();
|
||||||
}
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
<StyledForm onSubmit={handleSubmit(onSubmit)}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<Stack spacing={2}>
|
<Stack spacing={2}>
|
||||||
<Stack>
|
<Stack>
|
||||||
<FormControl error={!!errors.description} size="small" fullWidth variant="outlined">
|
<FormControl error={!!errors.description} size="small" fullWidth variant="outlined">
|
||||||
<InputLabel sx={{pt : 1}} htmlFor="description">توضیحات</InputLabel>
|
<InputLabel sx={{ pt: 1 }} htmlFor="description">
|
||||||
|
توضیحات
|
||||||
|
</InputLabel>
|
||||||
<OutlinedInput
|
<OutlinedInput
|
||||||
id="description"
|
id="description"
|
||||||
label={"توضیحات"}
|
label={"توضیحات"}
|
||||||
@@ -63,51 +71,51 @@ const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
|||||||
{...register("description")}
|
{...register("description")}
|
||||||
size="small"
|
size="small"
|
||||||
fullWidth
|
fullWidth
|
||||||
sx={{mt: 1}}
|
sx={{ mt: 1 }}
|
||||||
type="text"
|
type="text"
|
||||||
/>
|
/>
|
||||||
<FormHelperText
|
<FormHelperText id="description">
|
||||||
id="description">{errors.description ? errors.description.message : null}</FormHelperText>
|
{errors.description ? errors.description.message : null}
|
||||||
|
</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack>
|
<Stack>
|
||||||
<Controller
|
<Controller
|
||||||
name="province"
|
name="province"
|
||||||
control={control}
|
control={control}
|
||||||
render={({field: {onChange, value}, fieldState : {error }}) => (
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
<FormControl error={!!error} size="small" fullWidth variant="outlined">
|
<FormControl error={!!error} size="small" fullWidth variant="outlined">
|
||||||
<InputLabel htmlFor="province"/>
|
<InputLabel htmlFor="province" />
|
||||||
{errorProvinces ? (
|
{errorProvinces ? (
|
||||||
<Typography color={"red"}>خطایی در دریافت استان ها رخ داده است!</Typography>
|
<Typography color={"red"}>خطایی در دریافت استان ها رخ داده است!</Typography>
|
||||||
) :
|
) : loadingProvinces ? (
|
||||||
loadingProvinces ? (
|
<Typography sx={{ display: "flex", alignItems: "center", gap: 2 }}>
|
||||||
<Typography sx={{display : 'flex', alignItems : "center", gap : 2}}>
|
<CircularProgress size={20} />
|
||||||
<CircularProgress size={20} />
|
درحال دریافت لیست استان ها
|
||||||
درحال دریافت لیست استان ها
|
</Typography>
|
||||||
</Typography>
|
) : (
|
||||||
) : (
|
<Autocomplete
|
||||||
<Autocomplete
|
id="province"
|
||||||
id="province"
|
size="small"
|
||||||
size="small"
|
value={provinces.find((province) => province.id === value) || null}
|
||||||
value={provinces.find(province => province.id === value) || null}
|
disablePortal
|
||||||
disablePortal
|
options={provinces}
|
||||||
options={provinces}
|
getOptionLabel={(province) => province.name}
|
||||||
getOptionLabel={(province) => province.name}
|
isOptionEqualToValue={(option, value) => option.id === value.id}
|
||||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
onChange={(event, newValue) => {
|
||||||
onChange={(event, newValue) => {
|
onChange(newValue ? newValue.id : "");
|
||||||
onChange(newValue ? newValue.id : "");
|
}}
|
||||||
}}
|
renderInput={(params) => (
|
||||||
renderInput={(params) => (
|
<TextField
|
||||||
<TextField
|
{...params}
|
||||||
{...params}
|
autoComplete="off"
|
||||||
autoComplete="off"
|
error={!!errors.province}
|
||||||
error={!!errors.province}
|
fullWidth
|
||||||
fullWidth
|
label="استان"
|
||||||
label="استان"
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
|
||||||
<FormHelperText id="province">
|
<FormHelperText id="province">
|
||||||
{errors.province ? errors.province.message : null}
|
{errors.province ? errors.province.message : null}
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
@@ -118,24 +126,14 @@ const ReferFormContext = ({setOpenReferDialog, rowId, mutate}) => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button onClick={() => setOpenReferDialog(false)} variant="outlined" color="secondary" autoFocus>
|
||||||
onClick={() => setOpenReferDialog(false)}
|
|
||||||
variant="outlined"
|
|
||||||
color="secondary"
|
|
||||||
autoFocus
|
|
||||||
>
|
|
||||||
{"انصراف"}
|
{"انصراف"}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button variant="contained" color="primary" type={"submit"} disabled={isSubmitting}>
|
||||||
variant="contained"
|
{isSubmitting ? "در حال اسال" : "ارجاع"}
|
||||||
color="primary"
|
|
||||||
type={"submit"}
|
|
||||||
disabled={isSubmitting}
|
|
||||||
>
|
|
||||||
{isSubmitting ? "در حال اسال" :"ارجاع"}
|
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</StyledForm>
|
</StyledForm>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default ReferFormContext
|
export default ReferFormContext;
|
||||||
|
|||||||
@@ -1,37 +1,41 @@
|
|||||||
import {Dialog, DialogTitle, IconButton, Stack, Tooltip} from "@mui/material";
|
import { Dialog, DialogTitle, IconButton, Stack, Tooltip } from "@mui/material";
|
||||||
import ReplyIcon from '@mui/icons-material/Reply';
|
import ReplyIcon from "@mui/icons-material/Reply";
|
||||||
import DialogTransition from "@/core/components/DialogTransition";
|
import DialogTransition from "@/core/components/DialogTransition";
|
||||||
import {useState} from "react";
|
import { useState } from "react";
|
||||||
import ReferFormContext
|
import ReferFormContext from "@/components/dashboard/inquiryPrivacy/provinceAdmin/zaminGov/RowActions/Refer/ReferFormContext";
|
||||||
from "@/components/dashboard/inquiryPrivacy/provinceAdmin/zaminGov/RowActions/Refer/ReferFormContext";
|
|
||||||
|
|
||||||
const ReferForm = ({rowId, mutate}) => {
|
const ReferForm = ({ rowId, mutate }) => {
|
||||||
const [openReferDialog, setOpenReferDialog] = useState(false)
|
const [openReferDialog, setOpenReferDialog] = useState(false);
|
||||||
return(
|
return (
|
||||||
<Stack>
|
<Stack>
|
||||||
<Tooltip title="ارجاع به استان دیگر" arrow placement="right">
|
<Tooltip title="ارجاع به استان دیگر" arrow placement="right">
|
||||||
<IconButton
|
<IconButton
|
||||||
color="primary"
|
color="primary"
|
||||||
sx={{textTransform: "unset", alignSelf: "center"}}
|
sx={{ textTransform: "unset", alignSelf: "center" }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setOpenReferDialog(true)
|
setOpenReferDialog(true);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ReplyIcon/>
|
<ReplyIcon />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Dialog PaperProps={{
|
<Dialog
|
||||||
sx: {
|
PaperProps={{
|
||||||
transition: 'all .3s',
|
sx: {
|
||||||
boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'
|
transition: "all .3s",
|
||||||
}
|
boxShadow: "rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px",
|
||||||
}} open={openReferDialog} fullWidth TransitionComponent={DialogTransition}>
|
},
|
||||||
|
}}
|
||||||
|
open={openReferDialog}
|
||||||
|
fullWidth
|
||||||
|
TransitionComponent={DialogTransition}
|
||||||
|
>
|
||||||
<DialogTitle sx={{ m: 0, p: 2, borderBottom: 1, borderColor: "divider" }} id="create-dialog">
|
<DialogTitle sx={{ m: 0, p: 2, borderBottom: 1, borderColor: "divider" }} id="create-dialog">
|
||||||
ارجاع به استان دیگر
|
ارجاع به استان دیگر
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<ReferFormContext rowId={rowId} mutate={mutate} setOpenReferDialog={setOpenReferDialog} />
|
<ReferFormContext rowId={rowId} mutate={mutate} setOpenReferDialog={setOpenReferDialog} />
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</Stack>
|
</Stack>
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default ReferForm
|
export default ReferForm;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import ReferForm from "@/components/dashboard/inquiryPrivacy/provinceAdmin/zaminGov/RowActions/Refer";
|
import ReferForm from "@/components/dashboard/inquiryPrivacy/provinceAdmin/zaminGov/RowActions/Refer";
|
||||||
|
|
||||||
const RowActions = ({row, mutate}) => {
|
const RowActions = ({ row, mutate }) => {
|
||||||
return(
|
return (
|
||||||
<ReferForm mutate={mutate} rowId={row.getValue("id")} /> //rowId should pass
|
<ReferForm mutate={mutate} rowId={row.getValue("id")} /> //rowId should pass
|
||||||
)
|
);
|
||||||
}
|
};
|
||||||
export default RowActions
|
export default RowActions;
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ const TaskList = () => {
|
|||||||
filterFn: "equals",
|
filterFn: "equals",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[],
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -121,7 +121,7 @@ const TaskList = () => {
|
|||||||
table_name={"provinceAdminZaminGovList"}
|
table_name={"provinceAdminZaminGovList"}
|
||||||
enableRowActions
|
enableRowActions
|
||||||
positionActionsColumn={"last"}
|
positionActionsColumn={"last"}
|
||||||
renderRowActions={({ row, table }) => <RowActions row={row}/>}
|
renderRowActions={({ row, table }) => <RowActions row={row} />}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ const DataTable_Main = (props) => {
|
|||||||
initialStateProps,
|
initialStateProps,
|
||||||
TableToolbar,
|
TableToolbar,
|
||||||
table_title,
|
table_title,
|
||||||
|
RowActions,
|
||||||
} = props;
|
} = props;
|
||||||
const flatColumns = flattenArrayOfObjects(columns, "columns");
|
const flatColumns = flattenArrayOfObjects(columns, "columns");
|
||||||
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
|
const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 });
|
||||||
@@ -106,11 +107,8 @@ const DataTable_Main = (props) => {
|
|||||||
manualSorting: true,
|
manualSorting: true,
|
||||||
onPaginationChange: setPagination,
|
onPaginationChange: setPagination,
|
||||||
onSortingChange: onSortingChange,
|
onSortingChange: onSortingChange,
|
||||||
renderTopToolbarCustomActions: ({ table }) => (
|
renderTopToolbarCustomActions: ({ table }) => <>{TableToolbar && <TableToolbar mutate={mutate} />}</>,
|
||||||
<>
|
renderRowActions: ({ row }) => <RowActions row={row} mutate={mutate} />,
|
||||||
{TableToolbar && <TableToolbar mutate={mutate} />}
|
|
||||||
</>
|
|
||||||
),
|
|
||||||
...props,
|
...props,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ import { useAuth } from "@/lib/contexts/auth";
|
|||||||
|
|
||||||
const DataTableWithAuth = (props) => {
|
const DataTableWithAuth = (props) => {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
return (
|
return <DataTable user_id={user.username} {...props} />;
|
||||||
<DataTable
|
|
||||||
user_id={user.username}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
export default DataTableWithAuth;
|
export default DataTableWithAuth;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export const CHANGE_USER_PASSWORD = api + "/api/v3/profile/change_password";
|
|||||||
export const GET_LOGIN_ROUTE = api + "/login_dev";
|
export const GET_LOGIN_ROUTE = api + "/login_dev";
|
||||||
export const GET_PERMISSIONS_ROUTE = api + "/webapi/user/get-permission";
|
export const GET_PERMISSIONS_ROUTE = api + "/webapi/user/get-permission";
|
||||||
export const GET_SIDEBAR_BADGE_ROUTE = api + "/v2/activity_statistics";
|
export const GET_SIDEBAR_BADGE_ROUTE = api + "/v2/activity_statistics";
|
||||||
export const REFER_ADMIN_PROVINCE = "/v3/api/fake-submit"
|
export const REFER_ADMIN_PROVINCE = "/v3/api/fake-submit";
|
||||||
export const REFER_ADMIN_CITY = "/v3/api/fake-submit"
|
export const REFER_ADMIN_CITY = "/v3/api/fake-submit";
|
||||||
export const GET_CITY_LISTS = "/v3/api/fake-cities"
|
export const GET_CITY_LISTS = "/v3/api/fake-cities";
|
||||||
export const GET_PROVINCE_LISTS = "/v3/api/fake-provinces"
|
export const GET_PROVINCE_LISTS = "/v3/api/fake-provinces";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {GET_CITY_LISTS} from "@/core/utils/routes";
|
import { GET_CITY_LISTS } from "@/core/utils/routes";
|
||||||
|
|
||||||
const useCities = () => {
|
const useCities = () => {
|
||||||
const [cities, setCities] = useState([]);
|
const [cities, setCities] = useState([]);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {GET_PROVINCE_LISTS} from "@/core/utils/routes";
|
import { GET_PROVINCE_LISTS } from "@/core/utils/routes";
|
||||||
|
|
||||||
const useProvinces = () => {
|
const useProvinces = () => {
|
||||||
const [provinces, setProvinces] = useState([]);
|
const [provinces, setProvinces] = useState([]);
|
||||||
|
|||||||
Reference in New Issue
Block a user