diff --git a/.env.example b/.env.example index cc277d3..1746ff6 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,4 @@ HOST="rms.witel.ir" -NEXT_PUBLIC_VERSION="1.1.5" +NEXT_PUBLIC_VERSION="1.1.6" NEXT_PUBLIC_API_URL="https://rms.witel.ir" NEXT_PUBLIC_MAPTILE_ENDPOINT="https://rmsmap.rmto.ir/141map" \ No newline at end of file diff --git a/src/components/dashboard/damages/operator/OperatorList.jsx b/src/components/dashboard/damages/operator/OperatorList.jsx index 2c07053..584be1b 100644 --- a/src/components/dashboard/damages/operator/OperatorList.jsx +++ b/src/components/dashboard/damages/operator/OperatorList.jsx @@ -14,8 +14,14 @@ import ImageDialog from "./RowActions/ImageDialog"; import LocationForm from "./RowActions/LocationForm"; import ShowPlate from "./RowActions/ShowPlate"; import Toolbar from "./Toolbar"; +import { usePermissions } from "@/lib/hooks/usePermissions"; +import { useAuth } from "@/lib/contexts/auth"; const OperatorList = () => { + const { data: userPermissions } = usePermissions(); + const hasCountryPermission = userPermissions?.includes("show-receipt"); + const { user } = useAuth(); + const statusOptions = [ { value: "", label: "همه وضعیت ها" }, { value: 0, label: "بدون اقدام" }, @@ -26,6 +32,42 @@ const OperatorList = () => { { value: 5, label: "نامه پلیس راه صادر شده است" }, ]; const columns = useMemo(() => { + const provinceColumn = { + accessorKey: "province_id", + header: "استان", + id: "province_id", + enableColumnFilter: true, + datatype: "numeric", + filterMode: "equals", + grow: false, + size: 130, + ColumnSelectComponent: (props) => { + const { provinces, errorProvinces, loadingProvinces } = useProvinces(); + const getColumnSelectOptions = useMemo(() => { + if (loadingProvinces) { + return [{ value: "loading", label: "در حال بارگذاری..." }]; + } + if (errorProvinces) { + return [{ value: "error", label: "خطا در بارگذاری" }]; + } + return [ + { value: "", label: "کل کشور" }, + ...provinces.map((province) => ({ + value: province.id, + label: province.name_fa, + })), + ]; + }, [provinces, errorProvinces, loadingProvinces]); + return ( + + ); + }, + Cell: ({ row }) => <>{row.original.province_fa}, + }; return [ { accessorKey: "id", @@ -39,6 +81,25 @@ const OperatorList = () => { grow: false, size: 100, }, + { + accessorKey: "status", + header: "وضعیت", + id: "status", + enableColumnFilter: true, + datatype: "numeric", + filterMode: "equals", + grow: false, + size: 100, + columnSelectOption: () => { + return statusOptions.map((status) => ({ + value: status.value, + label: status.label, + })); + }, + Cell: ({ row }) => { + return {row.original.status_fa}; + }, + }, { header: "اطلاعات تصادف", id: "accidentInfo", @@ -47,42 +108,7 @@ const OperatorList = () => { grow: false, size: 50, columns: [ - { - accessorKey: "province_id", - header: "استان", - id: "province_id", - enableColumnFilter: true, - datatype: "numeric", - filterMode: "equals", - grow: false, - size: 130, - ColumnSelectComponent: (props) => { - const { provinces, errorProvinces, loadingProvinces } = useProvinces(); - const getColumnSelectOptions = useMemo(() => { - if (loadingProvinces) { - return [{ value: "loading", label: "در حال بارگذاری..." }]; - } - if (errorProvinces) { - return [{ value: "error", label: "خطا در بارگذاری" }]; - } - return [ - { value: "", label: "کل کشور" }, - ...provinces.map((province) => ({ - value: province.id, - label: province.name_fa, - })), - ]; - }, [provinces, errorProvinces, loadingProvinces]); - return ( - - ); - }, - Cell: ({ row }) => <>{row.original.province_fa}, - }, + ...(hasCountryPermission ? [provinceColumn] : []), { accessorKey: "city_id", header: "شهرستان", // Office @@ -90,17 +116,19 @@ const OperatorList = () => { enableColumnFilter: true, datatype: "numeric", filterMode: "equals", - dependencyId: "province_id", + dependencyId: hasCountryPermission ? "province_id" : null, grow: false, size: 120, ColumnSelectComponent: (props) => { const { cityList, loadingCityList, errorCityList } = useCities( - props.dependencyFieldValue.value + hasCountryPermission ? props.dependencyFieldValue.value : user.province_id + ); + const [prevDependency, setPrevDependency] = useState( + hasCountryPermission ? props.dependencyFieldValue.value : user.province_id ); - const [prevDependency, setPrevDependency] = useState(props.dependencyFieldValue.value); const getColumnSelectOptions = useMemo(() => { - if (props.dependencyFieldValue.value === "") { + if (hasCountryPermission && props.dependencyFieldValue.value === "") { return [{ value: "empty", label: "ابتدا استان را انتخاب کنید" }]; } if (loadingCityList) { @@ -118,10 +146,11 @@ const OperatorList = () => { ]; }, [cityList, loadingCityList, errorCityList]); useEffect(() => { + if (hasCountryPermission) return; if (prevDependency === props.dependencyFieldValue?.value) return; props.handleChange({ ...props.filterParameters, value: "" }); setPrevDependency(props.dependencyFieldValue?.value); - }, [props.dependencyFieldValue?.value]); + }, [props.dependencyFieldValue?.value, hasCountryPermission]); return ( { grow: false, size: 100, }, - { - accessorKey: "status", - header: "وضعیت", - id: "status", - enableColumnFilter: true, - datatype: "numeric", - filterMode: "equals", - grow: false, - size: 100, - columnSelectOption: () => { - return statusOptions.map((status) => ({ - value: status.value, - label: status.label, - })); - }, - Cell: ({ row }) => { - return {row.original.status_fa}; - }, - }, ]; }, []); @@ -456,7 +466,7 @@ const OperatorList = () => { sorting={[{ id: "id", desc: true }]} TableToolbar={Toolbar} enableRowActions - positionActionsColumn={"last"} + positionActionsColumn={"first"} RowActions={RowActions} /> diff --git a/src/components/dashboard/roadSafety/operator/Learn/index.jsx b/src/components/dashboard/roadSafety/operator/Learn/index.jsx index 8ea5000..8db03e7 100644 --- a/src/components/dashboard/roadSafety/operator/Learn/index.jsx +++ b/src/components/dashboard/roadSafety/operator/Learn/index.jsx @@ -14,7 +14,7 @@ const Learn = () => { document.body.appendChild(link); link.click(); document.body.removeChild(link); - } + }; return ( <> @@ -36,4 +36,4 @@ const Learn = () => { ); }; -export default Learn; \ No newline at end of file +export default Learn; diff --git a/src/components/dashboard/roadSafety/supervisor/Learn/index.jsx b/src/components/dashboard/roadSafety/supervisor/Learn/index.jsx index 8ea5000..8db03e7 100644 --- a/src/components/dashboard/roadSafety/supervisor/Learn/index.jsx +++ b/src/components/dashboard/roadSafety/supervisor/Learn/index.jsx @@ -14,7 +14,7 @@ const Learn = () => { document.body.appendChild(link); link.click(); document.body.removeChild(link); - } + }; return ( <> @@ -36,4 +36,4 @@ const Learn = () => { ); }; -export default Learn; \ No newline at end of file +export default Learn;