CFE-4 Merge branch 'feature/CFE-4_mock_handler_structure' into 'develop'
This commit is contained in:
153
mocks/handler.js
153
mocks/handler.js
@@ -1,146 +1,13 @@
|
|||||||
import {
|
import {userHandler} from "./handlers/user";
|
||||||
GET_PERMISSIONS_LIST,
|
import {permissionsHandler} from "./handlers/permissions";
|
||||||
GET_ROLE_MANAGEMENT,
|
import {rolesHandler} from "./handlers/roles";
|
||||||
GET_SIDEBAR_NOTIFICATION,
|
import {provincesHandler} from "./handlers/provinces";
|
||||||
GET_USER_ROUTE,
|
import {expertsHandler} from "./handlers/experts";
|
||||||
SET_USER_PASSWORD,
|
|
||||||
EXPERT_MANAGEMENT,
|
|
||||||
GET_PROVINCE_LIST,
|
|
||||||
GET_ROLE_LIST,
|
|
||||||
} from "@/core/data/apiRoutes";
|
|
||||||
import {rest} from "msw";
|
|
||||||
|
|
||||||
export const handler = [
|
export const handler = [
|
||||||
rest.get(GET_USER_ROUTE, (req, res, ctx) => {
|
...userHandler,
|
||||||
return res(ctx.json({
|
...permissionsHandler,
|
||||||
data: {
|
...rolesHandler,
|
||||||
id: 10,
|
...provincesHandler,
|
||||||
permissions: [
|
...expertsHandler
|
||||||
"manage_users"
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
rest.get(GET_SIDEBAR_NOTIFICATION, (req, res, ctx) => {
|
|
||||||
return res(ctx.json({
|
|
||||||
data: []
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
rest.post(SET_USER_PASSWORD, (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.status(200),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
|
||||||
return res(ctx.json(
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "manage_passenger_office_navgan",
|
|
||||||
name_fa: "مدیریت کارتابل رییس اداره مسافری استان"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "manage_province_working_group_navgan",
|
|
||||||
name_fa: "مدیریت کارتابل کارگروه استانی"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
))
|
|
||||||
}),
|
|
||||||
rest.get(GET_ROLE_MANAGEMENT, (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.json(
|
|
||||||
{
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
created_at: "2023-10-01T07:20:07.000000Z",
|
|
||||||
guard_name: "api",
|
|
||||||
id: 1,
|
|
||||||
name: "admin",
|
|
||||||
name_fa: "ادمین",
|
|
||||||
permissions: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "manage_users",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "manage_roles",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
created_at: "2023-10-01T07:20:07.000000Z",
|
|
||||||
guard_name: "api",
|
|
||||||
id: 2,
|
|
||||||
name: "manager",
|
|
||||||
name_fa: "مدیر",
|
|
||||||
permissions: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "manage_users",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "manage_roles",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
updated_at: "2023-10-10T07:38:12.000000Z"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
meta: {
|
|
||||||
totalRowCount: 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
rest.get(GET_PROVINCE_LIST, (req, res, ctx) => {
|
|
||||||
return res(ctx.json({
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "آذربایجان شرقی"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
name: "اردبیل"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
|
||||||
return res(ctx.json({
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: "admin",
|
|
||||||
name_fa: "ادمین"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: "manager",
|
|
||||||
name_fa: "مدیر"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}))
|
|
||||||
}),
|
|
||||||
rest.post(EXPERT_MANAGEMENT, (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.status(200),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
rest.delete(`${EXPERT_MANAGEMENT}/:id`, (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.status(200),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
rest.post(`${EXPERT_MANAGEMENT}/:id`, (req, res, ctx) => {
|
|
||||||
return res(
|
|
||||||
ctx.status(200),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
]
|
]
|
||||||
20
mocks/handlers/experts.js
Normal file
20
mocks/handlers/experts.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import {rest} from "msw";
|
||||||
|
import {ADD_EXPERT, DELETE_EXPERT, UPDATE_EXPERT} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
|
export const expertsHandler = [
|
||||||
|
rest.post(ADD_EXPERT, (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.status(200),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
rest.delete(`${DELETE_EXPERT}/:id`, (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.status(200),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
rest.post(`${UPDATE_EXPERT}/:id`, (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.status(200),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
]
|
||||||
23
mocks/handlers/permissions.js
Normal file
23
mocks/handlers/permissions.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import {rest} from "msw";
|
||||||
|
import {GET_PERMISSIONS_LIST} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
|
export const permissionsHandler = [
|
||||||
|
rest.get(GET_PERMISSIONS_LIST, (req, res, ctx) => {
|
||||||
|
return res(ctx.json(
|
||||||
|
{
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "manage_passenger_office_navgan",
|
||||||
|
name_fa: "مدیریت کارتابل رییس اداره مسافری استان"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "manage_province_working_group_navgan",
|
||||||
|
name_fa: "مدیریت کارتابل کارگروه استانی"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
))
|
||||||
|
})
|
||||||
|
]
|
||||||
19
mocks/handlers/provinces.js
Normal file
19
mocks/handlers/provinces.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import {rest} from "msw";
|
||||||
|
import {GET_PROVINCE_LIST} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
|
export const provincesHandler = [
|
||||||
|
rest.get(GET_PROVINCE_LIST, (req, res, ctx) => {
|
||||||
|
return res(ctx.json({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "آذربایجان شرقی"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
name: "اردبیل"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
]
|
||||||
70
mocks/handlers/roles.js
Normal file
70
mocks/handlers/roles.js
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
import {rest} from "msw";
|
||||||
|
import {GET_ROLE_LIST, GET_ROLES} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
|
export const rolesHandler = [
|
||||||
|
rest.get(GET_ROLES, (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.json(
|
||||||
|
{
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
created_at: "2023-10-01T07:20:07.000000Z",
|
||||||
|
guard_name: "api",
|
||||||
|
id: 1,
|
||||||
|
name: "admin",
|
||||||
|
name_fa: "ادمین",
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "manage_users",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "manage_roles",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
created_at: "2023-10-01T07:20:07.000000Z",
|
||||||
|
guard_name: "api",
|
||||||
|
id: 2,
|
||||||
|
name: "manager",
|
||||||
|
name_fa: "مدیر",
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "manage_users",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "manage_roles",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
updated_at: "2023-10-10T07:38:12.000000Z"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
meta: {
|
||||||
|
totalRowCount: 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
rest.get(GET_ROLE_LIST, (req, res, ctx) => {
|
||||||
|
return res(ctx.json({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
name: "admin",
|
||||||
|
name_fa: "ادمین"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "manager",
|
||||||
|
name_fa: "مدیر"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
]
|
||||||
25
mocks/handlers/user.js
Normal file
25
mocks/handlers/user.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import {rest} from "msw";
|
||||||
|
import {GET_SIDEBAR_NOTIFICATION, GET_USER, SET_USER_PASSWORD} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
|
export const userHandler = [
|
||||||
|
rest.get(GET_USER, (req, res, ctx) => {
|
||||||
|
return res(ctx.json({
|
||||||
|
data: {
|
||||||
|
id: 10,
|
||||||
|
permissions: [
|
||||||
|
"manage_users"
|
||||||
|
],
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
rest.get(GET_SIDEBAR_NOTIFICATION, (req, res, ctx) => {
|
||||||
|
return res(ctx.json({
|
||||||
|
data: []
|
||||||
|
}))
|
||||||
|
}),
|
||||||
|
rest.post(SET_USER_PASSWORD, (req, res, ctx) => {
|
||||||
|
return res(
|
||||||
|
ctx.status(200),
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import DataTable from "@/core/components/DataTable";
|
import DataTable from "@/core/components/DataTable";
|
||||||
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
import MuiDatePicker from "@/core/components/MuiDatePicker";
|
||||||
import {EXPERT_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {GET_EXPERTS} from "@/core/data/apiRoutes";
|
||||||
import TableToolbar from "../TableToolbar";
|
import TableToolbar from "../TableToolbar";
|
||||||
import TableRowActions from "../TableRowActions";
|
import TableRowActions from "../TableRowActions";
|
||||||
import {Box, Typography} from "@mui/material";
|
import {Box, Typography} from "@mui/material";
|
||||||
@@ -165,7 +165,7 @@ function ExpertManagementDataTable() {
|
|||||||
return (
|
return (
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTable
|
<DataTable
|
||||||
tableUrl={EXPERT_MANAGEMENT}
|
tableUrl={GET_EXPERTS}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
CustomToolbar={TableToolbar}
|
CustomToolbar={TableToolbar}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as Yup from "yup";
|
|||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {useFormik} from "formik";
|
import {useFormik} from "formik";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
import {EXPERT_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {ADD_EXPERT} from "@/core/data/apiRoutes";
|
||||||
import PersonalInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/PersonalInfo";
|
import PersonalInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/PersonalInfo";
|
||||||
import UserInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/UserInfo";
|
import UserInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/UserInfo";
|
||||||
import RestInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/RestInfo";
|
import RestInfo from "@/components/dashboard/expert-management/Form/CreateForm/CreateContent/RestInfo";
|
||||||
@@ -60,7 +60,7 @@ const CreateContent = ({setOpenCreateDialog, mutate, fetchUrl}) => {
|
|||||||
formData.append("position", values.position);
|
formData.append("position", values.position);
|
||||||
formData.append("roles", values.roles);
|
formData.append("roles", values.roles);
|
||||||
|
|
||||||
requestServer(`${EXPERT_MANAGEMENT}`, 'post', {auth: true, data: formData})
|
requestServer(`${ADD_EXPERT}`, 'post', {auth: true, data: formData})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setOpenCreateDialog(false)
|
setOpenCreateDialog(false)
|
||||||
mutate(fetchUrl)
|
mutate(fetchUrl)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import {EXPERT_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {DELETE_EXPERT} from "@/core/data/apiRoutes";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ const Delete = ({rowId, fetchUrl, mutate}) => {
|
|||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
requestServer(`${EXPERT_MANAGEMENT}/${rowId}`, 'DELETE')
|
requestServer(`${DELETE_EXPERT}/${rowId}`, 'DELETE')
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setOpenDeleteDialog(false);
|
setOpenDeleteDialog(false);
|
||||||
mutate(fetchUrl)
|
mutate(fetchUrl)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import * as Yup from "yup";
|
|||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import {useFormik} from "formik";
|
import {useFormik} from "formik";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
import {EXPERT_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {UPDATE_EXPERT} from "@/core/data/apiRoutes";
|
||||||
import PersonalInfo from "./PersonalInfo";
|
import PersonalInfo from "./PersonalInfo";
|
||||||
import UserInfo from "./UserInfo";
|
import UserInfo from "./UserInfo";
|
||||||
import RestInfo from "./RestInfo";
|
import RestInfo from "./RestInfo";
|
||||||
@@ -52,7 +52,7 @@ const UpdateContent = ({row, fetchUrl, mutate, setOpenUpdateDialog}) => {
|
|||||||
formData.append("position", values.position);
|
formData.append("position", values.position);
|
||||||
formData.append("roles", values.roles);
|
formData.append("roles", values.roles);
|
||||||
|
|
||||||
requestServer(`${EXPERT_MANAGEMENT}/${row.original.id}`, 'post', {auth: true, data: formData})
|
requestServer(`${UPDATE_EXPERT}/${row.original.id}`, 'post', {auth: true, data: formData})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
setOpenUpdateDialog(false)
|
setOpenUpdateDialog(false)
|
||||||
mutate(fetchUrl)
|
mutate(fetchUrl)
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
Checkbox, CircularProgress,
|
Checkbox,
|
||||||
|
CircularProgress,
|
||||||
DialogActions,
|
DialogActions,
|
||||||
DialogContent, DialogTitle,
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
Grid,
|
Grid,
|
||||||
Stack,
|
Stack,
|
||||||
TextField, Typography
|
TextField,
|
||||||
|
Typography
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import {useFormik} from "formik";
|
import {useFormik} from "formik";
|
||||||
import {ADD_ROLE_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {ADD_ROLE} from "@/core/data/apiRoutes";
|
||||||
import usePermissions from "@/lib/app/hooks/usePermissions";
|
import usePermissions from "@/lib/app/hooks/usePermissions";
|
||||||
|
|
||||||
const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => {
|
const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => {
|
||||||
@@ -40,7 +43,7 @@ const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => {
|
|||||||
formData.append(`permissions[${i}]`, values.permissions[i]);
|
formData.append(`permissions[${i}]`, values.permissions[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestServer(ADD_ROLE_MANAGEMENT, 'post', {
|
requestServer(ADD_ROLE, 'post', {
|
||||||
data: formData,
|
data: formData,
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
setOpenConfirmDialog(false)
|
setOpenConfirmDialog(false)
|
||||||
@@ -95,38 +98,40 @@ const CreateContent = ({mutate, fetchUrl, setOpenConfirmDialog}) => {
|
|||||||
fullWidth
|
fullWidth
|
||||||
>
|
>
|
||||||
<FormHelperText>{formik.touched.permissions && formik.errors.permissions}</FormHelperText>
|
<FormHelperText>{formik.touched.permissions && formik.errors.permissions}</FormHelperText>
|
||||||
{isLoading ?
|
{isLoading ?
|
||||||
<Stack direction={'row'} alignItems={'center'} spacing={2} justifyContent={'center'}>
|
<Stack direction={'row'} alignItems={'center'} spacing={2}
|
||||||
<CircularProgress size={20}/>
|
justifyContent={'center'}>
|
||||||
<Typography variant={'caption'}>{t("AddDialog.loading_permissions_list")}</Typography>
|
<CircularProgress size={20}/>
|
||||||
</Stack>
|
<Typography
|
||||||
:(
|
variant={'caption'}>{t("AddDialog.loading_permissions_list")}</Typography>
|
||||||
<Grid container spacing={2}>
|
</Stack>
|
||||||
<>
|
: (
|
||||||
{permissions_list.map((permission) => (
|
<Grid container spacing={2}>
|
||||||
<Grid key={permission.id} item xs={6}>
|
<>
|
||||||
<FormControlLabel
|
{permissions_list.map((permission) => (
|
||||||
control={
|
<Grid key={permission.id} item xs={6}>
|
||||||
<Checkbox
|
<FormControlLabel
|
||||||
data-testid="PermissionList-checkbox"
|
control={
|
||||||
checked={formik.values.permissions.includes(permission.id)}
|
<Checkbox
|
||||||
onChange={(e) => {
|
data-testid="PermissionList-checkbox"
|
||||||
if (e.target.checked) {
|
checked={formik.values.permissions.includes(permission.id)}
|
||||||
formik.setFieldValue("permissions", [...formik.values.permissions, permission.id])
|
onChange={(e) => {
|
||||||
} else {
|
if (e.target.checked) {
|
||||||
formik.setFieldValue("permissions", formik.values.permissions.filter((id) => id !== permission.id))
|
formik.setFieldValue("permissions", [...formik.values.permissions, permission.id])
|
||||||
}
|
} else {
|
||||||
}}
|
formik.setFieldValue("permissions", formik.values.permissions.filter((id) => id !== permission.id))
|
||||||
/>
|
}
|
||||||
}
|
}}
|
||||||
label={permission.name_fa}
|
/>
|
||||||
/>
|
}
|
||||||
</Grid>
|
label={permission.name_fa}
|
||||||
))}
|
/>
|
||||||
</>
|
</Grid>
|
||||||
</Grid>
|
))}
|
||||||
)
|
</>
|
||||||
}
|
</Grid>
|
||||||
|
)
|
||||||
|
}
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import {Button, DialogActions, DialogContent, DialogTitle, Typography} from "@mui/material";
|
import {Button, DialogActions, DialogContent, DialogTitle, Typography} from "@mui/material";
|
||||||
import {DELETE_ROLE_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {DELETE_ROLE} from "@/core/data/apiRoutes";
|
||||||
import {useState} from "react";
|
import {useState} from "react";
|
||||||
import useRequest from "@/lib/app/hooks/useRequest";
|
import useRequest from "@/lib/app/hooks/useRequest";
|
||||||
import useNotification from "@/lib/app/hooks/useNotification";
|
import useNotification from "@/lib/app/hooks/useNotification";
|
||||||
@@ -12,7 +12,7 @@ const DeleteContent = ({rowId, fetchUrl, mutate, setOpenConfirmDialog}) => {
|
|||||||
const {update_notification} = useNotification()
|
const {update_notification} = useNotification()
|
||||||
const handleSubmit = () => {
|
const handleSubmit = () => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
requestServer(`${DELETE_ROLE_MANAGEMENT}/${rowId}`, 'delete').then((response) => {
|
requestServer(`${DELETE_ROLE}/${rowId}`, 'delete').then((response) => {
|
||||||
mutate(fetchUrl)
|
mutate(fetchUrl)
|
||||||
update_notification()
|
update_notification()
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@@ -20,7 +20,7 @@ const DeleteContent = ({rowId, fetchUrl, mutate, setOpenConfirmDialog}) => {
|
|||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return(
|
return (
|
||||||
<>
|
<>
|
||||||
<DialogTitle>{t("DeleteDialog.delete")}</DialogTitle>
|
<DialogTitle>{t("DeleteDialog.delete")}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
@@ -39,4 +39,4 @@ const DeleteContent = ({rowId, fetchUrl, mutate, setOpenConfirmDialog}) => {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
export default DeleteContent
|
export default DeleteContent
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
import {
|
import {
|
||||||
Box,
|
|
||||||
Button,
|
Button,
|
||||||
Checkbox, CircularProgress, DialogActions,
|
Checkbox,
|
||||||
DialogContent, DialogTitle,
|
CircularProgress,
|
||||||
|
DialogActions,
|
||||||
|
DialogContent,
|
||||||
|
DialogTitle,
|
||||||
FormControl,
|
FormControl,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
FormHelperText,
|
FormHelperText,
|
||||||
FormLabel,
|
FormLabel,
|
||||||
Grid,
|
Grid,
|
||||||
Stack,
|
Stack,
|
||||||
TextField, Typography
|
TextField,
|
||||||
|
Typography
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {useFormik} from "formik";
|
import {useFormik} from "formik";
|
||||||
import {UPDATE_ROLE_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {UPDATE_ROLE} from "@/core/data/apiRoutes";
|
||||||
import * as Yup from "yup";
|
import * as Yup from "yup";
|
||||||
import usePermissions from "@/lib/app/hooks/usePermissions";
|
import usePermissions from "@/lib/app/hooks/usePermissions";
|
||||||
import useNotification from "@/lib/app/hooks/useNotification";
|
import useNotification from "@/lib/app/hooks/useNotification";
|
||||||
@@ -44,7 +47,7 @@ const UpdateContent = ({mutate, row, fetchUrl, setOpenConfirmDialog}) => {
|
|||||||
formData.append(`permissions[${i}]`, values.permissions[i]);
|
formData.append(`permissions[${i}]`, values.permissions[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
requestServer(`${UPDATE_ROLE_MANAGEMENT}/${row.getValue("id")}`, 'post', {
|
requestServer(`${UPDATE_ROLE}/${row.getValue("id")}`, 'post', {
|
||||||
data: formData,
|
data: formData,
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
mutate(fetchUrl)
|
mutate(fetchUrl)
|
||||||
@@ -56,7 +59,7 @@ const UpdateContent = ({mutate, row, fetchUrl, setOpenConfirmDialog}) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return(
|
return (
|
||||||
<>
|
<>
|
||||||
<DialogTitle>{t("UpdateDialog.update")}</DialogTitle>
|
<DialogTitle>{t("UpdateDialog.update")}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
@@ -96,11 +99,13 @@ const UpdateContent = ({mutate, row, fetchUrl, setOpenConfirmDialog}) => {
|
|||||||
>
|
>
|
||||||
<FormHelperText>{formik.touched.permissions && formik.errors.permissions}</FormHelperText>
|
<FormHelperText>{formik.touched.permissions && formik.errors.permissions}</FormHelperText>
|
||||||
{isLoading ?
|
{isLoading ?
|
||||||
<Stack direction={'row'} alignItems={'center'} spacing={2} justifyContent={'center'}>
|
<Stack direction={'row'} alignItems={'center'} spacing={2}
|
||||||
|
justifyContent={'center'}>
|
||||||
<CircularProgress size={20}/>
|
<CircularProgress size={20}/>
|
||||||
<Typography variant={'caption'}>{t("UpdateDialog.loading_permissions_list")}</Typography>
|
<Typography
|
||||||
|
variant={'caption'}>{t("UpdateDialog.loading_permissions_list")}</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
:(
|
: (
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
<>
|
<>
|
||||||
{permissions_list.map((permission) => (
|
{permissions_list.map((permission) => (
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import DataTable from "@/core/components/DataTable";
|
import DataTable from "@/core/components/DataTable";
|
||||||
import {GET_ROLE_MANAGEMENT} from "@/core/data/apiRoutes";
|
import {GET_ROLES} from "@/core/data/apiRoutes";
|
||||||
import TableRowActions from "@/components/dashboard/role-management/TableRowActions";
|
import TableRowActions from "@/components/dashboard/role-management/TableRowActions";
|
||||||
import {Box, Typography} from "@mui/material";
|
import {Box, Typography} from "@mui/material";
|
||||||
import {useTranslations} from "next-intl";
|
import {useTranslations} from "next-intl";
|
||||||
@@ -65,10 +65,10 @@ const RoleManagementComponent = () => {
|
|||||||
datatype: "numeric",
|
datatype: "numeric",
|
||||||
Cell: ({renderedCellValue}) => (<Typography variant="body2">{renderedCellValue}</Typography>),
|
Cell: ({renderedCellValue}) => (<Typography variant="body2">{renderedCellValue}</Typography>),
|
||||||
}], []);
|
}], []);
|
||||||
return(
|
return (
|
||||||
<Box sx={{px: 3}}>
|
<Box sx={{px: 3}}>
|
||||||
<DataTable
|
<DataTable
|
||||||
tableUrl={GET_ROLE_MANAGEMENT}
|
tableUrl={GET_ROLES}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
selectableRow={false}
|
selectableRow={false}
|
||||||
enableCustomToolbar={true}
|
enableCustomToolbar={true}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import FirstComponent from "@/components/first";
|
|||||||
import MockAppWithProviders from "../../../../mocks/AppWithProvider";
|
import MockAppWithProviders from "../../../../mocks/AppWithProvider";
|
||||||
import {server} from "../../../../mocks/server";
|
import {server} from "../../../../mocks/server";
|
||||||
import {rest} from "msw";
|
import {rest} from "msw";
|
||||||
import {GET_USER_ROUTE} from "@/core/data/apiRoutes";
|
import {GET_USER} from "@/core/data/apiRoutes";
|
||||||
|
|
||||||
describe("First Component From First Page", () => {
|
describe("First Component From First Page", () => {
|
||||||
describe("Rendering", () => {
|
describe("Rendering", () => {
|
||||||
@@ -46,7 +46,7 @@ describe("First Component From First Page", () => {
|
|||||||
});
|
});
|
||||||
it("Show Login Button And Do Not Show Dashboard Button When User Authentication Is Expired", async () => {
|
it("Show Login Button And Do Not Show Dashboard Button When User Authentication Is Expired", async () => {
|
||||||
localStorage.setItem("_token", 'token');
|
localStorage.setItem("_token", 'token');
|
||||||
server.use([rest.get(GET_USER_ROUTE, (req, res, ctx) => {
|
server.use([rest.get(GET_USER, (req, res, ctx) => {
|
||||||
return res(ctx.status(403))
|
return res(ctx.status(403))
|
||||||
})])
|
})])
|
||||||
render(<MockAppWithProviders><FirstComponent/></MockAppWithProviders>);
|
render(<MockAppWithProviders><FirstComponent/></MockAppWithProviders>);
|
||||||
|
|||||||
@@ -21,22 +21,21 @@ export const SET_USER_PASSWORD = BASE_URL + "/api/profile/change_password";
|
|||||||
//end change password
|
//end change password
|
||||||
|
|
||||||
//user data
|
//user data
|
||||||
export const GET_USER_ROUTE = BASE_URL + "/api/profile/info";
|
export const GET_USER = BASE_URL + "/api/profile/info";
|
||||||
//user data
|
//user data
|
||||||
|
|
||||||
//sidebar notification
|
//sidebar notification
|
||||||
export const GET_SIDEBAR_NOTIFICATION = BASE_URL + "/dashboard/notification"
|
export const GET_SIDEBAR_NOTIFICATION = BASE_URL + "/dashboard/notification"
|
||||||
//sidebar notification
|
//sidebar notification
|
||||||
|
|
||||||
|
|
||||||
// role management
|
// role management
|
||||||
export const GET_ROLE_MANAGEMENT =
|
export const GET_ROLES =
|
||||||
BASE_URL + "/api/roles"
|
BASE_URL + "/api/roles"
|
||||||
export const ADD_ROLE_MANAGEMENT =
|
export const ADD_ROLE =
|
||||||
BASE_URL + "/api/roles"
|
BASE_URL + "/api/roles"
|
||||||
export const UPDATE_ROLE_MANAGEMENT =
|
export const UPDATE_ROLE =
|
||||||
BASE_URL + "/api/roles"
|
BASE_URL + "/api/roles"
|
||||||
export const DELETE_ROLE_MANAGEMENT =
|
export const DELETE_ROLE =
|
||||||
BASE_URL + "/api/roles"
|
BASE_URL + "/api/roles"
|
||||||
|
|
||||||
export const GET_PERMISSIONS_LIST =
|
export const GET_PERMISSIONS_LIST =
|
||||||
@@ -44,5 +43,8 @@ export const GET_PERMISSIONS_LIST =
|
|||||||
//role management
|
//role management
|
||||||
|
|
||||||
//expert management
|
//expert management
|
||||||
export const EXPERT_MANAGEMENT = BASE_URL + "/api/users";
|
export const GET_EXPERTS = BASE_URL + "/api/users";
|
||||||
|
export const ADD_EXPERT = BASE_URL + "/api/users";
|
||||||
|
export const UPDATE_EXPERT = BASE_URL + "/api/users";
|
||||||
|
export const DELETE_EXPERT = BASE_URL + "/api/users";
|
||||||
//expert management
|
//expert management
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import {GET_USER_ROUTE} from "@/core/data/apiRoutes";
|
import {GET_USER} from "@/core/data/apiRoutes";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {createContext, useCallback, useEffect, useReducer} from "react";
|
import {createContext, useCallback, useEffect, useReducer} from "react";
|
||||||
import {errorRequest, errorResponse, errorSetting} from "@/core/utils/errorHandler";
|
import {errorRequest, errorResponse, errorSetting} from "@/core/utils/errorHandler";
|
||||||
@@ -71,7 +71,7 @@ export const UserProvider = ({children}) => {
|
|||||||
(callback = () => {
|
(callback = () => {
|
||||||
}) => {
|
}) => {
|
||||||
axios
|
axios
|
||||||
.get(GET_USER_ROUTE, {
|
.get(GET_USER, {
|
||||||
headers: {authorization: `Bearer ${state.token}`},
|
headers: {authorization: `Bearer ${state.token}`},
|
||||||
})
|
})
|
||||||
.then(({data}) => {
|
.then(({data}) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user