From 6d5db8dd3bed9c1acf50ff2be0631994a0d79894 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Tue, 5 Sep 2023 15:15:11 +0330 Subject: [PATCH 01/25] enable custom tollbar --- public/locales/fa/app.json | 33 +++ .../dashboard/commercial-chief/index.jsx | 2 +- .../dashboard/development-assistant/index.jsx | 2 +- .../dashboard/inspector-expert/index.jsx | 2 +- .../dashboard/machinary-office/index.jsx | 2 +- .../navgan-loan-management/index.jsx | 3 +- .../navgan-province-manager/index.jsx | 2 +- .../passenger-boss/Form/ConfirmForm.jsx | 2 +- .../dashboard/passenger-boss/index.jsx | 3 +- .../dashboard/passenger-office/index.jsx | 3 +- .../dashboard/province-head-expert/index.jsx | 2 +- .../refahi-loan-management/index.jsx | 3 +- .../refahi-province-manager/index.jsx | 3 +- .../transportation-assistance/index.jsx | 2 +- .../user-management/Form/AddForm.jsx | 190 ++++++++++++++++++ .../user-management/Form/DeleteForm.jsx | 60 ++++++ .../user-management/Form/UpdateForm.jsx | 151 ++++++++++++++ .../user-management/TableRowActions.jsx | 23 +++ .../user-management/TableToolbar.jsx | 32 +++ .../dashboard/user-management/index.jsx | 155 ++++++++++++++ src/core/components/DataTable.jsx | 2 +- src/core/data/apiRoutes.js | 11 + src/core/data/sidebarMenu.jsx | 9 + src/pages/dashboard/user-management/index.jsx | 26 +++ 24 files changed, 704 insertions(+), 19 deletions(-) create mode 100644 src/components/dashboard/user-management/Form/AddForm.jsx create mode 100644 src/components/dashboard/user-management/Form/DeleteForm.jsx create mode 100644 src/components/dashboard/user-management/Form/UpdateForm.jsx create mode 100644 src/components/dashboard/user-management/TableRowActions.jsx create mode 100644 src/components/dashboard/user-management/TableToolbar.jsx create mode 100644 src/components/dashboard/user-management/index.jsx create mode 100644 src/pages/dashboard/user-management/index.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 065e317..719ba4a 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -42,6 +42,7 @@ "province-head-expert": "کارشناس ستادی", "change-password": "تغییر رمز عبور", "development-assistant": "معاون توسعه", + "user-management": "مدیریت کاربر", "edit-profile": "ویرایش پروفایل" }, "secondary": { @@ -95,6 +96,7 @@ "development_assistant_page": "معاون توسعه", "inspector_expert_page": "بازدید کارشناس", "commercial_chief_page": "رئیس اداره بازرگانی", + "user_management_page": "مدیریت کاربر", "edit_profile": "ویرایش پروفایل" }, "MuiDatePicker": { @@ -268,6 +270,17 @@ "vehicle_type": "نوع ماشین", "state_name": "وضعیت درخواست" }, + "UserManagement": { + "name": "نام", + "id": "کد یکتا", + "national_id": "کد ملی", + "phone_number": "موبایل", + "created_at": "تاریخ درخواست", + "updated_at": "تاریخ بروزرسانی", + "navgan_id": "کد ناوگان", + "vehicle_type": "نوع ماشین", + "state_name": "وضعیت درخواست" + }, "ConfirmDialog": { "confirm": "تایید", "context": "آیا از تایید این آیتم اطمینان دارید؟", @@ -321,5 +334,25 @@ "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", "delete": "پاک کردن", "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" + }, + "DeleteDialog": { + "delete": "حذف", + "button-cancel": "انصراف", + "button-delete": "حذف کردن" + }, + "AddDialog": { + "add": "اضافه کردن", + "phone_number": "شماره تلفن", + "phone_number_positive": "شماره تلفن باید مثبت باشد", + "phone_number_error": "وارد کردن شماره تلفن الزامیست", + "type_id_error": "وارد کردن نوع کاربر الزامیست", + "navgan_id_error": "وارد کردن کد ناوگان الزامیست", + "national_id_error": "وارد کردن کد ملی الزامیست", + "phone_number_number": "شماره تلفن باید شامل اعداد باشد", + "national_id": "کد ملی", + "type_id": "نوع کاربر", + "navgan_id": "کد ناوگان", + "button-cancel": "انصراف", + "button-add": "اضافه کردن" } } diff --git a/src/components/dashboard/commercial-chief/index.jsx b/src/components/dashboard/commercial-chief/index.jsx index 9f84193..ab514a5 100644 --- a/src/components/dashboard/commercial-chief/index.jsx +++ b/src/components/dashboard/commercial-chief/index.jsx @@ -131,7 +131,7 @@ function DashboardCommercialChiefComponent() { tableUrl={GET_COMMERCIAL_CHIEF} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/development-assistant/index.jsx b/src/components/dashboard/development-assistant/index.jsx index ed46fb0..ab35636 100644 --- a/src/components/dashboard/development-assistant/index.jsx +++ b/src/components/dashboard/development-assistant/index.jsx @@ -132,7 +132,7 @@ function DashboardDevelopmentAssistantComponent() { tableUrl={GET_DEVELOPMENT_ASSISTANT} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/inspector-expert/index.jsx b/src/components/dashboard/inspector-expert/index.jsx index 1be98ed..53a2661 100644 --- a/src/components/dashboard/inspector-expert/index.jsx +++ b/src/components/dashboard/inspector-expert/index.jsx @@ -131,7 +131,7 @@ function DashboardInspectorExpertComponent() { tableUrl={GET_INSPECTOR_EXPERT} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/machinary-office/index.jsx b/src/components/dashboard/machinary-office/index.jsx index 73c373c..b341529 100644 --- a/src/components/dashboard/machinary-office/index.jsx +++ b/src/components/dashboard/machinary-office/index.jsx @@ -162,7 +162,7 @@ function DashboardMachinaryOfficeComponent() { tableUrl={GET_MACHINARY_OFFICE} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/navgan-loan-management/index.jsx b/src/components/dashboard/navgan-loan-management/index.jsx index eddf02b..57d3227 100644 --- a/src/components/dashboard/navgan-loan-management/index.jsx +++ b/src/components/dashboard/navgan-loan-management/index.jsx @@ -132,8 +132,7 @@ function DashboardNavganLoanManagementComponent() { tableUrl={GET_LOAN_MANAGEMENT_NAVGAN} columns={columns} selectableRow={false} - enableCustomToolbar={true} - // CustomToolbar={} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/navgan-province-manager/index.jsx b/src/components/dashboard/navgan-province-manager/index.jsx index 8823e37..a529336 100644 --- a/src/components/dashboard/navgan-province-manager/index.jsx +++ b/src/components/dashboard/navgan-province-manager/index.jsx @@ -163,7 +163,7 @@ function DashboardNavganProvinceManagerComponent() { tableUrl={GET_NAVGAN_PROVINCE_MANAGER} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx b/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx index 4b188f2..7349e22 100644 --- a/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx +++ b/src/components/dashboard/passenger-boss/Form/ConfirmForm.jsx @@ -40,7 +40,7 @@ const Confirm = ({rowId, fetchUrl, mutate}) => { "is-number", `${t("ConfirmDialog.approved_amount_number")}`, (value) => !isNaN(value) - ).test("positive", `${t("ConfirmDialog.proposed_amount_positive")}`, (value) => value >= 0) + ).test("positive", `${t("ConfirmDialog.approved_amount_positive")}`, (value) => value >= 0) .required(t("ConfirmDialog.approved_amount_error")) }); const formik = useFormik({ diff --git a/src/components/dashboard/passenger-boss/index.jsx b/src/components/dashboard/passenger-boss/index.jsx index ad6848f..4f5f553 100644 --- a/src/components/dashboard/passenger-boss/index.jsx +++ b/src/components/dashboard/passenger-boss/index.jsx @@ -163,8 +163,7 @@ function DashboardPassengerOfficeComponent() { tableUrl={GET_PASSENGER_BOSS} columns={columns} selectableRow={false} - enableCustomToolbar={true} - // CustomToolbar={} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/passenger-office/index.jsx b/src/components/dashboard/passenger-office/index.jsx index 3f50345..92335ad 100644 --- a/src/components/dashboard/passenger-office/index.jsx +++ b/src/components/dashboard/passenger-office/index.jsx @@ -163,8 +163,7 @@ function DashboardPassengerOfficeComponent() { tableUrl={GET_PASSENGER_OFFICE} columns={columns} selectableRow={false} - enableCustomToolbar={true} - // CustomToolbar={} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/province-head-expert/index.jsx b/src/components/dashboard/province-head-expert/index.jsx index c76c96d..6a20fa4 100644 --- a/src/components/dashboard/province-head-expert/index.jsx +++ b/src/components/dashboard/province-head-expert/index.jsx @@ -132,7 +132,7 @@ function DashboardProvinceHeadExpertComponent() { tableUrl={GET_PROVINCE_HEAD_EXPERT} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/refahi-loan-management/index.jsx b/src/components/dashboard/refahi-loan-management/index.jsx index 4f0b3e1..762c026 100644 --- a/src/components/dashboard/refahi-loan-management/index.jsx +++ b/src/components/dashboard/refahi-loan-management/index.jsx @@ -132,8 +132,7 @@ function DashboardRefahiLoanManagementComponent() { tableUrl={GET_LOAN_MANAGEMENT_REFAHI} columns={columns} selectableRow={false} - enableCustomToolbar={true} - // CustomToolbar={} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/refahi-province-manager/index.jsx b/src/components/dashboard/refahi-province-manager/index.jsx index 740f6e7..25f7527 100644 --- a/src/components/dashboard/refahi-province-manager/index.jsx +++ b/src/components/dashboard/refahi-province-manager/index.jsx @@ -132,8 +132,7 @@ function DashboardRefahiProvinceManagerComponent() { tableUrl={GET_REFAHI_PROVINCE_MANAGER} columns={columns} selectableRow={false} - enableCustomToolbar={true} - // CustomToolbar={} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/transportation-assistance/index.jsx b/src/components/dashboard/transportation-assistance/index.jsx index 01314d1..351107c 100644 --- a/src/components/dashboard/transportation-assistance/index.jsx +++ b/src/components/dashboard/transportation-assistance/index.jsx @@ -163,7 +163,7 @@ function DashboardTransportationAssistanceComponent() { tableUrl={GET_TRANSPORTATION_ASSISTANCE} columns={columns} selectableRow={false} - enableCustomToolbar={true} + enableCustomToolbar={false} enableLastUpdate={true} enablePinning={true} enableDensityToggle={false} diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx new file mode 100644 index 0000000..a13ec48 --- /dev/null +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -0,0 +1,190 @@ +import {useTranslations} from "next-intl"; +import * as Yup from "yup"; +import {ADD_USER_MANAGEMENT} from "@/core/data/apiRoutes"; +import {useFormik} from "formik"; +import {Button, Dialog, DialogActions, DialogContent, DialogTitle, Stack, TextField} from "@mui/material"; +import useRequest from "@/lib/app/hooks/useRequest"; + +const AddForm = ({openConfirmDialog, setOpenConfirmDialog, mutate, fetchUrl}) => { + const t = useTranslations(); + const requestServer = useRequest({auth: true}) + const validationSchema = Yup.object().shape({ + phone_number: Yup.mixed().test( + "is-number", + `${t("AddDialog.phone_number_number")}`, + (value) => !isNaN(value) + ).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) + .required(t("AddDialog.phone_number_error")), + type_id: Yup.number().required(t("AddDialog.type_id_error")), + navgan_id: Yup.number().required(t("AddDialog.navgan_id_error")), + national_id: Yup.number().required(t("AddDialog.national_id_error")), + }); + + // const handleSubmit = async (values, {setSubmitting, resetForm}) => { + // const formData = new FormData(); + // formData.append("phone_number", values.phone_number); + // formData.append("national_id", values.national_id); + // formData.append("type_id", values.type_id); + // formData.append("navgan_id", values.navgan_id); + // requestServer(ADD_USER_MANAGEMENT, 'post', { + // data: formData, + // }).then((response) => { + // mutate(fetchUrl) + // update_notification() + // }).catch(() => { + // }).finally(() => { + // setSubmitting(false); + // }); + // }; + // initialValues: { + // phone_number: "", + // national_id: "", + // type_id: "", + // navgan_id: "" + // } + const formik = useFormik({ + initialValues: { + phone_number: "", + national_id: "", + type_id: "", + navgan_id: "", + }, validationSchema, + onSubmit: (values, {setSubmitting}) => { + console.log("hello") + const formData = new FormData(); + formData.append("phone_number", values.phone_number); + formData.append("national_id", values.national_id); + formData.append("type_id", values.type_id); + formData.append("navgan_id", values.navgan_id); + + requestServer(ADD_USER_MANAGEMENT, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + const handlePhoneNumberChange = (event) => { + formik.setFieldValue("phone_number", event.target.value) + }; + const handleNationalIDChange = (event) => { + formik.setFieldValue("national_id", event.target.value) + }; + const handleTypeIDChange = (event) => { + formik.setFieldValue("type_id", event.target.value) + }; + const handleNavganIDChange = (event) => { + formik.setFieldValue("navgan_id", event.target.value) + }; + return ( + + {t("AddDialog.add")} + + + + + + + + + + + + + + + + + + + + + + ); +}; +export default AddForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/Form/DeleteForm.jsx b/src/components/dashboard/user-management/Form/DeleteForm.jsx new file mode 100644 index 0000000..122354b --- /dev/null +++ b/src/components/dashboard/user-management/Form/DeleteForm.jsx @@ -0,0 +1,60 @@ +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import {Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip} from "@mui/material"; +import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; +import {useFormik} from "formik"; +import {DELETE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; + + +const DeleteForm = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const formik = useFormik({ + onSubmit: (values, {setSubmitting}) => { + + + requestServer(`${DELETE_USER_MANAGEMENT}/${rowId}`, 'post').then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("DeleteDialog.delete")} + + + + + + + ); +}; +export default DeleteForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/Form/UpdateForm.jsx b/src/components/dashboard/user-management/Form/UpdateForm.jsx new file mode 100644 index 0000000..ea16667 --- /dev/null +++ b/src/components/dashboard/user-management/Form/UpdateForm.jsx @@ -0,0 +1,151 @@ +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + IconButton, + Stack, + TextField, + Tooltip +} from "@mui/material"; +import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; +import {useFormik} from "formik"; +import {UPDATE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; + + +const UpdateForm = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const formik = useFormik({ + initialValues: { + phone_number: "", + national_id: "", + type_id: "", + navgan_id: "", + }, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("phone_number", values.phone_number); + formData.append("national_id", values.national_id); + formData.append("type_id", values.type_id); + formData.append("navgan_id", values.navgan_id); + + requestServer(`${UPDATE_USER_MANAGEMENT}/${rowId}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + const handlePhoneNumberChange = (event) => { + formik.setFieldValue("phone_number", event.target.value) + }; + const handleNationalIDChange = (event) => { + formik.setFieldValue("national_id", event.target.value) + }; + const handleTypeIDChange = (event) => { + formik.setFieldValue("type_id", event.target.value) + }; + const handleNavganIDChange = (event) => { + formik.setFieldValue("navgan_id", event.target.value) + }; + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("ConfirmDialog.confirm")} + + + + + + + + + + + + + + + + + + + + + + + ); +}; +export default UpdateForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/TableRowActions.jsx b/src/components/dashboard/user-management/TableRowActions.jsx new file mode 100644 index 0000000..c67acb3 --- /dev/null +++ b/src/components/dashboard/user-management/TableRowActions.jsx @@ -0,0 +1,23 @@ +import {Box} from "@mui/material"; +import DeleteForm from "./Form/DeleteForm" +import UpdateForm from "./Form/UpdateForm" + +const TableRowActions = ({row, mutate, fetchUrl}) => { + + return ( + + + + + ); +}; + +export default TableRowActions; diff --git a/src/components/dashboard/user-management/TableToolbar.jsx b/src/components/dashboard/user-management/TableToolbar.jsx new file mode 100644 index 0000000..7371fbc --- /dev/null +++ b/src/components/dashboard/user-management/TableToolbar.jsx @@ -0,0 +1,32 @@ +import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; +import {Button, Stack, Tooltip} from "@mui/material"; +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import AddForm from "./Form/AddForm"; + +function TableToolbar({mutate, fetchUrl}) { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + return ( + + + + + + + ); +} + +export default TableToolbar; diff --git a/src/components/dashboard/user-management/index.jsx b/src/components/dashboard/user-management/index.jsx new file mode 100644 index 0000000..596c7e6 --- /dev/null +++ b/src/components/dashboard/user-management/index.jsx @@ -0,0 +1,155 @@ +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import {Box, Typography} from "@mui/material"; +import {useMemo} from "react"; +import {GET_USER_MANAGEMENT} from "@/core/data/apiRoutes"; +import {useTranslations} from "next-intl"; +import DataTable from "@/core/components/DataTable"; +import moment from "jalali-moment"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import TableToolbar from "@/components/dashboard/user-management/TableToolbar"; +import TableRowActions from "./TableRowActions" + +function DashboardUserManagementComponent() { + const t = useTranslations(); + + const columns = useMemo( + () => [ + { + accessorFn: (row) => row.id, + id: "id", + header: t("UserManagement.id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.name, + id: "name", + header: t("UserManagement.name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.national_id, + id: "national_id", + header: t("UserManagement.national_id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.phone_number, + id: "phone_number", + header: t("UserManagement.phone_number"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => + moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "created_at", + header: t("UserManagement.created_at"), + enableColumnFilter: true, + datatype: "date", + filterFn: "lessThan", + columnFilterModeOptions: ["lessThan", "greaterThan"], + Cell: ({renderedCellValue}) => { + return {renderedCellValue}; + }, + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return ( + + ); + }, + }, + { + accessorFn: (row) => + moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "updated_at", + header: t("UserManagement.updated_at"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.state_name, + id: "state_id", + header: t("UserManagement.state_name"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + ], + [] + ); + return ( + + + + + + ); +} + +export default DashboardUserManagementComponent; diff --git a/src/core/components/DataTable.jsx b/src/core/components/DataTable.jsx index b3b0f26..8d06a02 100644 --- a/src/core/components/DataTable.jsx +++ b/src/core/components/DataTable.jsx @@ -134,7 +134,7 @@ function DataTable(props) { renderTopToolbarCustomActions={({table}) => ( <> {props.enableCustomToolbar /* send condition */ - ? props.CustomToolbar /* send component */ + ? /* send component */ : ""} )} diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index aba46f1..19b89a2 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -150,3 +150,14 @@ export const UPDATE_LOAN_MANAGEMENT_NAVGAN = export const GET_LOAN_STATE_NAVGAN = BASE_URL + "/dashboard/loan_states/navgan" //loan management navgan + +//user management +export const GET_USER_MANAGEMENT = + BASE_URL + "/dashboard/user_management/show" +export const ADD_USER_MANAGEMENT = + BASE_URL + "/dashboard/user_management/store" +export const UPDATE_USER_MANAGEMENT = + BASE_URL + "/dashboard/user_management/update" +export const DELETE_USER_MANAGEMENT = + BASE_URL + "/dashboard/user_management/delete" +//user management diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 21a0952..29eab1d 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -136,6 +136,15 @@ const sidebarMenu = [ selected: false, permission: "manage_navgan_loan", }, + { + key: "sidebar.user-management", + name: "user_management", + type: "page", + route: "/dashboard/user-management", + icon: , + selected: false, + permission: "user_management", + }, ], ]; diff --git a/src/pages/dashboard/user-management/index.jsx b/src/pages/dashboard/user-management/index.jsx new file mode 100644 index 0000000..ce9cc1e --- /dev/null +++ b/src/pages/dashboard/user-management/index.jsx @@ -0,0 +1,26 @@ +import RolePermissionMiddleware from "@/middlewares/RolePermission"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; +import {parse} from "next-useragent"; +import DashboardUserManagementComponent from "@/components/dashboard/user-management"; + +const requiredPermissions = ["manage_refahi_loan"]; +export default function UserManagement() { + return ( + + + + + + ); +} + +export async function getServerSideProps({req, locale}) { + const {isBot} = parse(req.headers["user-agent"]); + return { + props: { + messages: (await import(`&/locales/${locale}/app.json`)).default, + title: "Dashboard.user_management_page", + isBot, + }, + }; +} From 57c9c44903d72980920fe1295f198659f27812d2 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Wed, 6 Sep 2023 14:43:43 +0330 Subject: [PATCH 02/25] make ready structure and directories for expert management implemention --- public/locales/fa/app.json | 6 +- .../expert-management/Form/DeleteForm.jsx | 85 +++++++++++++++++++ .../expert-management/Form/UpdateForm.jsx | 24 ++++++ .../expert-management/TableRowActions.jsx | 17 ++++ .../dashboard/expert-management/index.jsx | 60 +++++++++++++ src/core/data/apiRoutes.js | 13 +++ src/core/data/sidebarMenu.jsx | 10 +++ .../dashboard/expert-management/index.jsx | 26 ++++++ 8 files changed, 240 insertions(+), 1 deletion(-) create mode 100644 src/components/dashboard/expert-management/Form/DeleteForm.jsx create mode 100644 src/components/dashboard/expert-management/Form/UpdateForm.jsx create mode 100644 src/components/dashboard/expert-management/TableRowActions.jsx create mode 100644 src/components/dashboard/expert-management/index.jsx create mode 100644 src/pages/dashboard/expert-management/index.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 065e317..bf4d7d2 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -42,7 +42,8 @@ "province-head-expert": "کارشناس ستادی", "change-password": "تغییر رمز عبور", "development-assistant": "معاون توسعه", - "edit-profile": "ویرایش پروفایل" + "edit-profile": "ویرایش پروفایل", + "expert-management": "مدیریت کارشناسان" }, "secondary": { "passenger-office": "توزیع درخواست", @@ -321,5 +322,8 @@ "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", "delete": "پاک کردن", "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" + }, + "ExpertMangement": { + "id": "کد یکتا" } } diff --git a/src/components/dashboard/expert-management/Form/DeleteForm.jsx b/src/components/dashboard/expert-management/Form/DeleteForm.jsx new file mode 100644 index 0000000..eb5b4c0 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/DeleteForm.jsx @@ -0,0 +1,85 @@ +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControl, + FormHelperText, + IconButton, + InputLabel, + MenuItem, + Select, + Stack, + TextField, + Tooltip +} from "@mui/material"; +import {useFormik} from "formik"; +import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; +import {UPDATE_LOAN_MANAGEMENT_REFAHI} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; +import * as Yup from "yup"; +import useLoanStateRefahi from "@/lib/prefetchDataTable/hooks/useLoanStateRefahi"; + + +const Delete = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const {loan_state_refahi} = useLoanStateRefahi() + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + + const validationSchema = Yup.object().shape({ + description: Yup.string().required(t("UpdateDialog.description_error")), + next_state_id: Yup.number().required(t("UpdateDialog.next-state-id-error")) + }); + + const formik = useFormik({ + initialValues: { + description: "", + next_state_id: "" + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("description", values.description); + formData.append("next_state_id", values.next_state_id); + + requestServer(`${UPDATE_LOAN_MANAGEMENT_REFAHI}/${rowId}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + const handleDescriptionChange = (event) => { + formik.setFieldValue("description", event.target.value) + }; + const handleNextStateIDChange = (event) => { + formik.setFieldValue("next_state_id", event.target.value) + }; + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + ); +}; +export default Delete; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/Form/UpdateForm.jsx b/src/components/dashboard/expert-management/Form/UpdateForm.jsx new file mode 100644 index 0000000..a456677 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/UpdateForm.jsx @@ -0,0 +1,24 @@ +import {useTranslations} from "next-intl"; +import {IconButton, Tooltip} from "@mui/material"; +import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; + + +const Update = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + ); +}; +export default Update; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/TableRowActions.jsx b/src/components/dashboard/expert-management/TableRowActions.jsx new file mode 100644 index 0000000..fd599f9 --- /dev/null +++ b/src/components/dashboard/expert-management/TableRowActions.jsx @@ -0,0 +1,17 @@ +import {Box} from "@mui/material"; +import Update from "./Form/UpdateForm" + +const TableRowActions = ({row, mutate, fetchUrl}) => { + + return ( + + + + ); +}; + +export default TableRowActions; diff --git a/src/components/dashboard/expert-management/index.jsx b/src/components/dashboard/expert-management/index.jsx new file mode 100644 index 0000000..a792cb6 --- /dev/null +++ b/src/components/dashboard/expert-management/index.jsx @@ -0,0 +1,60 @@ +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import {Box, Typography} from "@mui/material"; +import {useMemo} from "react"; +import {GET_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; +import {useTranslations} from "next-intl"; +import TableRowActions from "./TableRowActions"; +import DataTable from "@/core/components/DataTable"; + +function DashboardExpertManagementComponent() { + const t = useTranslations(); + const columns = useMemo( + () => [ + { + accessorFn: (row) => row.id, + id: "id", + header: t("ExpertMangement.id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: [ + "equals", + "notEquals", + "contains", + "lessThan", + "greaterThan", + "between", + ], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + ], + [] + ); + return ( + + + + + + ); +} + +export default DashboardExpertManagementComponent; diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index aba46f1..d7d728a 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -150,3 +150,16 @@ export const UPDATE_LOAN_MANAGEMENT_NAVGAN = export const GET_LOAN_STATE_NAVGAN = BASE_URL + "/dashboard/loan_states/navgan" //loan management navgan + +//expert management +export const GET_EXPERT_MANAGEMENT = + BASE_URL + "/dashboard/experts/show" +export const CREATE_EXPERT_MANAGEMENT = + BASE_URL + "/dashboard/experts/store" +export const UPDATE_EXPERT_MANAGEMENT = + BASE_URL + "/dashboard/experts/update" +export const DELETE_EXPERT_MANAGEMENT = + BASE_URL + "/dashboard/experts/delete" +export const CHANGE_PASSWORD_EXPERT_MANAGEMENT = + BASE_URL + "/dashboard/experts/change_password" +//expert management diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 21a0952..dfc3daa 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -10,6 +10,7 @@ import GradingIcon from '@mui/icons-material/Grading'; import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle'; import Diversity3Icon from '@mui/icons-material/Diversity3'; import PaidIcon from '@mui/icons-material/Paid'; +import ManageAccountsIcon from '@mui/icons-material/ManageAccounts'; const sidebarMenu = [ [ @@ -136,6 +137,15 @@ const sidebarMenu = [ selected: false, permission: "manage_navgan_loan", }, + { + key: "sidebar.expert-management", + name: "expert_management", + type: "page", + route: "/dashboard/expert-management", + icon: , + selected: false, + permission: "manage_navgan_loan", + }, ], ]; diff --git a/src/pages/dashboard/expert-management/index.jsx b/src/pages/dashboard/expert-management/index.jsx new file mode 100644 index 0000000..84518f7 --- /dev/null +++ b/src/pages/dashboard/expert-management/index.jsx @@ -0,0 +1,26 @@ +import RolePermissionMiddleware from "@/middlewares/RolePermission"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; +import {parse} from "next-useragent"; +import DashboardExpertManagementComponent from "@/components/dashboard/expert-management"; + +const requiredPermissions = ["manage_transportation_navgan"]; +export default function ExpertMangement() { + return ( + + + + + + ); +} + +export async function getServerSideProps({req, locale}) { + const {isBot} = parse(req.headers["user-agent"]); + return { + props: { + messages: (await import(`&/locales/${locale}/app.json`)).default, + title: "Dashboard.expert_management", + isBot, + }, + }; +} From 525cd1e62b49e6c9b73a3a73db576141fedfc941 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 10 Sep 2023 10:45:20 +0330 Subject: [PATCH 03/25] TF-4 AddDialog completed --- public/locales/fa/app.json | 22 +- .../user-management/Form/AddForm.jsx | 302 ++++++++++-------- .../user-management/Form/DeleteForm.jsx | 4 +- .../user-management/Form/UpdateForm.jsx | 24 +- .../user-management/TableToolbar.jsx | 27 +- 5 files changed, 191 insertions(+), 188 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 719ba4a..f51eb1a 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -321,11 +321,7 @@ "update": "تغییر وضعیت درخواست", "update-tooltip": "بروزرسانی", "button-cancel": "بستن", - "button-update": "بروزرسانی", - "description": "توضیحات خود را وارد نمائید", - "description_error": "وارد کردن توضیحات الزامی است!", - "next-state-id": "وضعیت بعدی", - "next-state-id-error": "وارد کردن وضعیت بعدی الزامی است!" + "button-update": "بروزرسانی" }, "UploadSystem": { "upload_file": "فایل خود را بارگذاری کنید", @@ -333,6 +329,10 @@ "upload_file_unit": "حداکثر 2Mb", "upload_file_format": "فرمت قابل قبول : png,jpg,pdf", "delete": "پاک کردن", + "phone_number": "شماره تلفن", + "national_id": "کد ملی", + "navgan_id": "کد ناوگان", + "type_id": "نوع کاربر", "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" }, "DeleteDialog": { @@ -345,11 +345,17 @@ "phone_number": "شماره تلفن", "phone_number_positive": "شماره تلفن باید مثبت باشد", "phone_number_error": "وارد کردن شماره تلفن الزامیست", + "phone_number_number": "شماره تلفن باید شامل اعداد باشد", + "phone_number_max": "شماره تلفن باید شامل 11 رقم باشد", + "national_id_positive": "کد ملی باید مثبت باشد", + "national_id_number": "کد ملی باید شامل اعداد باشد", + "national_id_max": "کد ملی باید شامل 10 رقم باشد", + "national_id": "کد ملی", + "national_id_error": "وارد کردن کد ملی الزامیست", "type_id_error": "وارد کردن نوع کاربر الزامیست", "navgan_id_error": "وارد کردن کد ناوگان الزامیست", - "national_id_error": "وارد کردن کد ملی الزامیست", - "phone_number_number": "شماره تلفن باید شامل اعداد باشد", - "national_id": "کد ملی", + "refahi": "رفاهی", + "navgan": "ناوگان", "type_id": "نوع کاربر", "navgan_id": "کد ناوگان", "button-cancel": "انصراف", diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx index a13ec48..1f26ecf 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -2,46 +2,48 @@ import {useTranslations} from "next-intl"; import * as Yup from "yup"; import {ADD_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import {useFormik} from "formik"; -import {Button, Dialog, DialogActions, DialogContent, DialogTitle, Stack, TextField} from "@mui/material"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControl, + FormHelperText, + InputLabel, + MenuItem, + Select, + Stack, + TextField, + Tooltip +} from "@mui/material"; import useRequest from "@/lib/app/hooks/useRequest"; +import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; +import {useState} from "react"; -const AddForm = ({openConfirmDialog, setOpenConfirmDialog, mutate, fetchUrl}) => { +const AddForm = ({mutate, fetchUrl}) => { const t = useTranslations(); const requestServer = useRequest({auth: true}) + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); const validationSchema = Yup.object().shape({ phone_number: Yup.mixed().test( "is-number", `${t("AddDialog.phone_number_number")}`, (value) => !isNaN(value) ).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) + .test("max", `${t("AddDialog.phone_number_max")}`, (value) => value.length <= 11) .required(t("AddDialog.phone_number_error")), + national_id: Yup.mixed().test( + "is-number", + `${t("AddDialog.national_id_number")}`, + (value) => !isNaN(value) + ).test("positive", `${t("AddDialog.national_id_positive")}`, (value) => value >= 0) + .test("max", `${t("AddDialog.national_id_max")}`, (value) => value.length <= 10) + .required(t("AddDialog.national_id_error")), type_id: Yup.number().required(t("AddDialog.type_id_error")), navgan_id: Yup.number().required(t("AddDialog.navgan_id_error")), - national_id: Yup.number().required(t("AddDialog.national_id_error")), }); - // const handleSubmit = async (values, {setSubmitting, resetForm}) => { - // const formData = new FormData(); - // formData.append("phone_number", values.phone_number); - // formData.append("national_id", values.national_id); - // formData.append("type_id", values.type_id); - // formData.append("navgan_id", values.navgan_id); - // requestServer(ADD_USER_MANAGEMENT, 'post', { - // data: formData, - // }).then((response) => { - // mutate(fetchUrl) - // update_notification() - // }).catch(() => { - // }).finally(() => { - // setSubmitting(false); - // }); - // }; - // initialValues: { - // phone_number: "", - // national_id: "", - // type_id: "", - // navgan_id: "" - // } const formik = useFormik({ initialValues: { phone_number: "", @@ -60,6 +62,7 @@ const AddForm = ({openConfirmDialog, setOpenConfirmDialog, mutate, fetchUrl}) => requestServer(ADD_USER_MANAGEMENT, 'post', { data: formData, }).then((response) => { + setOpenConfirmDialog(false) mutate(fetchUrl) update_notification() }).catch(() => { @@ -68,123 +71,142 @@ const AddForm = ({openConfirmDialog, setOpenConfirmDialog, mutate, fetchUrl}) => }); }, }); - const handlePhoneNumberChange = (event) => { - formik.setFieldValue("phone_number", event.target.value) - }; - const handleNationalIDChange = (event) => { - formik.setFieldValue("national_id", event.target.value) - }; - const handleTypeIDChange = (event) => { - formik.setFieldValue("type_id", event.target.value) - }; - const handleNavganIDChange = (event) => { - formik.setFieldValue("navgan_id", event.target.value) - }; return ( - - {t("AddDialog.add")} - - - - - - - - - - - - - - - - - - - - - + + + {t("AddDialog.add")} + + + + { + if (event.target.value.length <= 11) return formik.handleChange(event) + }} + fullWidth + variant="outlined" + onBlur={formik.handleBlur("phone_number")} + error={ + formik.touched.phone_number && + Boolean(formik.errors.phone_number) + } + helperText={ + formik.touched.phone_number && formik.errors.phone_number + } + sx={{mt: 1}} + /> + + + { + if (event.target.value.length <= 10) return formik.handleChange(event) + }} + fullWidth + variant="outlined" + onBlur={formik.handleBlur("national_id")} + error={ + formik.touched.national_id && + Boolean(formik.errors.national_id) + } + helperText={ + formik.touched.national_id && formik.errors.national_id + } + sx={{mt: 1}} + /> + + + + {t("AddDialog.type_id")} + + + {formik.touched.type_id && formik.errors.type_id} + + + + + + + + + + + + + + ); }; export default AddForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/Form/DeleteForm.jsx b/src/components/dashboard/user-management/Form/DeleteForm.jsx index 122354b..2e44a2f 100644 --- a/src/components/dashboard/user-management/Form/DeleteForm.jsx +++ b/src/components/dashboard/user-management/Form/DeleteForm.jsx @@ -1,8 +1,8 @@ import {useTranslations} from "next-intl"; import {useState} from "react"; import {Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip} from "@mui/material"; -import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import {useFormik} from "formik"; +import DeleteIcon from '@mui/icons-material/Delete'; import {DELETE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useNotification from "@/lib/app/hooks/useNotification"; @@ -37,7 +37,7 @@ const DeleteForm = ({rowId, fetchUrl, mutate}) => { setOpenConfirmDialog(true) }} > - + { return ( <> - + { setOpenConfirmDialog(true) }} > - + - {t("ConfirmDialog.confirm")} + {t("UpdateDialog.update")} { { { { diff --git a/src/components/dashboard/user-management/TableToolbar.jsx b/src/components/dashboard/user-management/TableToolbar.jsx index 7371fbc..558cdc5 100644 --- a/src/components/dashboard/user-management/TableToolbar.jsx +++ b/src/components/dashboard/user-management/TableToolbar.jsx @@ -1,32 +1,11 @@ -import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; -import {Button, Stack, Tooltip} from "@mui/material"; import {useTranslations} from "next-intl"; -import {useState} from "react"; import AddForm from "./Form/AddForm"; function TableToolbar({mutate, fetchUrl}) { const t = useTranslations(); - const [openConfirmDialog, setOpenConfirmDialog] = useState(false); - return ( - - - - - - - ); + + return + } export default TableToolbar; From 77644bbf5f233a911ec495d95f52f4f10194c63e Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 10 Sep 2023 11:33:33 +0330 Subject: [PATCH 04/25] TF-4 delete and update Dialog --- public/locales/fa/app.json | 6 + .../user-management/Form/AddForm.jsx | 1 - .../user-management/Form/DeleteForm.jsx | 32 +++-- .../user-management/Form/UpdateForm.jsx | 115 +++++++++++++----- 4 files changed, 106 insertions(+), 48 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index f51eb1a..7f2f162 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -321,6 +321,12 @@ "update": "تغییر وضعیت درخواست", "update-tooltip": "بروزرسانی", "button-cancel": "بستن", + "refahi": "رفاهی", + "navgan": "ناوگان", + "phone_number": "شماره تلفن", + "national_id": "کد ملی", + "type_id": "نوع کاربر", + "navgan_id": "کد ناوگان", "button-update": "بروزرسانی" }, "UploadSystem": { diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx index 1f26ecf..d807d68 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -52,7 +52,6 @@ const AddForm = ({mutate, fetchUrl}) => { navgan_id: "", }, validationSchema, onSubmit: (values, {setSubmitting}) => { - console.log("hello") const formData = new FormData(); formData.append("phone_number", values.phone_number); formData.append("national_id", values.national_id); diff --git a/src/components/dashboard/user-management/Form/DeleteForm.jsx b/src/components/dashboard/user-management/Form/DeleteForm.jsx index 2e44a2f..f336036 100644 --- a/src/components/dashboard/user-management/Form/DeleteForm.jsx +++ b/src/components/dashboard/user-management/Form/DeleteForm.jsx @@ -1,32 +1,28 @@ import {useTranslations} from "next-intl"; import {useState} from "react"; import {Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip} from "@mui/material"; -import {useFormik} from "formik"; import DeleteIcon from '@mui/icons-material/Delete'; import {DELETE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useNotification from "@/lib/app/hooks/useNotification"; - const DeleteForm = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false) const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() - const formik = useFormik({ - onSubmit: (values, {setSubmitting}) => { - - - requestServer(`${DELETE_USER_MANAGEMENT}/${rowId}`, 'post').then((response) => { - mutate(fetchUrl) - update_notification() - }).catch(() => { - }).finally(() => { - setSubmitting(false); - }); - }, - }); + const handleSubmit = () => { + setIsSubmitting(true) + requestServer(`${DELETE_USER_MANAGEMENT}/${rowId}`, 'delete').then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setIsSubmitting(false) + }); + } return ( <> @@ -45,11 +41,11 @@ const DeleteForm = ({rowId, fetchUrl, mutate}) => { {t("DeleteDialog.delete")} - diff --git a/src/components/dashboard/user-management/Form/UpdateForm.jsx b/src/components/dashboard/user-management/Form/UpdateForm.jsx index 1eef4a8..257fce8 100644 --- a/src/components/dashboard/user-management/Form/UpdateForm.jsx +++ b/src/components/dashboard/user-management/Form/UpdateForm.jsx @@ -6,7 +6,12 @@ import { DialogActions, DialogContent, DialogTitle, + FormControl, + FormHelperText, IconButton, + InputLabel, + MenuItem, + Select, Stack, TextField, Tooltip @@ -16,7 +21,7 @@ import UpdateIcon from '@mui/icons-material/Update'; import {UPDATE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useNotification from "@/lib/app/hooks/useNotification"; - +import * as Yup from "yup"; const UpdateForm = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); @@ -24,20 +29,38 @@ const UpdateForm = ({rowId, fetchUrl, mutate}) => { const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() + const validationSchema = Yup.object().shape({ + phone_number: Yup.mixed().test( + "is-number", + `${t("AddDialog.phone_number_number")}`, + (value) => !isNaN(value) + ).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) + .test("max", `${t("AddDialog.phone_number_max")}`, (value) => value.length <= 11) + .required(t("AddDialog.phone_number_error")), + national_id: Yup.mixed().test( + "is-number", + `${t("AddDialog.national_id_number")}`, + (value) => !isNaN(value) + ).test("positive", `${t("AddDialog.national_id_positive")}`, (value) => value >= 0) + .test("max", `${t("AddDialog.national_id_max")}`, (value) => value.length <= 10) + .required(t("AddDialog.national_id_error")), + type_id: Yup.number().required(t("AddDialog.type_id_error")), + navgan_id: Yup.number().required(t("AddDialog.navgan_id_error")), + }); + const formik = useFormik({ initialValues: { phone_number: "", national_id: "", type_id: "", navgan_id: "", - }, + }, validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("phone_number", values.phone_number); formData.append("national_id", values.national_id); formData.append("type_id", values.type_id); formData.append("navgan_id", values.navgan_id); - requestServer(`${UPDATE_USER_MANAGEMENT}/${rowId}`, 'post', { data: formData, }).then((response) => { @@ -50,19 +73,6 @@ const UpdateForm = ({rowId, fetchUrl, mutate}) => { }, }); - const handlePhoneNumberChange = (event) => { - formik.setFieldValue("phone_number", event.target.value) - }; - const handleNationalIDChange = (event) => { - formik.setFieldValue("national_id", event.target.value) - }; - const handleTypeIDChange = (event) => { - formik.setFieldValue("type_id", event.target.value) - }; - const handleNavganIDChange = (event) => { - formik.setFieldValue("navgan_id", event.target.value) - }; - return ( <> @@ -86,9 +96,19 @@ const UpdateForm = ({rowId, fetchUrl, mutate}) => { rows={8} label={t("UpdateDialog.phone_number")} value={formik.values.phone_number} - onChange={handlePhoneNumberChange} + onChange={(event) => { + if (event.target.value.length <= 11) return formik.handleChange(event) + }} fullWidth variant="outlined" + onBlur={formik.handleBlur("phone_number")} + error={ + formik.touched.phone_number && + Boolean(formik.errors.phone_number) + } + helperText={ + formik.touched.phone_number && formik.errors.phone_number + } sx={{mt: 1}} /> @@ -98,23 +118,52 @@ const UpdateForm = ({rowId, fetchUrl, mutate}) => { rows={8} label={t("UpdateDialog.national_id")} value={formik.values.national_id} - onChange={handleNationalIDChange} + onChange={(event) => { + if (event.target.value.length <= 10) return formik.handleChange(event) + }} fullWidth variant="outlined" + onBlur={formik.handleBlur("national_id")} + error={ + formik.touched.national_id && + Boolean(formik.errors.national_id) + } + helperText={ + formik.touched.national_id && formik.errors.national_id + } sx={{mt: 1}} /> - + + {t("UpdateDialog.type_id")} + + + {formik.touched.type_id && formik.errors.type_id} + + { rows={8} label={t("UpdateDialog.navgan_id")} value={formik.values.navgan_id} - onChange={handleNavganIDChange} + onChange={formik.handleChange} fullWidth variant="outlined" + onBlur={formik.handleBlur("navgan_id")} + error={ + formik.touched.navgan_id && + Boolean(formik.errors.navgan_id) + } + helperText={ + formik.touched.navgan_id && formik.errors.navgan_id + } sx={{mt: 1}} /> From ae8e2a3378cfeb3d3f70cf365045eda557fc881f Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 10 Sep 2023 15:08:41 +0330 Subject: [PATCH 05/25] TF-4 user management edit form --- public/locales/fa/app.json | 8 +- .../user-management/Form/AddForm.jsx | 6 +- .../user-management/Form/DeleteForm.jsx | 15 +- .../user-management/Form/UpdateForm.jsx | 260 ++++++++---------- .../user-management/TableRowActions.jsx | 2 +- .../dashboard/user-management/index.jsx | 12 +- 6 files changed, 143 insertions(+), 160 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 7f2f162..e2e5105 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -278,6 +278,7 @@ "created_at": "تاریخ درخواست", "updated_at": "تاریخ بروزرسانی", "navgan_id": "کد ناوگان", + "type_name": "نوع کاربر", "vehicle_type": "نوع ماشین", "state_name": "وضعیت درخواست" }, @@ -318,8 +319,8 @@ "description_error": "وارد کردن توضیحات الزامی است!" }, "UpdateDialog": { - "update": "تغییر وضعیت درخواست", - "update-tooltip": "بروزرسانی", + "update": "ویرایش", + "update-tooltip": "ویرایش", "button-cancel": "بستن", "refahi": "رفاهی", "navgan": "ناوگان", @@ -327,7 +328,7 @@ "national_id": "کد ملی", "type_id": "نوع کاربر", "navgan_id": "کد ناوگان", - "button-update": "بروزرسانی" + "button-update": "ویرایش" }, "UploadSystem": { "upload_file": "فایل خود را بارگذاری کنید", @@ -344,6 +345,7 @@ "DeleteDialog": { "delete": "حذف", "button-cancel": "انصراف", + "typography": "آیا از حدف این مورد اطمینان دارید ؟", "button-delete": "حذف کردن" }, "AddDialog": { diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx index d807d68..c0021e8 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -147,11 +147,11 @@ const AddForm = ({mutate, fetchUrl}) => { formik.touched.type_id && Boolean(formik.errors.type_id) } - onBlur={formik.handleBlur("type_id")} > {t("AddDialog.type_id")} diff --git a/src/components/dashboard/user-management/Form/DeleteForm.jsx b/src/components/dashboard/user-management/Form/DeleteForm.jsx index f336036..b653428 100644 --- a/src/components/dashboard/user-management/Form/DeleteForm.jsx +++ b/src/components/dashboard/user-management/Form/DeleteForm.jsx @@ -1,6 +1,15 @@ import {useTranslations} from "next-intl"; import {useState} from "react"; -import {Button, Dialog, DialogActions, DialogTitle, IconButton, Tooltip} from "@mui/material"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + IconButton, + Tooltip, + Typography +} from "@mui/material"; import DeleteIcon from '@mui/icons-material/Delete'; import {DELETE_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; @@ -12,7 +21,6 @@ const DeleteForm = ({rowId, fetchUrl, mutate}) => { const [isSubmitting, setIsSubmitting] = useState(false) const requestServer = useRequest({auth: true}) const {update_notification} = useNotification() - const handleSubmit = () => { setIsSubmitting(true) requestServer(`${DELETE_USER_MANAGEMENT}/${rowId}`, 'delete').then((response) => { @@ -39,6 +47,9 @@ const DeleteForm = ({rowId, fetchUrl, mutate}) => { {t("DeleteDialog.delete")} + + {t("DeleteDialog.typography")} + - - - - - ); + + { + if (event.target.value.length <= 10) return formik.handleChange(event) + }} + fullWidth + variant="outlined" + onBlur={formik.handleBlur("national_id")} + error={formik.touched.national_id && Boolean(formik.errors.national_id)} + helperText={formik.touched.national_id && formik.errors.national_id} + sx={{mt: 1}} + /> + + + + {t("UpdateDialog.type_id")} + + + {formik.touched.type_id && formik.errors.type_id} + + + + + + + + + + + + + + ); }; export default UpdateForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/TableRowActions.jsx b/src/components/dashboard/user-management/TableRowActions.jsx index c67acb3..5b0f031 100644 --- a/src/components/dashboard/user-management/TableRowActions.jsx +++ b/src/components/dashboard/user-management/TableRowActions.jsx @@ -7,7 +7,7 @@ const TableRowActions = ({row, mutate, fetchUrl}) => { return ( diff --git a/src/components/dashboard/user-management/index.jsx b/src/components/dashboard/user-management/index.jsx index 596c7e6..fc235e5 100644 --- a/src/components/dashboard/user-management/index.jsx +++ b/src/components/dashboard/user-management/index.jsx @@ -34,9 +34,9 @@ function DashboardUserManagementComponent() { ), }, { - accessorFn: (row) => row.name, - id: "name", - header: t("UserManagement.name"), + accessorFn: (row) => row.navgan_id, + id: "navgan_id", + header: t("UserManagement.navgan_id"), enableColumnFilter: true, datatype: "text", filterFn: "contains", @@ -114,9 +114,9 @@ function DashboardUserManagementComponent() { ), }, { - accessorFn: (row) => row.state_name, - id: "state_id", - header: t("UserManagement.state_name"), + accessorFn: (row) => row.type_name, + id: "type_name", + header: t("UserManagement.type_name"), enableColumnFilter: false, datatype: "numeric", Cell: ({renderedCellValue}) => ( From 6ab5a92b56760a721b40619926421e97e3622b1e Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 10 Sep 2023 15:59:52 +0330 Subject: [PATCH 06/25] TF-4 user management formData navgan id --- .../user-management/Form/AddForm.jsx | 285 +++++++++--------- .../user-management/Form/DeleteForm.jsx | 2 +- .../user-management/Form/UpdateForm.jsx | 12 +- 3 files changed, 148 insertions(+), 151 deletions(-) diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx index c0021e8..6014c8d 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -26,37 +26,34 @@ const AddForm = ({mutate, fetchUrl}) => { const requestServer = useRequest({auth: true}) const [openConfirmDialog, setOpenConfirmDialog] = useState(false); const validationSchema = Yup.object().shape({ - phone_number: Yup.mixed().test( - "is-number", - `${t("AddDialog.phone_number_number")}`, - (value) => !isNaN(value) - ).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) + phone_number: Yup.mixed().test("is-number", `${t("AddDialog.phone_number_number")}`, (value) => !isNaN(value)).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) .test("max", `${t("AddDialog.phone_number_max")}`, (value) => value.length <= 11) .required(t("AddDialog.phone_number_error")), - national_id: Yup.mixed().test( - "is-number", - `${t("AddDialog.national_id_number")}`, - (value) => !isNaN(value) - ).test("positive", `${t("AddDialog.national_id_positive")}`, (value) => value >= 0) + national_id: Yup.mixed().test("is-number", `${t("AddDialog.national_id_number")}`, (value) => !isNaN(value)).test("positive", `${t("AddDialog.national_id_positive")}`, (value) => value >= 0) .test("max", `${t("AddDialog.national_id_max")}`, (value) => value.length <= 10) .required(t("AddDialog.national_id_error")), type_id: Yup.number().required(t("AddDialog.type_id_error")), - navgan_id: Yup.number().required(t("AddDialog.navgan_id_error")), + navgan_id: Yup.number().when('type_id', { + is: 1, // Condition: Check if type_id is equal to 1 + then: (schema) => schema.required(t("AddDialog.navgan_id_error")), + otherwise: (schema) => schema, // No validation for navgan_id when type_id is not 1 + }) }); + // validationSchema.describe({value: {type_id: true}}); + const formik = useFormik({ initialValues: { phone_number: "", national_id: "", type_id: "", navgan_id: "", - }, validationSchema, - onSubmit: (values, {setSubmitting}) => { + }, validationSchema, onSubmit: (values, {setSubmitting}) => { const formData = new FormData(); formData.append("phone_number", values.phone_number); formData.append("national_id", values.national_id); formData.append("type_id", values.type_id); - formData.append("navgan_id", values.navgan_id); + if (formik.values.type_id === 1) formData.append("navgan_id", values.navgan_id); requestServer(ADD_USER_MANAGEMENT, 'post', { data: formData, @@ -70,142 +67,138 @@ const AddForm = ({mutate, fetchUrl}) => { }); }, }); - return ( - - - - - - {t("AddDialog.add")} - - - - { - if (event.target.value.length <= 11) return formik.handleChange(event) - }} - fullWidth - variant="outlined" - onBlur={formik.handleBlur("phone_number")} - error={ - formik.touched.phone_number && - Boolean(formik.errors.phone_number) - } - helperText={ - formik.touched.phone_number && formik.errors.phone_number - } - sx={{mt: 1}} - /> - - - { - if (event.target.value.length <= 10) return formik.handleChange(event) - }} - fullWidth - variant="outlined" - onBlur={formik.handleBlur("national_id")} - error={ - formik.touched.national_id && - Boolean(formik.errors.national_id) - } - helperText={ - formik.touched.national_id && formik.errors.national_id - } - sx={{mt: 1}} - /> - - - - {t("AddDialog.type_id")} - - - {formik.touched.type_id && formik.errors.type_id} - - - - - + + + + + {t("AddDialog.add")} + + + + { + if (event.target.value.length <= 11) return formik.handleChange(event) + }} + fullWidth + variant="outlined" + onBlur={formik.handleBlur("phone_number")} + error={formik.touched.phone_number && Boolean(formik.errors.phone_number)} + helperText={formik.touched.phone_number && formik.errors.phone_number} + sx={{mt: 1}} + /> + + + { + if (event.target.value.length <= 10) return formik.handleChange(event) + }} + fullWidth + variant="outlined" + onBlur={formik.handleBlur("national_id")} + error={formik.touched.national_id && Boolean(formik.errors.national_id)} + helperText={formik.touched.national_id && formik.errors.national_id} + sx={{mt: 1}} + /> + + + + {t("AddDialog.type_id")} + + + {formik.touched.type_id && formik.errors.type_id} + + - - - - - - - - ); + + {formik.values.type_id === 1 ? () : null} + {/**/} + + + + + + + + + ); }; export default AddForm; \ No newline at end of file diff --git a/src/components/dashboard/user-management/Form/DeleteForm.jsx b/src/components/dashboard/user-management/Form/DeleteForm.jsx index b653428..5cf2eb3 100644 --- a/src/components/dashboard/user-management/Form/DeleteForm.jsx +++ b/src/components/dashboard/user-management/Form/DeleteForm.jsx @@ -44,7 +44,7 @@ const DeleteForm = ({rowId, fetchUrl, mutate}) => { - {t("DeleteDialog.delete")} diff --git a/src/components/dashboard/user-management/Form/UpdateForm.jsx b/src/components/dashboard/user-management/Form/UpdateForm.jsx index eccbf36..44631c5 100644 --- a/src/components/dashboard/user-management/Form/UpdateForm.jsx +++ b/src/components/dashboard/user-management/Form/UpdateForm.jsx @@ -37,7 +37,11 @@ const UpdateForm = ({row, fetchUrl, mutate}) => { .test("max", `${t("AddDialog.national_id_max")}`, (value) => value.length <= 10) .required(t("AddDialog.national_id_error")), type_id: Yup.number().required(t("AddDialog.type_id_error")), - navgan_id: Yup.number().required(t("AddDialog.navgan_id_error")), + navgan_id: Yup.number().when('type_id', { + is: 1, // Condition: Check if type_id is equal to 1 + then: (schema) => schema.required(t("AddDialog.navgan_id_error")), + otherwise: (schema) => schema, // No validation for navgan_id when type_id is not 1 + }) }); const formik = useFormik({ @@ -51,7 +55,7 @@ const UpdateForm = ({row, fetchUrl, mutate}) => { formData.append("phone_number", values.phone_number); formData.append("national_id", values.national_id); formData.append("type_id", values.type_id); - formData.append("navgan_id", values.navgan_id); + if (formik.values.type_id === 1) formData.append("navgan_id", values.navgan_id); requestServer(`${UPDATE_USER_MANAGEMENT}/${row.getValue("id")}`, 'post', { data: formData, }).then((response) => { @@ -142,7 +146,7 @@ const UpdateForm = ({row, fetchUrl, mutate}) => { - { error={formik.touched.navgan_id && Boolean(formik.errors.navgan_id)} helperText={formik.touched.navgan_id && formik.errors.navgan_id} sx={{mt: 1}} - /> + />) : null} From 48cf959e0d5707e9bfed8115440e2759739b606d Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 10 Sep 2023 16:05:25 +0330 Subject: [PATCH 07/25] TF-4 user management permissions --- .../dashboard/user-management/Form/AddForm.jsx | 18 ------------------ src/core/data/sidebarMenu.jsx | 5 +++-- src/pages/dashboard/user-management/index.jsx | 2 +- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/AddForm.jsx index 6014c8d..97e6c3b 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/AddForm.jsx @@ -167,24 +167,6 @@ const AddForm = ({mutate, fetchUrl}) => { helperText={formik.touched.navgan_id && formik.errors.navgan_id} sx={{mt: 1}} />) : null} - {/**/} diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 29eab1d..4957bad 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -10,6 +10,7 @@ import GradingIcon from '@mui/icons-material/Grading'; import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle'; import Diversity3Icon from '@mui/icons-material/Diversity3'; import PaidIcon from '@mui/icons-material/Paid'; +import PersonIcon from '@mui/icons-material/Person'; const sidebarMenu = [ [ @@ -141,9 +142,9 @@ const sidebarMenu = [ name: "user_management", type: "page", route: "/dashboard/user-management", - icon: , + icon: , selected: false, - permission: "user_management", + permission: "manage_users", }, ], ]; diff --git a/src/pages/dashboard/user-management/index.jsx b/src/pages/dashboard/user-management/index.jsx index ce9cc1e..5a43454 100644 --- a/src/pages/dashboard/user-management/index.jsx +++ b/src/pages/dashboard/user-management/index.jsx @@ -3,7 +3,7 @@ import WithAuthMiddleware from "@/middlewares/WithAuth"; import {parse} from "next-useragent"; import DashboardUserManagementComponent from "@/components/dashboard/user-management"; -const requiredPermissions = ["manage_refahi_loan"]; +const requiredPermissions = ["manage_users"]; export default function UserManagement() { return ( From 044b98d06539e4fa8da4458c0d605e987d5b85aa Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 11 Sep 2023 11:18:35 +0330 Subject: [PATCH 08/25] TF-4 user management add filter on type id --- public/locales/fa/app.json | 5 + .../dashboard/user-management/index.jsx | 263 +++++++++--------- 2 files changed, 129 insertions(+), 139 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index e2e5105..ae67ef2 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -18,8 +18,13 @@ "open_profile": "پروفایل", "edit_profile": " پروفایل", "change_password": "تغییر رمز عبور", + "equals": "برابر", "logout": "خروج" }, + "Select": { + "helper_text": "حالت فیلتر: برابر", + "menu_item": "نوع کاربر را وارد کنید" + }, "Titles": { "title_login_page": "صفحه ورود", "title_login_expert_page": "ورود کارشناس", diff --git a/src/components/dashboard/user-management/index.jsx b/src/components/dashboard/user-management/index.jsx index fc235e5..341017f 100644 --- a/src/components/dashboard/user-management/index.jsx +++ b/src/components/dashboard/user-management/index.jsx @@ -1,5 +1,5 @@ import DashboardLayouts from "@/layouts/dashboardLayouts"; -import {Box, Typography} from "@mui/material"; +import {Box, FormControl, FormHelperText, IconButton, MenuItem, Select, Stack, Typography} from "@mui/material"; import {useMemo} from "react"; import {GET_USER_MANAGEMENT} from "@/core/data/apiRoutes"; import {useTranslations} from "next-intl"; @@ -8,148 +8,133 @@ import moment from "jalali-moment"; import MuiDatePicker from "@/core/components/MuiDatePicker"; import TableToolbar from "@/components/dashboard/user-management/TableToolbar"; import TableRowActions from "./TableRowActions" +import ClearIcon from "@mui/icons-material/Clear"; function DashboardUserManagementComponent() { const t = useTranslations(); - const columns = useMemo( - () => [ - { - accessorFn: (row) => row.id, - id: "id", - header: t("UserManagement.id"), - enableColumnFilter: true, - datatype: "numeric", - filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains", - "lessThan", - "greaterThan", - "between", - ], - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - { - accessorFn: (row) => row.navgan_id, - id: "navgan_id", - header: t("UserManagement.navgan_id"), - enableColumnFilter: true, - datatype: "text", - filterFn: "contains", - columnFilterModeOptions: ["contains", "equals", "notEquals"], - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - { - accessorFn: (row) => row.national_id, - id: "national_id", - header: t("UserManagement.national_id"), - enableColumnFilter: true, - datatype: "numeric", - filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains", - "lessThan", - "greaterThan", - "between", - ], - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - { - accessorFn: (row) => row.phone_number, - id: "phone_number", - header: t("UserManagement.phone_number"), - enableColumnFilter: true, - datatype: "numeric", - filterFn: "equals", - columnFilterModeOptions: [ - "equals", - "notEquals", - "contains", - "lessThan", - "greaterThan", - "between", - ], - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - { - accessorFn: (row) => - moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), - id: "created_at", - header: t("UserManagement.created_at"), - enableColumnFilter: true, - datatype: "date", - filterFn: "lessThan", - columnFilterModeOptions: ["lessThan", "greaterThan"], - Cell: ({renderedCellValue}) => { - return {renderedCellValue}; - }, - Header: ({column}) => <>{column.columnDef.header}, - Filter: ({column}) => { - return ( - - ); - }, - }, - { - accessorFn: (row) => - moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), - id: "updated_at", - header: t("UserManagement.updated_at"), - enableColumnFilter: false, - datatype: "numeric", - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - { - accessorFn: (row) => row.type_name, - id: "type_name", - header: t("UserManagement.type_name"), - enableColumnFilter: false, - datatype: "numeric", - Cell: ({renderedCellValue}) => ( - {renderedCellValue} - ), - }, - ], - [] - ); - return ( - - - - - - ); + const columns = useMemo(() => [{ + accessorFn: (row) => row.id, + id: "id", + header: t("UserManagement.id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between",], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, { + accessorFn: (row) => row.navgan_id, + id: "navgan_id", + header: t("UserManagement.navgan_id"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, { + accessorFn: (row) => row.national_id, + id: "national_id", + header: t("UserManagement.national_id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between",], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, { + accessorFn: (row) => row.phone_number, + id: "phone_number", + header: t("UserManagement.phone_number"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between",], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, { + accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "created_at", + header: t("UserManagement.created_at"), + enableColumnFilter: true, + datatype: "date", + filterFn: "lessThan", + columnFilterModeOptions: ["lessThan", "greaterThan"], + Cell: ({renderedCellValue}) => { + return {renderedCellValue}; + }, + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return (); + }, + }, { + accessorFn: (row) => moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "updated_at", + header: t("UserManagement.updated_at"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, { + accessorFn: (row) => row.type_name, + id: "type_id", + header: t("UserManagement.type_name"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["equals"], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return ( + + + {t("Select.helper_text")} + + { + column.setFilterValue(null); + }} + sx={{ + color: column.getFilterValue() ? "rgba(0, 0, 0, 0.54)" : "#bfbfbf", + height: 20 + }} + > + + + ) + } + },], []); + return ( + + + + ); } export default DashboardUserManagementComponent; From 1dd82eed5868ec97a48a932ca206612c839d632d Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 11 Sep 2023 12:58:31 +0330 Subject: [PATCH 09/25] TF-4 user management restyling --- src/components/dashboard/user-management/index.jsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/dashboard/user-management/index.jsx b/src/components/dashboard/user-management/index.jsx index 341017f..527fb23 100644 --- a/src/components/dashboard/user-management/index.jsx +++ b/src/components/dashboard/user-management/index.jsx @@ -82,13 +82,13 @@ function DashboardUserManagementComponent() { Cell: ({renderedCellValue}) => ({renderedCellValue}), Header: ({column}) => <>{column.columnDef.header}, Filter: ({column}) => { - return ( + return ( - {t("filter_mode")}: {t(column.columnDef._filterFn)} + {t("Select.menu_item")} {t("UpdateDialog.navgan")} {t("UpdateDialog.refahi")} - {t("Select.helper_text")} + {t("filter_mode")}: {t(column.columnDef._filterFn)} From 7c2d64a712209481928fce698ab30bacef8976c7 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 11 Sep 2023 16:45:04 +0330 Subject: [PATCH 14/25] TF-98 user management debug --- public/locales/fa/app.json | 2 +- .../CreateContent.jsx} | 49 +++++-------------- .../user-management/Form/CreateForm/index.jsx | 35 +++++++++++++ .../user-management/TableToolbar.jsx | 4 +- 4 files changed, 51 insertions(+), 39 deletions(-) rename src/components/dashboard/user-management/Form/{AddForm.jsx => CreateForm/CreateContent.jsx} (86%) create mode 100644 src/components/dashboard/user-management/Form/CreateForm/index.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index baecc48..bd591f2 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -354,7 +354,7 @@ "button-delete": "حذف کردن" }, "AddDialog": { - "add": "کاربر جدید", + "add": "افزودن کاربر جدید", "phone_number": "شماره تلفن", "phone_number_positive": "شماره تلفن باید مثبت باشد", "phone_number_error": "وارد کردن شماره تلفن الزامیست", diff --git a/src/components/dashboard/user-management/Form/AddForm.jsx b/src/components/dashboard/user-management/Form/CreateForm/CreateContent.jsx similarity index 86% rename from src/components/dashboard/user-management/Form/AddForm.jsx rename to src/components/dashboard/user-management/Form/CreateForm/CreateContent.jsx index 97e6c3b..1ab35f9 100644 --- a/src/components/dashboard/user-management/Form/AddForm.jsx +++ b/src/components/dashboard/user-management/Form/CreateForm/CreateContent.jsx @@ -1,30 +1,24 @@ -import {useTranslations} from "next-intl"; -import * as Yup from "yup"; -import {ADD_USER_MANAGEMENT} from "@/core/data/apiRoutes"; -import {useFormik} from "formik"; import { Button, - Dialog, DialogActions, DialogContent, - DialogTitle, FormControl, FormHelperText, InputLabel, MenuItem, Select, Stack, - TextField, - Tooltip + TextField } from "@mui/material"; +import {useTranslations} from "next-intl"; import useRequest from "@/lib/app/hooks/useRequest"; -import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; -import {useState} from "react"; +import * as Yup from "yup"; +import {useFormik} from "formik"; +import {ADD_USER_MANAGEMENT} from "@/core/data/apiRoutes"; -const AddForm = ({mutate, fetchUrl}) => { +const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => { const t = useTranslations(); const requestServer = useRequest({auth: true}) - const [openConfirmDialog, setOpenConfirmDialog] = useState(false); const validationSchema = Yup.object().shape({ phone_number: Yup.mixed().test("is-number", `${t("AddDialog.phone_number_number")}`, (value) => !isNaN(value)).test("positive", `${t("AddDialog.phone_number_positive")}`, (value) => value >= 0) .test("max", `${t("AddDialog.phone_number_max")}`, (value) => value.length <= 11) @@ -40,8 +34,6 @@ const AddForm = ({mutate, fetchUrl}) => { }) }); - // validationSchema.describe({value: {type_id: true}}); - const formik = useFormik({ initialValues: { phone_number: "", @@ -67,24 +59,9 @@ const AddForm = ({mutate, fetchUrl}) => { }); }, }); - return ( - - - - - {t("AddDialog.add")} + + return ( + <> @@ -180,7 +157,7 @@ const AddForm = ({mutate, fetchUrl}) => { {t("AddDialog.button-add")} - - ); -}; -export default AddForm; \ No newline at end of file + + ) +} +export default CreateContent \ No newline at end of file diff --git a/src/components/dashboard/user-management/Form/CreateForm/index.jsx b/src/components/dashboard/user-management/Form/CreateForm/index.jsx new file mode 100644 index 0000000..58e5224 --- /dev/null +++ b/src/components/dashboard/user-management/Form/CreateForm/index.jsx @@ -0,0 +1,35 @@ +import {Button, Dialog, DialogTitle, Stack, Tooltip} from "@mui/material"; +import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import CreateContent from "@/components/dashboard/user-management/Form/CreateForm/CreateContent"; + +const CreateForm = ({mutate, fetchUrl}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + + return ( + + + + + + {t("AddDialog.add")} + + + + ) +} +export default CreateForm \ No newline at end of file diff --git a/src/components/dashboard/user-management/TableToolbar.jsx b/src/components/dashboard/user-management/TableToolbar.jsx index 558cdc5..9ea36f5 100644 --- a/src/components/dashboard/user-management/TableToolbar.jsx +++ b/src/components/dashboard/user-management/TableToolbar.jsx @@ -1,10 +1,10 @@ import {useTranslations} from "next-intl"; -import AddForm from "./Form/AddForm"; +import CreateForm from "@/components/dashboard/user-management/Form/CreateForm"; function TableToolbar({mutate, fetchUrl}) { const t = useTranslations(); - return + return } From 45b919f0fc80a72ae9c35140604b496d5c7d3720 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Mon, 11 Sep 2023 16:52:24 +0330 Subject: [PATCH 15/25] complete create and delete part and some update form design and structure --- public/locales/fa/app.json | 54 ++- .../Form/CreateForm/CreateContent.jsx | 367 ++++++++++++++++++ .../Form/CreateForm/index.jsx | 39 ++ .../expert-management/Form/DeleteForm.jsx | 96 ++--- .../expert-management/Form/UpdateForm.jsx | 24 -- .../Form/UpdateForm/UpdateContent.jsx | 348 +++++++++++++++++ .../Form/UpdateForm/index.jsx | 55 +++ .../expert-management/TableRowActions.jsx | 7 +- .../expert-management/TableToolbar.jsx | 13 + .../dashboard/expert-management/index.jsx | 131 +++++++ .../dashboard/passenger-boss/index.jsx | 1 + src/core/components/DataTable.jsx | 2 +- src/core/data/apiRoutes.js | 9 + .../dashboard/expert-management/index.jsx | 2 +- 14 files changed, 1065 insertions(+), 83 deletions(-) create mode 100644 src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx create mode 100644 src/components/dashboard/expert-management/Form/CreateForm/index.jsx delete mode 100644 src/components/dashboard/expert-management/Form/UpdateForm.jsx create mode 100644 src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx create mode 100644 src/components/dashboard/expert-management/Form/UpdateForm/index.jsx create mode 100644 src/components/dashboard/expert-management/TableToolbar.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index bf4d7d2..fde5626 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -96,7 +96,8 @@ "development_assistant_page": "معاون توسعه", "inspector_expert_page": "بازدید کارشناس", "commercial_chief_page": "رئیس اداره بازرگانی", - "edit_profile": "ویرایش پروفایل" + "edit_profile": "ویرایش پروفایل", + "expert_management": "مدیریت کارشناسان" }, "MuiDatePicker": { "date_picker_birthday": "تاریخ" @@ -324,6 +325,55 @@ "uploadfile_error": "حجم فایل بیشتر از 2 مگابایت می باشد" }, "ExpertMangement": { - "id": "کد یکتا" + "id": "کد یکتا", + "name": "نام", + "username": "نام کاربری", + "email": "پست الکترونیک", + "phone_number": "شماره همراه", + "national_id": "کد ملی", + "position": "سمت", + "province_name": "استان", + "city_name": "شهر", + "role_name": "نقش", + "updated_at": "آخرین بروزرسانی", + "button_while_submiting": "درحال افزودن کارشناس", + "button_submit": "افزودن کارشناس", + "button_close": "بستن", + "button_delete": "حذف", + "add": "افزودن کارشناس", + "button-cancel": "بستن", + "button-confirm": "ثبت", + "create": "افزودن کارشناس", + "update": "ویرایش کارشناس", + "text_field_name": "نام", + "text_field_username": "نام کاربری", + "text_field_email": "پست الکترونیک", + "text_field_phone_number": "شماره همراه", + "text_field_national_id": "کد ملی", + "text_field_password": "رمز عبور", + "text_field_position": "سمت", + "text_field_province_id": "استان", + "text_field_city_id": "شهر", + "text_field_role_id": "نقش", + "text_field_please_select_province": "ابتدا استان خود را انتخاب کنید", + "text_field_loading_cities_list": "درحال دریافت شهر ها", + "text_field_error_fetching_cities": "خطا در دریافت شهر ها", + "error_message_name": "نام خود را وارد کنید", + "error_message_username": "نام کاربری خود را وارد کنید", + "error_message_email": "پست الکترونیک خود را وارد کنید", + "error_message_phone_number": "شماره همراه خود را وارد کنید", + "error_message_national_id": "کد ملی خود را وارد کنید", + "error_message_password": "رمز عبور خود را وارد کنید", + "error_message_position": "سمت خود را وارد کنید", + "error_message_province_id": "استان خود را وارد کنید", + "error_message_city_id": "شهر خود را وارد کنید", + "error_message_role_id": "نقش خود را وارد کنید", + "personal_info": "مشخصات کارشناس", + "user_info": "اطلاعات کاربری", + "rest_info": "اطلاعات تکمیلی", + "delete_tooltip": "حذف", + "update_tooltip": "ویرایش کارشناس", + "delete_expert": "حذف کارشناس", + "are_you_sure_text": "آیا از انجام این عملیات اطمینان دارید؟" } } diff --git a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx new file mode 100644 index 0000000..82d8a58 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx @@ -0,0 +1,367 @@ +import { + Box, + Button, + Chip, + DialogActions, + DialogContent, + Divider, + FormControl, + FormHelperText, + Grid, + InputLabel, + MenuItem, + Select, + TextField, +} from "@mui/material"; +import {useFormik} from "formik"; +import {useTranslations} from "next-intl"; +import * as Yup from "yup"; +import {useEffect, useState} from "react"; +import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST, GET_PROVINCE_LIST, GET_ROLE_LIST} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; + +const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { + const t = useTranslations(); + const requestServer = useRequest() + const [provinceList, setProvinceList] = useState([]); + const [cityList, setCityList] = useState([]); + const [roleList, setRoleList] = useState([]); + const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); + + useEffect(() => { + requestServer(GET_PROVINCE_LIST, "get", {auth: true, notification: false}) + .then(({data}) => { + const formattedData = data.map((province, index) => ({ + id: index, + name: province.name, + value: province.id, + })); + setProvinceList(formattedData); + }).catch(() => { + }); + }, []); + + useEffect(() => { + requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) + .then(({data}) => { + const result = data.data; + const formattedData = result.map((role, index) => ({ + id: index, + name: role.name, + name_fa: role.name_fa, + value: role.id, + })); + setRoleList(formattedData); + }).catch(() => { + }); + }, []); + + function getCities(province_id) { + formik.setFieldTouched("city_id", false, false); + formik.setFieldValue("city_id", "") + setCityTextField(t("ExpertMangement.text_field_loading_cities_list")) + requestServer(`${GET_CITY_LIST}?province_id=${province_id}`, "get", {auth: true, notification: false}) + .then(({data}) => { + const result = data.data; + const formattedData = result.map((city, index) => ({ + id: index, + name: city.name, + value: city.id, + })); + setCityList(formattedData); + setCityTextField(t("ExpertMangement.text_field_city_id")) + }).catch(() => { + setCityTextField(t("ExpertMangement.text_field_error_fetching_cities")) + }); + } + + + const validationSchema = Yup.object().shape({ + name: Yup.string().required(t("ExpertMangement.error_message_name")), + username: Yup.string().required(t("ExpertMangement.error_message_username")), + email: Yup.string().required(t("ExpertMangement.error_message_email")), + phone_number: Yup.string().required(t("ExpertMangement.error_message_phone_number")), + national_id: Yup.string().required(t("ExpertMangement.error_message_national_id")), + password: Yup.string().required(t("ExpertMangement.error_message_password")), + position: Yup.string().required(t("ExpertMangement.error_message_position")), + province_id: Yup.string().required(t("ExpertMangement.error_message_province_id")), + city_id: Yup.string().required(t("ExpertMangement.error_message_city_id")), + role_id: Yup.string().required(t("ExpertMangement.error_message_role_id")) + }); + + const formik = useFormik({ + initialValues: { + name: "", + username: "", + email: "", + phone_number: "", + national_id: "", + password: "", + position: "", + province_id: "", + city_id: "", + role_id: "" + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("name", values.name); + formData.append("national_id", values.national_id); + formData.append("phone_number", values.phone_number); + formData.append("email", values.email); + formData.append("username", values.username); + formData.append("password", values.password); + formData.append("province_id", values.province_id); + formData.append("city_id", values.city_id); + formData.append("position", values.position); + formData.append("role_id", values.role_id); + + requestServer(`${CREATE_EXPERT_MANAGEMENT}`, 'post', {auth: true, data: formData}) + .then((response) => { + mutate(fetchUrl) + setOpenCreateDialog(false) + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {t("ExpertMangement.text_field_province_id")} + + + {formik.touched.province_id && formik.errors.province_id ? formik.errors.province_id : ""} + + + + + + {cityTextField} + + + {formik.touched.city_id && formik.errors.city_id ? formik.errors.city_id : ""} + + + + + + + + + + + {t("ExpertMangement.text_field_role_id")} + + + {formik.touched.role_id && formik.errors.role_id ? formik.errors.role_id : ""} + + + + + + + + + + + ); +}; + +export default CreateContent; diff --git a/src/components/dashboard/expert-management/Form/CreateForm/index.jsx b/src/components/dashboard/expert-management/Form/CreateForm/index.jsx new file mode 100644 index 0000000..8556b11 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/CreateForm/index.jsx @@ -0,0 +1,39 @@ +import {Button, Dialog, DialogTitle, Stack, Tooltip,} from "@mui/material"; +import {useTranslations} from "next-intl"; +import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; +import {useState} from "react"; +import CreateContent from "./CreateContent"; + +const Create = ({mutate, fetchUrl}) => { + const t = useTranslations(); + const [openCreateDialog, setOpenCreateDialog] = useState(false); + + return ( + <> + + + + + + + {t("ExpertMangement.create")} + + + + ); +}; + +export default Create; diff --git a/src/components/dashboard/expert-management/Form/DeleteForm.jsx b/src/components/dashboard/expert-management/Form/DeleteForm.jsx index eb5b4c0..87a097c 100644 --- a/src/components/dashboard/expert-management/Form/DeleteForm.jsx +++ b/src/components/dashboard/expert-management/Form/DeleteForm.jsx @@ -1,84 +1,72 @@ -import {useTranslations} from "next-intl"; -import {useState} from "react"; import { Button, Dialog, DialogActions, DialogContent, + DialogContentText, DialogTitle, - FormControl, - FormHelperText, IconButton, - InputLabel, - MenuItem, - Select, - Stack, - TextField, Tooltip } from "@mui/material"; -import {useFormik} from "formik"; -import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; -import {UPDATE_LOAN_MANAGEMENT_REFAHI} from "@/core/data/apiRoutes"; +import DeleteIcon from '@mui/icons-material/Delete'; +import {useState} from "react"; +import {DELETE_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; -import useNotification from "@/lib/app/hooks/useNotification"; -import * as Yup from "yup"; -import useLoanStateRefahi from "@/lib/prefetchDataTable/hooks/useLoanStateRefahi"; - +import {useTranslations} from "next-intl"; const Delete = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); - const {loan_state_refahi} = useLoanStateRefahi() - const [openConfirmDialog, setOpenConfirmDialog] = useState(false); - const requestServer = useRequest({auth: true}) - const {update_notification} = useNotification() + const requestServer = useRequest({auth: true}); + const [openDeleteDialog, setOpenDeleteDialog] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false); - const validationSchema = Yup.object().shape({ - description: Yup.string().required(t("UpdateDialog.description_error")), - next_state_id: Yup.number().required(t("UpdateDialog.next-state-id-error")) - }); - - const formik = useFormik({ - initialValues: { - description: "", - next_state_id: "" - }, - validationSchema, - onSubmit: (values, {setSubmitting}) => { - const formData = new FormData(); - formData.append("description", values.description); - formData.append("next_state_id", values.next_state_id); - - requestServer(`${UPDATE_LOAN_MANAGEMENT_REFAHI}/${rowId}`, 'post', { - data: formData, - }).then((response) => { + const handleDelete = () => { + setIsSubmitting(true) + requestServer(`${DELETE_EXPERT_MANAGEMENT}/${rowId}`, 'post') + .then((response) => { mutate(fetchUrl) - update_notification() - }).catch(() => { - }).finally(() => { - setSubmitting(false); + }) + .catch(() => { + }) + .finally(() => { + setIsSubmitting(false) + setOpenDeleteDialog(false); }); - }, - }); - - const handleDescriptionChange = (event) => { - formik.setFieldValue("description", event.target.value) - }; - const handleNextStateIDChange = (event) => { - formik.setFieldValue("next_state_id", event.target.value) }; return ( <> - + { - setOpenConfirmDialog(true) + setOpenDeleteDialog(true); }} > - + + + {t("ExpertMangement.delete_expert")} + + {t("ExpertMangement.are_you_sure_text")} + + + + + + ); }; diff --git a/src/components/dashboard/expert-management/Form/UpdateForm.jsx b/src/components/dashboard/expert-management/Form/UpdateForm.jsx deleted file mode 100644 index a456677..0000000 --- a/src/components/dashboard/expert-management/Form/UpdateForm.jsx +++ /dev/null @@ -1,24 +0,0 @@ -import {useTranslations} from "next-intl"; -import {IconButton, Tooltip} from "@mui/material"; -import ChangeCircleIcon from '@mui/icons-material/ChangeCircle'; - - -const Update = ({rowId, fetchUrl, mutate}) => { - const t = useTranslations(); - - return ( - <> - - { - setOpenConfirmDialog(true) - }} - > - - - - - ); -}; -export default Update; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx new file mode 100644 index 0000000..39a8a6b --- /dev/null +++ b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx @@ -0,0 +1,348 @@ +import {useTranslations} from "next-intl"; +import { + Box, + Button, + Chip, + DialogActions, + DialogContent, + Divider, + FormControl, + FormHelperText, + Grid, + InputLabel, + MenuItem, + Select, + TextField +} from "@mui/material"; +import {useEffect, useState} from "react"; +import {useFormik} from "formik"; +import {GET_CITY_LIST, GET_PROVINCE_LIST, GET_ROLE_LIST, UPDATE_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; +import * as Yup from "yup"; +import useRequest from "@/lib/app/hooks/useRequest"; + + +const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { + const t = useTranslations(); + const requestServer = useRequest(); + const [provinceList, setProvinceList] = useState([]); + const [cityList, setCityList] = useState([]); + const [roleList, setRoleList] = useState([]); + const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); + + useEffect(() => { + requestServer(GET_PROVINCE_LIST, "get", {auth: true, notification: false}) + .then(({data}) => { + const formattedData = data.map((province, index) => ({ + id: index, + name: province.name, + value: province.id, + })); + setProvinceList(formattedData); + }).catch(() => { + }); + }, []); + + useEffect(() => { + requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) + .then(({data}) => { + const result = data.data; + const formattedData = result.map((role, index) => ({ + id: index, + name: role.name, + name_fa: role.name_fa, + value: role.id, + })); + setRoleList(formattedData); + }).catch(() => { + }); + }, []); + + function getCities(province_id) { + formik.setFieldTouched("city_id", false, false); + // formik.setFieldValue("city_id", "") + setCityTextField(t("ExpertMangement.text_field_loading_cities_list")) + requestServer(`${GET_CITY_LIST}?province_id=${province_id}`, "get", {auth: true, notification: false}) + .then(({data}) => { + const result = data.data; + const formattedData = result.map((city, index) => ({ + id: index, + name: city.name, + value: city.id, + })); + setCityList(formattedData); + setCityTextField(t("ExpertMangement.text_field_city_id")) + }).catch(() => { + setCityTextField(t("ExpertMangement.text_field_error_fetching_cities")) + }); + } + + + const validationSchema = Yup.object().shape({ + name: Yup.string().required(t("ExpertMangement.error_message_name")), + username: Yup.string().required(t("ExpertMangement.error_message_username")), + email: Yup.string().required(t("ExpertMangement.error_message_email")), + phone_number: Yup.string().required(t("ExpertMangement.error_message_phone_number")), + national_id: Yup.string().required(t("ExpertMangement.error_message_national_id")), + password: Yup.string().required(t("ExpertMangement.error_message_password")), + position: Yup.string().required(t("ExpertMangement.error_message_position")), + province_id: Yup.string().required(t("ExpertMangement.error_message_province_id")), + city_id: Yup.string().required(t("ExpertMangement.error_message_city_id")), + role_id: Yup.string().required(t("ExpertMangement.error_message_role_id")) + }); + const formik = useFormik({ + initialValues: { + name: row.original.name, + username: row.original.username, + email: row.original.email, + phone_number: row.original.phone_number, + national_id: row.original.national_id, + position: row.original.position, + province_id: row.original.province_id, + city_id: row.original.city_id, + role_id: row.original.role_id + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("name", values.name); + formData.append("national_id", values.national_id); + formData.append("phone_number", values.phone_number); + formData.append("email", values.email); + formData.append("username", values.username); + formData.append("province_id", values.province_id); + formData.append("city_id", values.city_id); + formData.append("position", values.position); + formData.append("role_id", values.role_id); + + requestServer(`${UPDATE_EXPERT_MANAGEMENT}/${row.original.id}`, 'post', {auth: true, data: formData}) + .then((response) => { + mutate(fetchUrl) + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {t("ExpertMangement.text_field_province_id")} + + + {formik.touched.province_id && formik.errors.province_id ? formik.errors.province_id : ""} + + + + + + {cityTextField} + + + {formik.touched.city_id && formik.errors.city_id ? formik.errors.city_id : ""} + + + + + + + + + + + {t("ExpertMangement.text_field_role_id")} + + + {formik.touched.role_id && formik.errors.role_id ? formik.errors.role_id : ""} + + + + + + + + + + + ); +}; +export default UpdateContent; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/Form/UpdateForm/index.jsx b/src/components/dashboard/expert-management/Form/UpdateForm/index.jsx new file mode 100644 index 0000000..56760f1 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/UpdateForm/index.jsx @@ -0,0 +1,55 @@ +import {useTranslations} from "next-intl"; +import {Dialog, DialogTitle, IconButton, Tooltip} from "@mui/material"; +import EditIcon from '@mui/icons-material/Edit'; +import {useState} from "react"; +import useRequest from "@/lib/app/hooks/useRequest"; +import UpdateContent from "./UpdateContent"; +import {GET_CITY_LIST} from "@/core/data/apiRoutes"; + + +const Update = ({row, fetchUrl, mutate}) => { + const t = useTranslations(); + const requestServer = useRequest(); + const [openUpdateDialog, setOpenUpdateDialog] = useState(false); + + // function getCities(province_id) { + // formik.setFieldTouched("city_id", false, false); + // // formik.setFieldValue("city_id", "") + // setCityTextField(t("ExpertMangement.text_field_loading_cities_list")) + // requestServer(`${GET_CITY_LIST}?province_id=${province_id}`, "get", {auth: true, notification: false}) + // .then(({data}) => { + // const result = data.data; + // const formattedData = result.map((city, index) => ({ + // id: index, + // name: city.name, + // value: city.id, + // })); + // setCityList(formattedData); + // setCityTextField(t("ExpertMangement.text_field_city_id")) + // }).catch(() => { + // setCityTextField(t("ExpertMangement.text_field_error_fetching_cities")) + // }); + // } + + return ( + <> + + { + setOpenUpdateDialog(true) + // getCities(row.original.province_id) + }} + > + + + + + {t("ExpertMangement.update")} + + + + ); +}; +export default Update; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/TableRowActions.jsx b/src/components/dashboard/expert-management/TableRowActions.jsx index fd599f9..4458fad 100644 --- a/src/components/dashboard/expert-management/TableRowActions.jsx +++ b/src/components/dashboard/expert-management/TableRowActions.jsx @@ -1,11 +1,16 @@ import {Box} from "@mui/material"; import Update from "./Form/UpdateForm" +import Delete from "./Form/DeleteForm"; const TableRowActions = ({row, mutate, fetchUrl}) => { - return ( + + + + ); +} + +export default TableToolbar; diff --git a/src/components/dashboard/expert-management/index.jsx b/src/components/dashboard/expert-management/index.jsx index a792cb6..3497091 100644 --- a/src/components/dashboard/expert-management/index.jsx +++ b/src/components/dashboard/expert-management/index.jsx @@ -5,6 +5,9 @@ import {GET_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; import {useTranslations} from "next-intl"; import TableRowActions from "./TableRowActions"; import DataTable from "@/core/components/DataTable"; +import TableToolbar from "@/components/dashboard/expert-management/TableToolbar"; +import moment from "jalali-moment"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; function DashboardExpertManagementComponent() { const t = useTranslations(); @@ -29,6 +32,133 @@ function DashboardExpertManagementComponent() { {renderedCellValue} ), }, + { + accessorFn: (row) => row.name, + id: "name", + header: t("ExpertMangement.name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.username, + id: "username", + header: t("ExpertMangement.username"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.email, + id: "email", + header: t("ExpertMangement.email"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.phone_number, + id: "phone_number", + header: t("ExpertMangement.phone_number"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.national_id, + id: "national_id", + header: t("ExpertMangement.national_id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.position, + id: "position", + header: t("ExpertMangement.position"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.province_name, + id: "province_id", + header: t("ExpertMangement.province_name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.city_name, + id: "city_id", + header: t("ExpertMangement.city_name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => row.role_name, + id: "role_id", + header: t("ExpertMangement.role_name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ( + {renderedCellValue} + ), + }, + { + accessorFn: (row) => + moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "updated_at", + header: t("ExpertMangement.updated_at"), + enableColumnFilter: true, + datatype: "date", + filterFn: "lessThan", + columnFilterModeOptions: ["lessThan", "greaterThan"], + Cell: ({renderedCellValue}) => { + return {renderedCellValue}; + }, + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return ( + + ); + }, + }, ], [] ); @@ -39,6 +169,7 @@ function DashboardExpertManagementComponent() { tableUrl={GET_EXPERT_MANAGEMENT} columns={columns} selectableRow={false} + CustomToolbar={TableToolbar} enableCustomToolbar={true} enableLastUpdate={true} enablePinning={true} diff --git a/src/components/dashboard/passenger-boss/index.jsx b/src/components/dashboard/passenger-boss/index.jsx index ad6848f..c90b28a 100644 --- a/src/components/dashboard/passenger-boss/index.jsx +++ b/src/components/dashboard/passenger-boss/index.jsx @@ -175,6 +175,7 @@ function DashboardPassengerOfficeComponent() { enableGlobalFilter={false} enableColumnResizing={false} // if you want true this you shold change renderRowActions props ** see https://www.material-react-table.com/docs/guides/row-actions enableRowActions={true} + renderMainAction={TableToolbar} TableRowAction={TableRowActions} /> diff --git a/src/core/components/DataTable.jsx b/src/core/components/DataTable.jsx index b3b0f26..8d06a02 100644 --- a/src/core/components/DataTable.jsx +++ b/src/core/components/DataTable.jsx @@ -134,7 +134,7 @@ function DataTable(props) { renderTopToolbarCustomActions={({table}) => ( <> {props.enableCustomToolbar /* send condition */ - ? props.CustomToolbar /* send component */ + ? /* send component */ : ""} )} diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index d7d728a..0cdaaff 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -163,3 +163,12 @@ export const DELETE_EXPERT_MANAGEMENT = export const CHANGE_PASSWORD_EXPERT_MANAGEMENT = BASE_URL + "/dashboard/experts/change_password" //expert management + +// province/city list +export const GET_PROVINCE_LIST = BASE_URL + "/api/provinces"; +export const GET_CITY_LIST = BASE_URL + "/api/cities"; +// province/city list + +// role list +export const GET_ROLE_LIST = BASE_URL + "/dashboard/roles/list"; +// role list diff --git a/src/pages/dashboard/expert-management/index.jsx b/src/pages/dashboard/expert-management/index.jsx index 84518f7..ce91ee6 100644 --- a/src/pages/dashboard/expert-management/index.jsx +++ b/src/pages/dashboard/expert-management/index.jsx @@ -4,7 +4,7 @@ import {parse} from "next-useragent"; import DashboardExpertManagementComponent from "@/components/dashboard/expert-management"; const requiredPermissions = ["manage_transportation_navgan"]; -export default function ExpertMangement() { +export default function ExpertManagement() { return ( From 2b5a440ef66e27732054db93cad82a58eedd9069 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Tue, 12 Sep 2023 17:10:27 +0330 Subject: [PATCH 16/25] make a hook for getting provinces --- public/locales/fa/app.json | 2 + .../Form/CreateForm/CreateContent.jsx | 37 +++++++++---------- .../Form/UpdateForm/UpdateContent.jsx | 35 +++++++++--------- src/lib/app/hooks/useProvince.jsx | 29 +++++++++++++++ 4 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 src/lib/app/hooks/useProvince.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index fde5626..ec9cd67 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -355,6 +355,8 @@ "text_field_province_id": "استان", "text_field_city_id": "شهر", "text_field_role_id": "نقش", + "text_field_loading_provinces_list": "درحال دریافت شهر ها", + "text_field_error_fetching_provinces": "خطا در دریافت شهر ها", "text_field_please_select_province": "ابتدا استان خود را انتخاب کنید", "text_field_loading_cities_list": "درحال دریافت شهر ها", "text_field_error_fetching_cities": "خطا در دریافت شهر ها", diff --git a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx index 82d8a58..80795ae 100644 --- a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx +++ b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx @@ -17,29 +17,17 @@ import {useFormik} from "formik"; import {useTranslations} from "next-intl"; import * as Yup from "yup"; import {useEffect, useState} from "react"; -import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST, GET_PROVINCE_LIST, GET_ROLE_LIST} from "@/core/data/apiRoutes"; +import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST, GET_ROLE_LIST} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; +import useProvince from "@/lib/app/hooks/useProvince"; const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { const t = useTranslations(); const requestServer = useRequest() - const [provinceList, setProvinceList] = useState([]); const [cityList, setCityList] = useState([]); const [roleList, setRoleList] = useState([]); const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); - - useEffect(() => { - requestServer(GET_PROVINCE_LIST, "get", {auth: true, notification: false}) - .then(({data}) => { - const formattedData = data.map((province, index) => ({ - id: index, - name: province.name, - value: province.id, - })); - setProvinceList(formattedData); - }).catch(() => { - }); - }, []); + const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince(); useEffect(() => { requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) @@ -255,6 +243,7 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { {t("ExpertMangement.text_field_province_id")} {formik.touched.province_id && formik.errors.province_id ? formik.errors.province_id : ""} diff --git a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx index 39a8a6b..3fa43a9 100644 --- a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx +++ b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx @@ -19,28 +19,17 @@ import {useFormik} from "formik"; import {GET_CITY_LIST, GET_PROVINCE_LIST, GET_ROLE_LIST, UPDATE_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; import * as Yup from "yup"; import useRequest from "@/lib/app/hooks/useRequest"; +import useProvince from "@/lib/app/hooks/useProvince"; const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { const t = useTranslations(); const requestServer = useRequest(); - const [provinceList, setProvinceList] = useState([]); + // const [provinceList, setProvinceList] = useState([]); const [cityList, setCityList] = useState([]); const [roleList, setRoleList] = useState([]); const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); - - useEffect(() => { - requestServer(GET_PROVINCE_LIST, "get", {auth: true, notification: false}) - .then(({data}) => { - const formattedData = data.map((province, index) => ({ - id: index, - name: province.name, - value: province.id, - })); - setProvinceList(formattedData); - }).catch(() => { - }); - }, []); + const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince(); useEffect(() => { requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) @@ -247,11 +236,21 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { fullWidth variant="outlined" > - {provinceList.map((item) => ( - - {item.name} + {isLoadingProvinceList ? ( + + {t("ExpertMangement.text_field_loading_provinces_list")} - ))} + ) : errorProvinceList ? ( + + {t("ExpertMangement.text_field_error_fetching_provinces")} + + ) : ( + provinceList.map((item) => ( + + {item.name} + + )) + )} {formik.touched.province_id && formik.errors.province_id ? formik.errors.province_id : ""} diff --git a/src/lib/app/hooks/useProvince.jsx b/src/lib/app/hooks/useProvince.jsx new file mode 100644 index 0000000..d0fbda0 --- /dev/null +++ b/src/lib/app/hooks/useProvince.jsx @@ -0,0 +1,29 @@ +import {GET_PROVINCE_LIST} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useSWR from "swr"; + +const useProvince = () => { + const requestServer = useRequest({auth: true, notification: false}) + + //swr config + const fetcher = (...args) => { + return requestServer(args, 'get').then(({data}) => { + return data; + }).catch(() => { + }) + }; + + const {data, isLoading} = useSWR(GET_PROVINCE_LIST, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }); + + return { + provinceList: data, + isLoadingProvinceList: isLoading, + errorProvinceList: !data + } +}; + +export default useProvince; \ No newline at end of file From 123eb18a81ff54fbfdf5b27f0f56e8a3ad9caa49 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Wed, 13 Sep 2023 15:48:11 +0330 Subject: [PATCH 17/25] debug getting cities make a role hook and debug getting data from row in update --- public/locales/fa/app.json | 2 + .../Form/CreateForm/CreateContent.jsx | 36 ++++++------ .../Form/UpdateForm/UpdateContent.jsx | 56 +++++++++---------- src/lib/app/hooks/useRole.jsx | 29 ++++++++++ 4 files changed, 74 insertions(+), 49 deletions(-) create mode 100644 src/lib/app/hooks/useRole.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index ec9cd67..60482e2 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -357,6 +357,8 @@ "text_field_role_id": "نقش", "text_field_loading_provinces_list": "درحال دریافت شهر ها", "text_field_error_fetching_provinces": "خطا در دریافت شهر ها", + "text_field_loading_roles_list": "درحال دریافت نقش ها", + "text_field_error_fetching_roles": "خطا در دریافت نقش ها", "text_field_please_select_province": "ابتدا استان خود را انتخاب کنید", "text_field_loading_cities_list": "درحال دریافت شهر ها", "text_field_error_fetching_cities": "خطا در دریافت شهر ها", diff --git a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx index 80795ae..f2e43cb 100644 --- a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx +++ b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx @@ -20,29 +20,15 @@ import {useEffect, useState} from "react"; import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST, GET_ROLE_LIST} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useProvince from "@/lib/app/hooks/useProvince"; +import useRole from "@/lib/app/hooks/useRole"; const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { const t = useTranslations(); const requestServer = useRequest() const [cityList, setCityList] = useState([]); - const [roleList, setRoleList] = useState([]); const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince(); - - useEffect(() => { - requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) - .then(({data}) => { - const result = data.data; - const formattedData = result.map((role, index) => ({ - id: index, - name: role.name, - name_fa: role.name_fa, - value: role.id, - })); - setRoleList(formattedData); - }).catch(() => { - }); - }, []); + const {roleList, isLoadingRoleList, errorRoleList} = useRole(); function getCities(province_id) { formik.setFieldTouched("city_id", false, false); @@ -336,11 +322,21 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { fullWidth variant="outlined" > - {roleList.map((item) => ( - - {item.name_fa} + {isLoadingRoleList ? ( + + {t("ExpertMangement.text_field_loading_roles_list")} - ))} + ) : errorRoleList ? ( + + {t("ExpertMangement.text_field_error_fetching_roles")} + + ) : ( + roleList.map((item) => ( + + {item.name_fa} + + )) + )} {formik.touched.role_id && formik.errors.role_id ? formik.errors.role_id : ""} diff --git a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx index 3fa43a9..45edcde 100644 --- a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx +++ b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx @@ -20,6 +20,7 @@ import {GET_CITY_LIST, GET_PROVINCE_LIST, GET_ROLE_LIST, UPDATE_EXPERT_MANAGEMEN import * as Yup from "yup"; import useRequest from "@/lib/app/hooks/useRequest"; import useProvince from "@/lib/app/hooks/useProvince"; +import useRole from "@/lib/app/hooks/useRole"; const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { @@ -27,28 +28,14 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { const requestServer = useRequest(); // const [provinceList, setProvinceList] = useState([]); const [cityList, setCityList] = useState([]); - const [roleList, setRoleList] = useState([]); + const [citiesExist, setCitiesExist] = useState(false); const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince(); - - useEffect(() => { - requestServer(GET_ROLE_LIST, "get", {auth: true, notification: false}) - .then(({data}) => { - const result = data.data; - const formattedData = result.map((role, index) => ({ - id: index, - name: role.name, - name_fa: role.name_fa, - value: role.id, - })); - setRoleList(formattedData); - }).catch(() => { - }); - }, []); + const {roleList, isLoadingRoleList, errorRoleList} = useRole(); function getCities(province_id) { formik.setFieldTouched("city_id", false, false); - // formik.setFieldValue("city_id", "") + citiesExist && formik.setFieldValue("city_id", "") setCityTextField(t("ExpertMangement.text_field_loading_cities_list")) requestServer(`${GET_CITY_LIST}?province_id=${province_id}`, "get", {auth: true, notification: false}) .then(({data}) => { @@ -58,6 +45,7 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { name: city.name, value: city.id, })); + setCitiesExist(true); setCityList(formattedData); setCityTextField(t("ExpertMangement.text_field_city_id")) }).catch(() => { @@ -65,7 +53,6 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { }); } - const validationSchema = Yup.object().shape({ name: Yup.string().required(t("ExpertMangement.error_message_name")), username: Yup.string().required(t("ExpertMangement.error_message_username")), @@ -113,6 +100,10 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { }, }); + useEffect(() => { + getCities(formik.values.province_id); + }, [formik.values.province_id]); + return ( <> @@ -227,11 +218,8 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { { {formik.touched.role_id && formik.errors.role_id ? formik.errors.role_id : ""} diff --git a/src/lib/app/hooks/useRole.jsx b/src/lib/app/hooks/useRole.jsx new file mode 100644 index 0000000..fc3dd18 --- /dev/null +++ b/src/lib/app/hooks/useRole.jsx @@ -0,0 +1,29 @@ +import {GET_ROLE_LIST} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useSWR from "swr"; + +const useRole = () => { + const requestServer = useRequest({auth: true, notification: false}) + + //swr config + const fetcher = (...args) => { + return requestServer(args, 'get').then(({data}) => { + return data.data; + }).catch(() => { + }) + }; + + const {data, isLoading} = useSWR(GET_ROLE_LIST, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }); + + return { + roleList: data, + isLoadingRoleList: isLoading, + errorRoleList: !data + } +}; + +export default useRole; \ No newline at end of file From 46d0c415929ae8e9450cdd67491a5709991f9f9d Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Sun, 17 Sep 2023 10:26:09 +0330 Subject: [PATCH 18/25] TF-99 error message required --- public/locales/fa/app.json | 7 +++++-- src/components/dashboard/change-password/index.jsx | 6 +++--- src/components/login-expert/index.jsx | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index bd591f2..071daf8 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -78,7 +78,8 @@ "link_routing_back_to": "بازگشت به", "link_routing_previuos_page": "صفحه قبل", "link_routing_main_page": "صفحه اصلی", - "error_message_required": "اجباری!" + "error_message_username": "وارد کردن نام کاربری الزامیست", + "error_message_password": "وارد کردن رمز عبور الزامیست" }, "ErrorPage": { "custom_404": "صفحه مورد نظر یافت نشد | 404", @@ -112,7 +113,9 @@ "label_current_password": "رمز عبور فعلی", "label_new_password": "رمز عبور جدید", "label_confirm_password": "تکرار رمز عبور جدید", - "error_message_required": "اجباری !", + "error_message_current_password": "وارد کردن رمز عبور فعلی الزامیست", + "error_message_new_password": "وارد کردن رمز عبور جدید الزامیست", + "error_message_confirm_password": "وارد کردن تکرار رمز عبور الزامیست", "error_message_password_length": "رمز عبور باید حداقل 8 کاراکتر باشد.", "error_message_password_match": "پسورد ها یکسان هستند", "error_message_password_not_match": "پسورد و تکرار رمز عبور باید یکسان باشد" diff --git a/src/components/dashboard/change-password/index.jsx b/src/components/dashboard/change-password/index.jsx index ae74de6..0adc477 100644 --- a/src/components/dashboard/change-password/index.jsx +++ b/src/components/dashboard/change-password/index.jsx @@ -35,13 +35,13 @@ const DashboardChangePasswordComponent = () => { }; const validationSchema = Yup.object().shape({ current_password: Yup.string().required( - t("ChangePassword.error_message_required") + t("ChangePassword.error_message_current_password") ), new_password: Yup.string() .min(8, t("ChangePassword.error_message_password_length")) - .required(t("ChangePassword.error_message_required")), + .required(t("ChangePassword.error_message_new_password")), new_password_confirmation: Yup.string() - .required(t("ChangePassword.error_message_required")) + .required(t("ChangePassword.error_message_confirm_password")) .test( t("ChangePassword.error_message_password_match"), t("ChangePassword.error_message_password_not_match"), diff --git a/src/components/login-expert/index.jsx b/src/components/login-expert/index.jsx index 2eaa3bd..9e8d3b3 100644 --- a/src/components/login-expert/index.jsx +++ b/src/components/login-expert/index.jsx @@ -46,8 +46,8 @@ const LoginComponent = () => { password: "", }; const validationSchema = Yup.object().shape({ - username: Yup.string().required(t("LoginPage.error_message_required")), - password: Yup.string().required(t("LoginPage.error_message_required")), + username: Yup.string().required(t("LoginPage.error_message_username")), + password: Yup.string().required(t("LoginPage.error_message_password")), }); return ( From 0c0fc5515eb46175d9f3d356d4f012e17ca3e392 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Sun, 17 Sep 2023 15:18:46 +0330 Subject: [PATCH 19/25] add RegEx for password field and add chnage password option for expert management and a bit debug on update of expert --- public/locales/fa/app.json | 6 ++ .../ChangePassword/ChangePasswordContent.jsx | 91 +++++++++++++++++++ .../Form/ChangePassword/index.jsx | 33 +++++++ .../Form/CreateForm/CreateContent.jsx | 29 +++++- .../Form/UpdateForm/UpdateContent.jsx | 3 +- .../Form/UpdateForm/index.jsx | 23 ----- .../expert-management/TableRowActions.jsx | 7 ++ 7 files changed, 164 insertions(+), 28 deletions(-) create mode 100644 src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx create mode 100644 src/components/dashboard/expert-management/Form/ChangePassword/index.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 60482e2..8aa65ff 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -345,6 +345,7 @@ "button-confirm": "ثبت", "create": "افزودن کارشناس", "update": "ویرایش کارشناس", + "change_password": "تغییر رمز عبور", "text_field_name": "نام", "text_field_username": "نام کاربری", "text_field_email": "پست الکترونیک", @@ -362,21 +363,26 @@ "text_field_please_select_province": "ابتدا استان خود را انتخاب کنید", "text_field_loading_cities_list": "درحال دریافت شهر ها", "text_field_error_fetching_cities": "خطا در دریافت شهر ها", + "text_field_new_password": "رمز عبور جدید", "error_message_name": "نام خود را وارد کنید", "error_message_username": "نام کاربری خود را وارد کنید", "error_message_email": "پست الکترونیک خود را وارد کنید", "error_message_phone_number": "شماره همراه خود را وارد کنید", "error_message_national_id": "کد ملی خود را وارد کنید", "error_message_password": "رمز عبور خود را وارد کنید", + "error_message_password_regex": "رمز عبور باید حداقل 8 کاراکتر و متشکل از عدد، حرف یا سمبل باشد", "error_message_position": "سمت خود را وارد کنید", "error_message_province_id": "استان خود را وارد کنید", "error_message_city_id": "شهر خود را وارد کنید", "error_message_role_id": "نقش خود را وارد کنید", + "error_message_new_password": "رمز عبور جدید را وارد کنید", + "error_message_new_password_regex": "رمز عبور باید حداقل 8 کاراکتر و متشکل از عدد، حرف یا سمبل باشد", "personal_info": "مشخصات کارشناس", "user_info": "اطلاعات کاربری", "rest_info": "اطلاعات تکمیلی", "delete_tooltip": "حذف", "update_tooltip": "ویرایش کارشناس", + "change_password_tooltip": "تغییر رمز عبور", "delete_expert": "حذف کارشناس", "are_you_sure_text": "آیا از انجام این عملیات اطمینان دارید؟" } diff --git a/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx b/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx new file mode 100644 index 0000000..da9abab --- /dev/null +++ b/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx @@ -0,0 +1,91 @@ +import {useTranslations} from "next-intl"; +import {Button, DialogActions, DialogContent, IconButton, InputAdornment, TextField} from "@mui/material"; +import {CHANGE_PASSWORD_EXPERT_MANAGEMENT} from "@/core/data/apiRoutes"; +import {useFormik} from "formik"; +import * as Yup from "yup"; +import {Visibility, VisibilityOff} from "@mui/icons-material"; +import {useState} from "react"; +import useRequest from "@/lib/app/hooks/useRequest"; + + +const ChnagePasswordContent = ({rowId, fetchUrl, mutate, setOpenChangePasswordDialog}) => { + const t = useTranslations(); + const requestServer = useRequest(); + const [showPassword, setShowPassword] = useState(false); + + const handleClickShowPassword = () => { + setShowPassword(!showPassword); + }; + + const validationSchema = Yup.object().shape({ + new_password: Yup.string() + .required(t("ExpertMangement.error_message_new_password")) + .matches( + /^(?=.*[0-9])(?=.*[A-Za-z!@#$%^&*])[A-Za-z!@#$%^&*\d]{8,}$/, + t("ExpertMangement.error_message_new_password_regex") + ), + }); + + const formik = useFormik({ + initialValues: { + new_password: "", + }, + validationSchema, + onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("new_password", values.new_password); + + requestServer(`${CHANGE_PASSWORD_EXPERT_MANAGEMENT}/${rowId}`, 'post', { + auth: true, + data: formData + }) + .then((response) => { + mutate(fetchUrl) + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return ( + <> + + + + {showPassword ? : } + + + ), + }} + sx={{width: "100%"}} + /> + + + + + + + ); +}; +export default ChnagePasswordContent; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/Form/ChangePassword/index.jsx b/src/components/dashboard/expert-management/Form/ChangePassword/index.jsx new file mode 100644 index 0000000..958d1c8 --- /dev/null +++ b/src/components/dashboard/expert-management/Form/ChangePassword/index.jsx @@ -0,0 +1,33 @@ +import {useTranslations} from "next-intl"; +import {Dialog, DialogTitle, IconButton, Tooltip} from "@mui/material"; +import KeyIcon from '@mui/icons-material/Key'; +import {useState} from "react"; +import ChangePasswordContent from "./ChangePasswordContent"; + + +const ChangePassword = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openChnagePasswordDialog, setOpenChangePasswordDialog] = useState(false); + + return ( + <> + + { + setOpenChangePasswordDialog(true) + }} + > + + + + + {t("ExpertMangement.change_password")} + + + + ); +}; +export default ChangePassword; \ No newline at end of file diff --git a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx index f2e43cb..c22783a 100644 --- a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx +++ b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx @@ -8,6 +8,8 @@ import { FormControl, FormHelperText, Grid, + IconButton, + InputAdornment, InputLabel, MenuItem, Select, @@ -16,11 +18,12 @@ import { import {useFormik} from "formik"; import {useTranslations} from "next-intl"; import * as Yup from "yup"; -import {useEffect, useState} from "react"; -import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST, GET_ROLE_LIST} from "@/core/data/apiRoutes"; +import {useState} from "react"; +import {CREATE_EXPERT_MANAGEMENT, GET_CITY_LIST} from "@/core/data/apiRoutes"; import useRequest from "@/lib/app/hooks/useRequest"; import useProvince from "@/lib/app/hooks/useProvince"; import useRole from "@/lib/app/hooks/useRole"; +import {Visibility, VisibilityOff} from "@mui/icons-material"; const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { const t = useTranslations(); @@ -29,6 +32,11 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { const [cityTextField, setCityTextField] = useState(t("ExpertMangement.text_field_please_select_province")); const {provinceList, isLoadingProvinceList, errorProvinceList} = useProvince(); const {roleList, isLoadingRoleList, errorRoleList} = useRole(); + const [showPassword, setShowPassword] = useState(false); + + const handleClickShowPassword = () => { + setShowPassword(!showPassword); + }; function getCities(province_id) { formik.setFieldTouched("city_id", false, false); @@ -56,7 +64,12 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { email: Yup.string().required(t("ExpertMangement.error_message_email")), phone_number: Yup.string().required(t("ExpertMangement.error_message_phone_number")), national_id: Yup.string().required(t("ExpertMangement.error_message_national_id")), - password: Yup.string().required(t("ExpertMangement.error_message_password")), + password: Yup.string() + .required(t("ExpertMangement.error_message_password")) + .matches( + /^(?=.*[0-9])(?=.*[A-Za-z!@#$%^&*])[A-Za-z!@#$%^&*\d]{8,}$/, + t("ExpertMangement.error_message_password_regex") + ), position: Yup.string().required(t("ExpertMangement.error_message_position")), province_id: Yup.string().required(t("ExpertMangement.error_message_province_id")), city_id: Yup.string().required(t("ExpertMangement.error_message_city_id")), @@ -208,6 +221,16 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { onBlur={formik.handleBlur} error={formik.touched.password && !!formik.errors.password} helperText={formik.touched.password && formik.errors.password ? formik.errors.password : null} + type={showPassword ? "text" : "password"} + InputProps={{ + endAdornment: ( + + + {showPassword ? : } + + + ), + }} sx={{width: "100%"}} /> diff --git a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx index 45edcde..0b8ae58 100644 --- a/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx +++ b/src/components/dashboard/expert-management/Form/UpdateForm/UpdateContent.jsx @@ -59,7 +59,6 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { email: Yup.string().required(t("ExpertMangement.error_message_email")), phone_number: Yup.string().required(t("ExpertMangement.error_message_phone_number")), national_id: Yup.string().required(t("ExpertMangement.error_message_national_id")), - password: Yup.string().required(t("ExpertMangement.error_message_password")), position: Yup.string().required(t("ExpertMangement.error_message_position")), province_id: Yup.string().required(t("ExpertMangement.error_message_province_id")), city_id: Yup.string().required(t("ExpertMangement.error_message_city_id")), @@ -300,7 +299,7 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => { row.province_name, - id: "province_id", + id: "province_name", header: t("ExpertMangement.province_name"), - enableColumnFilter: true, + enableColumnFilter: false, datatype: "text", filterFn: "contains", columnFilterModeOptions: ["contains", "equals", "notEquals"], @@ -118,9 +118,9 @@ function DashboardExpertManagementComponent() { }, { accessorFn: (row) => row.city_name, - id: "city_id", + id: "city_name", header: t("ExpertMangement.city_name"), - enableColumnFilter: true, + enableColumnFilter: false, datatype: "text", filterFn: "contains", columnFilterModeOptions: ["contains", "equals", "notEquals"], @@ -129,10 +129,10 @@ function DashboardExpertManagementComponent() { ), }, { - accessorFn: (row) => row.role_name, - id: "role_id", + accessorFn: (row) => row.roles[0].name_fa, + id: "roles[0].name_fa", header: t("ExpertMangement.role_name"), - enableColumnFilter: true, + enableColumnFilter: false, datatype: "text", filterFn: "contains", columnFilterModeOptions: ["contains", "equals", "notEquals"], From 4f5cb353842082942413bd12b0ef44c241adbfda Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Sun, 17 Sep 2023 17:16:46 +0330 Subject: [PATCH 21/25] TF-100 bugfix of password regex --- .../Form/ChangePassword/ChangePasswordContent.jsx | 2 +- .../expert-management/Form/CreateForm/CreateContent.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx b/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx index da9abab..b1c708c 100644 --- a/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx +++ b/src/components/dashboard/expert-management/Form/ChangePassword/ChangePasswordContent.jsx @@ -21,7 +21,7 @@ const ChnagePasswordContent = ({rowId, fetchUrl, mutate, setOpenChangePasswordDi new_password: Yup.string() .required(t("ExpertMangement.error_message_new_password")) .matches( - /^(?=.*[0-9])(?=.*[A-Za-z!@#$%^&*])[A-Za-z!@#$%^&*\d]{8,}$/, + /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/, t("ExpertMangement.error_message_new_password_regex") ), }); diff --git a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx index c22783a..14e0032 100644 --- a/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx +++ b/src/components/dashboard/expert-management/Form/CreateForm/CreateContent.jsx @@ -67,7 +67,7 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => { password: Yup.string() .required(t("ExpertMangement.error_message_password")) .matches( - /^(?=.*[0-9])(?=.*[A-Za-z!@#$%^&*])[A-Za-z!@#$%^&*\d]{8,}$/, + /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/, t("ExpertMangement.error_message_password_regex") ), position: Yup.string().required(t("ExpertMangement.error_message_position")), From ef2244584d9f70216b00ce048a323d3f7db5e751 Mon Sep 17 00:00:00 2001 From: Mohammad Jalali Date: Mon, 18 Sep 2023 10:21:09 +0330 Subject: [PATCH 22/25] bug fix for change password page --- src/components/dashboard/change-password/index.jsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/dashboard/change-password/index.jsx b/src/components/dashboard/change-password/index.jsx index 0adc477..cd2b9fd 100644 --- a/src/components/dashboard/change-password/index.jsx +++ b/src/components/dashboard/change-password/index.jsx @@ -38,8 +38,11 @@ const DashboardChangePasswordComponent = () => { t("ChangePassword.error_message_current_password") ), new_password: Yup.string() - .min(8, t("ChangePassword.error_message_password_length")) - .required(t("ChangePassword.error_message_new_password")), + .required(t("ExpertMangement.error_message_new_password")) + .matches( + /^(?=.*[a-zA-Z])(?=.*\d).{8,}$/, + t("ExpertMangement.error_message_new_password_regex") + ), new_password_confirmation: Yup.string() .required(t("ChangePassword.error_message_confirm_password")) .test( From eb4af5c824b36594d4eb18ffc45e6d48801d4d5e Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 18 Sep 2023 14:14:51 +0330 Subject: [PATCH 23/25] TF-96 role management initialize --- public/locales/fa/app.json | 21 +++ .../Form/CreateForm/CreateContent.jsx | 137 +++++++++++++++ .../role-management/Form/CreateForm/index.jsx | 35 ++++ .../role-management/Form/DeleteForm.jsx | 67 ++++++++ .../role-management/Form/UpdateForm.jsx | 156 ++++++++++++++++++ .../role-management/TableRowActions.jsx | 23 +++ .../role-management/TableToolbar.jsx | 11 ++ .../dashboard/role-management/index.jsx | 96 +++++++++++ src/core/data/apiRoutes.js | 14 ++ src/core/data/sidebarMenu.jsx | 10 ++ src/lib/app/hooks/usePermissions.jsx | 25 +++ src/pages/dashboard/role-management/index.jsx | 26 +++ 12 files changed, 621 insertions(+) create mode 100644 src/components/dashboard/role-management/Form/CreateForm/CreateContent.jsx create mode 100644 src/components/dashboard/role-management/Form/CreateForm/index.jsx create mode 100644 src/components/dashboard/role-management/Form/DeleteForm.jsx create mode 100644 src/components/dashboard/role-management/Form/UpdateForm.jsx create mode 100644 src/components/dashboard/role-management/TableRowActions.jsx create mode 100644 src/components/dashboard/role-management/TableToolbar.jsx create mode 100644 src/components/dashboard/role-management/index.jsx create mode 100644 src/lib/app/hooks/usePermissions.jsx create mode 100644 src/pages/dashboard/role-management/index.jsx diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 071daf8..b070875 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -48,6 +48,7 @@ "change-password": "تغییر رمز عبور", "development-assistant": "معاون توسعه", "user-management": "مدیریت کاربر", + "role-management": "مدیریت نقش ها", "edit-profile": "ویرایش پروفایل" }, "secondary": { @@ -103,6 +104,7 @@ "inspector_expert_page": "بازدید کارشناس", "commercial_chief_page": "رئیس اداره بازرگانی", "user_management_page": "مدیریت کاربر", + "role_management_page": "مدیریت نقش ها", "edit_profile": "ویرایش پروفایل" }, "MuiDatePicker": { @@ -290,6 +292,13 @@ "vehicle_type": "نوع ماشین", "state_name": "وضعیت درخواست" }, + "RoleManagement": { + "id": "کد یکتا", + "name_fa": "نام فارسی ", + "name": "نام انگلیسی", + "created_at": "تاریخ درخواست", + "updated_at": "تاریخ بروزرسانی" + }, "ConfirmDialog": { "confirm": "تایید", "context": "آیا از تایید این آیتم اطمینان دارید؟", @@ -334,6 +343,12 @@ "navgan": "ناوگان", "phone_number": "شماره تلفن", "national_id": "کد ملی", + "name": "نام انگلیسی", + "name_error": "وارد کردن نام انگلیسی الزامیست", + "name_fa": "نام فارسی", + "name_fa_error": "وارد کردن نام فارسی الزامیست", + "permission": "دسترسی", + "permission_min_error": "حداقل باید یک دسترسی انتخاب شود", "type_id": "نوع کاربر", "navgan_id": "کد ناوگان", "button-update": "ویرایش" @@ -358,6 +373,12 @@ }, "AddDialog": { "add": "افزودن کاربر جدید", + "name": "نام انگلیسی", + "name_error": "وارد کردن نام انگلیسی الزامیست", + "name_fa": "نام فارسی", + "name_fa_error": "وارد کردن نام فارسی الزامیست", + "permission": "دسترسی", + "permission_min_error": "حداقل باید یک دسترسی انتخاب شود", "phone_number": "شماره تلفن", "phone_number_positive": "شماره تلفن باید مثبت باشد", "phone_number_error": "وارد کردن شماره تلفن الزامیست", diff --git a/src/components/dashboard/role-management/Form/CreateForm/CreateContent.jsx b/src/components/dashboard/role-management/Form/CreateForm/CreateContent.jsx new file mode 100644 index 0000000..a7f5f37 --- /dev/null +++ b/src/components/dashboard/role-management/Form/CreateForm/CreateContent.jsx @@ -0,0 +1,137 @@ +import { + Button, + Checkbox, + DialogActions, + DialogContent, + FormControl, + FormControlLabel, + FormHelperText, + FormLabel, + Grid, + Stack, + TextField +} from "@mui/material"; +import {useTranslations} from "next-intl"; +import useRequest from "@/lib/app/hooks/useRequest"; +import * as Yup from "yup"; +import {useFormik} from "formik"; +import {ADD_ROLE_MANAGEMENT} from "@/core/data/apiRoutes"; +import usePermissions from "@/lib/app/hooks/usePermissions"; + +const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => { + const t = useTranslations(); + const requestServer = useRequest({auth: true}) + const {permissions_list} = usePermissions() + const validationSchema = Yup.object().shape({ + name: Yup.string().required(t("AddDialog.name_error")), + name_fa: Yup.string().required(t("AddDialog.name_fa_error")), + permissions: Yup.array().min(1, t("AddDialog.permission_min_error")).required(t("AddDialog.permission")), + }); + const formik = useFormik({ + initialValues: { + name: "", + name_fa: "", + permissions: [], + }, validationSchema, onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("name", values.name); + formData.append("name_fa", values.name_fa); + for (let i = 0; i < values.permissions.length; i++) { + formData.append(`permissions[${i}]`, values.permissions[i]); + } + + requestServer(ADD_ROLE_MANAGEMENT, 'post', { + data: formData, + }).then((response) => { + setOpenConfirmDialog(false) + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return ( + <> + + + + + + + + {t("AddDialog.permission")}
+ + {formik.touched.permissions && formik.errors.permissions} + + {permissions_list ? ( + permissions_list.map((permission) => ( + + { + if (e.target.checked) { + formik.setFieldValue("permissions", [...formik.values.permissions, permission.id]) + } else { + formik.setFieldValue("permissions", formik.values.permissions.filter((id) => id !== permission.id)) + } + }} + /> + } + label={permission.name_fa} + /> + + )) + ) : null} + + +
+
+
+
+ + + + + + ) +} +export default CreateContent \ No newline at end of file diff --git a/src/components/dashboard/role-management/Form/CreateForm/index.jsx b/src/components/dashboard/role-management/Form/CreateForm/index.jsx new file mode 100644 index 0000000..f0a27e7 --- /dev/null +++ b/src/components/dashboard/role-management/Form/CreateForm/index.jsx @@ -0,0 +1,35 @@ +import {Button, Dialog, DialogTitle, Stack, Tooltip} from "@mui/material"; +import DataSaverOnIcon from "@mui/icons-material/DataSaverOn"; +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import CreateContent from "./CreateContent"; + +const CreateForm = ({mutate, fetchUrl}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + + return ( + + + + + + {t("AddDialog.add")} + + + + ) +} +export default CreateForm \ No newline at end of file diff --git a/src/components/dashboard/role-management/Form/DeleteForm.jsx b/src/components/dashboard/role-management/Form/DeleteForm.jsx new file mode 100644 index 0000000..9c613b1 --- /dev/null +++ b/src/components/dashboard/role-management/Form/DeleteForm.jsx @@ -0,0 +1,67 @@ +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import { + Button, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + IconButton, + Tooltip, + Typography +} from "@mui/material"; +import DeleteIcon from '@mui/icons-material/Delete'; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; +import {DELETE_ROLE_MANAGEMENT} from "@/core/data/apiRoutes"; + +const DeleteForm = ({rowId, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const [isSubmitting, setIsSubmitting] = useState(false) + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + const handleSubmit = () => { + setIsSubmitting(true) + requestServer(`${DELETE_ROLE_MANAGEMENT}/${rowId}`, 'delete').then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setIsSubmitting(false) + }); + } + + return ( + <> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("DeleteDialog.delete")} + + {t("DeleteDialog.typography")} + + + + + + + + ); +}; +export default DeleteForm; \ No newline at end of file diff --git a/src/components/dashboard/role-management/Form/UpdateForm.jsx b/src/components/dashboard/role-management/Form/UpdateForm.jsx new file mode 100644 index 0000000..7fd4459 --- /dev/null +++ b/src/components/dashboard/role-management/Form/UpdateForm.jsx @@ -0,0 +1,156 @@ +import {useTranslations} from "next-intl"; +import {useState} from "react"; +import { + Button, + Checkbox, + Dialog, + DialogActions, + DialogContent, + DialogTitle, + FormControl, + FormControlLabel, + FormHelperText, + FormLabel, + Grid, + IconButton, + Stack, + TextField, + Tooltip +} from "@mui/material"; +import {useFormik} from "formik"; +import EditIcon from '@mui/icons-material/Edit'; +import {UPDATE_ROLE_MANAGEMENT} from "@/core/data/apiRoutes"; +import useRequest from "@/lib/app/hooks/useRequest"; +import useNotification from "@/lib/app/hooks/useNotification"; +import * as Yup from "yup"; +import usePermissions from "@/lib/app/hooks/usePermissions"; + +const UpdateForm = ({row, fetchUrl, mutate}) => { + const t = useTranslations(); + const [openConfirmDialog, setOpenConfirmDialog] = useState(false); + const requestServer = useRequest({auth: true}) + const {update_notification} = useNotification() + const {permissions_list} = usePermissions() + + const validationSchema = Yup.object().shape({ + name: Yup.string().required(t("UpdateDialog.name_error")), + name_fa: Yup.string().required(t("UpdateDialog.name_fa_error")), + permissions: Yup.array().min(1, t("UpdateDialog.permission_min_error")).required(t("UpdateDialog.permission")), + }); + + const formik = useFormik({ + initialValues: { + name: row.getValue("name"), + name_fa: row.getValue("name_fa"), + permissions: row.original.permissions.map((obj) => obj.id), + }, validationSchema, onSubmit: (values, {setSubmitting}) => { + const formData = new FormData(); + formData.append("name", values.name); + formData.append("name_fa", values.name_fa); + for (let i = 0; i < values.permissions.length; i++) { + formData.append(`permissions[${i}]`, values.permissions[i]); + } + + requestServer(`${UPDATE_ROLE_MANAGEMENT}/${row.getValue("id")}`, 'post', { + data: formData, + }).then((response) => { + mutate(fetchUrl) + update_notification() + }).catch(() => { + }).finally(() => { + setSubmitting(false); + }); + }, + }); + + return (<> + + { + setOpenConfirmDialog(true) + }} + > + + + + + {t("UpdateDialog.update")} + + + + + + + + {t("UpdateDialog.permission")}
+ + {formik.touched.permissions && formik.errors.permissions} + + {permissions_list ? ( + permissions_list.map((permission) => ( + + { + if (e.target.checked) { + formik.setFieldValue("permissions", [...formik.values.permissions, permission.id]) + } else { + formik.setFieldValue("permissions", formik.values.permissions.filter((id) => id !== permission.id)) + } + }} + /> + } + label={permission.name_fa} + /> + + )) + ) : null} + + +
+
+
+
+ + + + +
+ ); +}; +export default UpdateForm; \ No newline at end of file diff --git a/src/components/dashboard/role-management/TableRowActions.jsx b/src/components/dashboard/role-management/TableRowActions.jsx new file mode 100644 index 0000000..5b0f031 --- /dev/null +++ b/src/components/dashboard/role-management/TableRowActions.jsx @@ -0,0 +1,23 @@ +import {Box} from "@mui/material"; +import DeleteForm from "./Form/DeleteForm" +import UpdateForm from "./Form/UpdateForm" + +const TableRowActions = ({row, mutate, fetchUrl}) => { + + return ( + + + + + ); +}; + +export default TableRowActions; diff --git a/src/components/dashboard/role-management/TableToolbar.jsx b/src/components/dashboard/role-management/TableToolbar.jsx new file mode 100644 index 0000000..c4cb13b --- /dev/null +++ b/src/components/dashboard/role-management/TableToolbar.jsx @@ -0,0 +1,11 @@ +import {useTranslations} from "next-intl"; +import CreateForm from "./Form/CreateForm/index"; + +function TableToolbar({mutate, fetchUrl}) { + const t = useTranslations(); + + return + +} + +export default TableToolbar; diff --git a/src/components/dashboard/role-management/index.jsx b/src/components/dashboard/role-management/index.jsx new file mode 100644 index 0000000..5d55575 --- /dev/null +++ b/src/components/dashboard/role-management/index.jsx @@ -0,0 +1,96 @@ +import DashboardLayouts from "@/layouts/dashboardLayouts"; +import {Box, Typography} from "@mui/material"; +import {useMemo} from "react"; +import {GET_ROLE_MANAGEMENT} from "@/core/data/apiRoutes"; +import {useTranslations} from "next-intl"; +import DataTable from "@/core/components/DataTable"; +import moment from "jalali-moment"; +import MuiDatePicker from "@/core/components/MuiDatePicker"; +import TableToolbar from "@/components/dashboard/role-management/TableToolbar"; +import TableRowActions from "./TableRowActions" + +function DashboardRoleManagementComponent() { + const t = useTranslations(); + + const columns = useMemo(() => [{ + accessorFn: (row) => row.id, + id: "id", + sortDescFirst: true, + header: t("RoleManagement.id"), + enableColumnFilter: true, + datatype: "numeric", + filterFn: "equals", + columnFilterModeOptions: ["equals", "notEquals", "contains", "lessThan", "greaterThan", "between",], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, + { + accessorFn: (row) => row.name_fa, + id: "name_fa", + header: t("RoleManagement.name_fa"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains", "equals", "notEquals"], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, + { + accessorFn: (row) => row.name, + id: "name", + header: t("RoleManagement.name"), + enableColumnFilter: true, + datatype: "text", + filterFn: "contains", + columnFilterModeOptions: ["contains"], + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }, + { + accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "created_at", + header: t("RoleManagement.created_at"), + enableColumnFilter: true, + datatype: "date", + filterFn: "lessThan", + columnFilterModeOptions: ["lessThan", "greaterThan"], + Cell: ({renderedCellValue}) => { + return {renderedCellValue}; + }, + Header: ({column}) => <>{column.columnDef.header}, + Filter: ({column}) => { + return (); + }, + }, { + accessorFn: (row) => moment(row.updated_at).locale("fa").format("HH:mm | yyyy/MM/DD"), + id: "updated_at", + header: t("RoleManagement.updated_at"), + enableColumnFilter: false, + datatype: "numeric", + Cell: ({renderedCellValue}) => ({renderedCellValue}), + }], []); + return ( + + + + ); +} + +export default DashboardRoleManagementComponent; diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 19b89a2..127e205 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -161,3 +161,17 @@ export const UPDATE_USER_MANAGEMENT = export const DELETE_USER_MANAGEMENT = BASE_URL + "/dashboard/user_management/delete" //user management + +// role management +export const GET_ROLE_MANAGEMENT = + BASE_URL + "/dashboard/roles" +export const ADD_ROLE_MANAGEMENT = + BASE_URL + "/dashboard/roles/store" +export const UPDATE_ROLE_MANAGEMENT = + BASE_URL + "/dashboard/roles/update" +export const DELETE_ROLE_MANAGEMENT = + BASE_URL + "/dashboard/roles/delete" + +export const GET_PERMISSIONS_LIST = + BASE_URL + "/dashboard/permissions/list" +//role management diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 4957bad..de305d7 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -11,6 +11,7 @@ import SupervisedUserCircleIcon from '@mui/icons-material/SupervisedUserCircle'; import Diversity3Icon from '@mui/icons-material/Diversity3'; import PaidIcon from '@mui/icons-material/Paid'; import PersonIcon from '@mui/icons-material/Person'; +import AccessibilityIcon from '@mui/icons-material/Accessibility'; const sidebarMenu = [ [ @@ -146,6 +147,15 @@ const sidebarMenu = [ selected: false, permission: "manage_users", }, + { + key: "sidebar.role-management", + name: "role_management", + type: "page", + route: "/dashboard/role-management", + icon: , + selected: false, + permission: "manage_roles", + }, ], ]; diff --git a/src/lib/app/hooks/usePermissions.jsx b/src/lib/app/hooks/usePermissions.jsx new file mode 100644 index 0000000..0e6aa07 --- /dev/null +++ b/src/lib/app/hooks/usePermissions.jsx @@ -0,0 +1,25 @@ +import useRequest from "@/lib/app/hooks/useRequest"; +import useSWR from "swr"; +import {GET_PERMISSIONS_LIST} from "@/core/data/apiRoutes"; + +const usePermissions = () => { + const requestServer = useRequest({auth: true, notification: false}) + const fetcher = (...args) => { + return requestServer(args, 'get').then((response) => { + return response.data.data; + }).catch(() => { + }) + }; + + const {data} = useSWR(GET_PERMISSIONS_LIST, fetcher, { + revalidateIfStale: false, + revalidateOnFocus: false, + revalidateOnReconnect: false + }) + const permissions_list = data + //swr config + + // render data + return {permissions_list} +} +export default usePermissions; \ No newline at end of file diff --git a/src/pages/dashboard/role-management/index.jsx b/src/pages/dashboard/role-management/index.jsx new file mode 100644 index 0000000..c309729 --- /dev/null +++ b/src/pages/dashboard/role-management/index.jsx @@ -0,0 +1,26 @@ +import RolePermissionMiddleware from "@/middlewares/RolePermission"; +import WithAuthMiddleware from "@/middlewares/WithAuth"; +import {parse} from "next-useragent"; +import DashboardRoleManagementComponent from "@/components/dashboard/role-management"; + +const requiredPermissions = ["manage_roles"]; +export default function RoleManagement() { + return ( + + + + + + ); +} + +export async function getServerSideProps({req, locale}) { + const {isBot} = parse(req.headers["user-agent"]); + return { + props: { + messages: (await import(`&/locales/${locale}/app.json`)).default, + title: "Dashboard.role_management_page", + isBot, + }, + }; +} From 37025bc4dd375902cbbb9cbdbc7c3d5004df019b Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 18 Sep 2023 16:04:35 +0330 Subject: [PATCH 24/25] TF-101 fix responsive bug --- public/locales/fa/app.json | 4 +++ .../dashboard/expert-management/index.jsx | 3 ++ .../machinary-office/Form/ConfirmForm.jsx | 4 +-- .../passenger-boss/Form/ConfirmForm.jsx | 2 +- .../dashboard/passenger-boss/index.jsx | 1 - .../Form/ConfirmForm.jsx | 2 -- src/core/components/PriceField.jsx | 32 +++++++++---------- 7 files changed, 25 insertions(+), 23 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 02ce525..c335958 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -339,6 +339,10 @@ }, "UpdateDialog": { "update": "ویرایش", + "description": "توضیحات خود را وارد نمائید", + "description_error": "وارد کردن توضیحات الزامی است!", + "next-state-id": "وضعیت", + "next-state-id-error": "وارد کردن وضعیت الزامیست", "update-tooltip": "ویرایش", "button-cancel": "بستن", "refahi": "رفاهی", diff --git a/src/components/dashboard/expert-management/index.jsx b/src/components/dashboard/expert-management/index.jsx index 34e6785..a87cab0 100644 --- a/src/components/dashboard/expert-management/index.jsx +++ b/src/components/dashboard/expert-management/index.jsx @@ -170,6 +170,9 @@ function DashboardExpertManagementComponent() { columns={columns} selectableRow={false} CustomToolbar={TableToolbar} + sorting={[{ + id: 'id', desc: true + }]} enableCustomToolbar={true} enableLastUpdate={true} enablePinning={true} diff --git a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx index a55653c..555c580 100644 --- a/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx +++ b/src/components/dashboard/machinary-office/Form/ConfirmForm.jsx @@ -14,7 +14,6 @@ import { } from "@mui/material"; import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import UploadSystem from "@/core/components/UploadSystem"; -import useDirection from "@/lib/app/hooks/useDirection"; import {useFormik} from "formik"; import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; import {CONFIRM_MACHINARY_OFFICE} from "@/core/data/apiRoutes"; @@ -26,7 +25,6 @@ import PriceField from "@/core/components/PriceField"; const Confirm = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); - const {directionApp} = useDirection(); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); @@ -113,7 +111,7 @@ const Confirm = ({rowId, fetchUrl, mutate}) => { PaperProps={{sx: {boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'}}}> {t("ConfirmDialog.confirm")} - + { PaperProps={{sx: {boxShadow: 'rgba(60, 64, 67, 0.3) 0px 1px 16px 0px, rgba(60, 64, 67, 0.15) 0px 1px 10px 0px'}}}> {t("ConfirmDialog.confirm")} - +
diff --git a/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx b/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx index 7aba85c..6319be8 100644 --- a/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx +++ b/src/components/dashboard/transportation-assistance/Form/ConfirmForm.jsx @@ -14,7 +14,6 @@ import { } from "@mui/material"; import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt"; import UploadSystem from "@/core/components/UploadSystem"; -import useDirection from "@/lib/app/hooks/useDirection"; import {useFormik} from "formik"; import UploadFileNotification from "@/core/components/notifications/UploadFileNotification"; import {CONFIRM_TRANSPORTATION_ASSISTANCE} from "@/core/data/apiRoutes"; @@ -24,7 +23,6 @@ import useNotification from "@/lib/app/hooks/useNotification"; const Confirm = ({rowId, fetchUrl, mutate}) => { const t = useTranslations(); - const {directionApp} = useDirection(); const [selectedImage, setSelectedImage] = useState(""); const [fileType, setfileType] = useState(null); const [fileName, setfileName] = useState(null); diff --git a/src/core/components/PriceField.jsx b/src/core/components/PriceField.jsx index 29d8763..e62e4e1 100644 --- a/src/core/components/PriceField.jsx +++ b/src/core/components/PriceField.jsx @@ -1,23 +1,23 @@ -import {InputAdornment, TextField, Typography} from "@mui/material"; +import {Stack, TextField, Typography} from "@mui/material"; import {useTranslations} from "next-intl"; const PriceField = (props) => { const t = useTranslations(); return ( - - {((props.value) / 10).toLocaleString()} - {t("ConfirmDialog.toman")} - - ), - }} - {...props} - /> - ) + + + + + + + {((props.value) / 10).toLocaleString()} + + + {t("ConfirmDialog.toman")} + + + ) } export default PriceField \ No newline at end of file From b648fdafcb7fd3dd5c9c69f61459fb7a1ad840d4 Mon Sep 17 00:00:00 2001 From: AmirHossein Mahmoodi Date: Tue, 19 Sep 2023 10:16:24 +0330 Subject: [PATCH 25/25] change version to 1.7.5 --- example.env.local | 2 +- package.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/example.env.local b/example.env.local index 2c06285..6a02763 100644 --- a/example.env.local +++ b/example.env.local @@ -1,5 +1,5 @@ NEXT_PUBLIC_API_NAME = "Loan Facilities Dashboard" -NEXT_PUBLIC_API_VERSION = "1.0.0" +NEXT_PUBLIC_API_VERSION = "1.7.5" NEXT_PUBLIC_DEFAULT_LANGUAGE = "fa" NEXT_PUBLIC_DEFAULT_DIRECTION = "rtl" diff --git a/package.json b/package.json index 86613ec..c51cd27 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "dashboard", - "version": "0.1.0", + "name": "LoanFacilitiesDashboard", + "version": "1.7.5", "private": true, "scripts": { "dev": "next dev",