Commit 6a1f19b5 by tdgiang

update code

parent be49e123
......@@ -12,6 +12,10 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next'
import {
dropdownDepartment,
dropdownUserGroup,
} from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
......@@ -21,29 +25,21 @@ const ToolNotificate = (props) => {
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const [status, setStatus] = useState()
const history = useHistory()
const { t } = useTranslation()
const [data, setData] = useState([])
const [permissions, setPermissions] = useState([])
// useEffect(() => {
// getListPermission();
// }, []);
// const getListPermission = () => {
// let temp = localStorage.getItem(KEY.LISTPATH);
// let listPath = JSON.parse(temp);
// if (listPath) {
// const newlist = listPath.map((e) => {
// if (e.function_code) return e.function_code;
// return e.action_code;
// });
// setPermissions(newlist);
// }
// };
const [role, setRole] = useState()
const [listRole, setListRole] = useState([])
useEffect(() => {
getUserGroup()
}, [])
const handeChangeActive = async (id, status_id) => {
props.showLoading()
const res = await changeStatusEmployee({ id, status_id })
const res = await changeStatusEmployee({ id: id, status_id })
props.hideLoading()
if (res.data.code == 200) {
getData()
......@@ -64,6 +60,8 @@ const ToolNotificate = (props) => {
full_name: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
status,
user_group_id: role,
})
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
......@@ -87,7 +85,7 @@ const ToolNotificate = (props) => {
useEffect(() => {
getData()
}, [searchDebount, pageIndex])
}, [searchDebount, pageIndex, status, role])
const removeItem = async (id) => {
props.showLoading()
......@@ -110,6 +108,22 @@ const ToolNotificate = (props) => {
}
}
const getUserGroup = async () => {
const res = await dropdownUserGroup({})
if (res.data.code == 200 && res.data.data) {
setListRole(res.data.data)
} else if (res.data.code == 401) {
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
return (
<ToolUserView
data={data}
......@@ -124,6 +138,11 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
permissions={permissions}
status={status}
setStatus={setStatus}
role={role}
setRole={setRole}
listRole={listRole}
/>
)
}
......
......@@ -55,12 +55,12 @@ const columns = [
align: 'left',
minWidth: 'auto',
},
// {
// id: 'phone',
// label: 'Điện thoại',
// align: 'left',
// minWidth: 'auto',
// },
{
id: 'user_group_name',
label: 'Vai trò',
align: 'left',
minWidth: 'auto',
},
]
function TableList(props) {
......
......@@ -32,6 +32,11 @@ function CustomerView(props) {
pageIndex,
totalRecords,
permissions,
status,
setStatus,
role,
setRole,
listRole,
} = props
const handleChange = (event) => {
setAge(event.target.value)
......@@ -59,7 +64,16 @@ function CustomerView(props) {
container
spacing={3}
>
<Grid item lg={3} md={3} sm={6} xs={6}>
<Grid
container
spacing={3}
item
lg={8}
md={8}
sm={8}
xs={8}
>
<Grid item lg={4} md={4} sm={4} xs={4}>
<TextField
variant="outlined"
className="w-full"
......@@ -72,6 +86,66 @@ function CustomerView(props) {
}}
/>
</Grid>
<Grid item lg={4} md={4} sm={4} xs={4}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Vai trò
</InputLabel>
<Select
label="Vai trò"
value={role}
onChange={(e) => setRole(e.target.value)}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{listRole.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid item lg={4} md={4} sm={4} xs={4}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Trng thái
</InputLabel>
<Select
label="Trạng thái"
value={status}
onChange={(e) => setStatus(e.target.value)}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{[
{
id: 1,
name: 'Hoạt động',
},
{
id: 2,
name: 'Khoá',
},
].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
</Grid>
{checkRole(user, '/employee/create') ? (
<Link to="/employee/create">
<Button
......
......@@ -27,7 +27,7 @@ const SimpleForm = (props) => {
if (res.data.code == 200) {
history.push('/function')
if (res.data.code == 200) {
toast.success('Tạo hành động thành công!', {
toast.success('Tạo chức năng thành công!', {
theme: 'colored',
})
}
......
......@@ -51,7 +51,7 @@ const SimpleForm = (props) => {
if (res.data.code == 200) {
history.push('/function')
if (res.data.code == 200) {
toast.success('Cập nhật hành động thành công!', {
toast.success('Cập nhật chức năng thành công!', {
theme: 'colored',
})
}
......
......@@ -49,6 +49,7 @@ const columns = [
align: 'left',
minWidth: 'auto',
},
{
id: 'date_created',
label: 'Ngày tạo',
......@@ -56,8 +57,8 @@ const columns = [
minWidth: 'auto',
},
{
id: 'date_created',
label: 'Ngày tạo',
id: 'date_updated',
label: 'Ngày cập nhật',
align: 'left',
minWidth: 'auto',
},
......
......@@ -12,6 +12,8 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next'
import { getDropFunction } from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null)
......@@ -21,12 +23,18 @@ const ToolNotificate = (props) => {
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const [listFunction, setListFunction] = useState([])
const [function_id, setFunction] = useState()
const history = useHistory()
const [data, setData] = useState([])
const [permissions, setPermissions] = useState([])
useEffect(() => {
getDropDown()
}, [])
const handeChangeActive = async (id, status_id) => {
props.showLoading()
const res = await changeStatusAction({ id, status_id })
......@@ -49,6 +57,7 @@ const ToolNotificate = (props) => {
name: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
function_id,
})
props.hideLoading()
......@@ -75,7 +84,7 @@ const ToolNotificate = (props) => {
useEffect(() => {
getData()
}, [txtSearch, pageIndex])
}, [searchDebount, pageIndex, function_id])
const removeItem = async (id) => {
props.showLoading()
......@@ -98,6 +107,19 @@ const ToolNotificate = (props) => {
}
}
const getDropDown = async () => {
try {
const res = await getDropFunction()
console.log(res)
const newList = res.data.data.map((e) => {
return { ...e }
})
setListFunction(newList)
} catch (err) {
//toast.error(t(err))
}
}
return (
<ToolUserView
data={data}
......@@ -112,6 +134,9 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
permissions={permissions}
function_id={function_id}
setFunction={setFunction}
listFunction={listFunction}
/>
)
}
......
......@@ -36,19 +36,26 @@ const columns = [
align: 'center',
minWidth: 50,
},
{
id: 'code',
label: 'Mã code',
align: 'left',
minWidth: 'auto',
},
{
id: 'name',
label: 'Tên chức năng',
label: 'Tên hành động',
align: 'left',
minWidth: 'auto',
},
{
id: 'code',
label: 'Mã code',
id: 'function_name',
label: 'Thuộc chức năng',
align: 'left',
minWidth: 'auto',
},
{
id: 'url',
label: 'Đường dẫn',
......
......@@ -32,6 +32,9 @@ function CustomerView(props) {
pageIndex,
totalRecords,
permissions,
function_id,
setFunction,
listFunction,
} = props
const { user } = useAuth()
const handleChange = (event) => {
......@@ -61,7 +64,16 @@ function CustomerView(props) {
container
spacing={3}
>
<Grid item lg={3} md={3} sm={6} xs={6}>
<Grid
container
item
spacing={3}
lg={8}
md={8}
sm={8}
xs={8}
>
<Grid item lg={4} md={4} sm={6} xs={6}>
<TextField
variant="outlined"
className="w-full"
......@@ -74,6 +86,35 @@ function CustomerView(props) {
}}
/>
</Grid>
<Grid item lg={4} md={4} sm={6} xs={6}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Chc năng
</InputLabel>
<Select
label="Chức năng"
value={function_id}
onChange={(e) =>
setFunction(e.target.value)
}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{listFunction.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
</Grid>
{checkRole(user, '/role/create') ? (
<Link to="/role/create">
<Button
......
......@@ -47,7 +47,7 @@ const ToolNotificate = (props) => {
const getData = async () => {
props.showLoading()
const res = await getListMerchants({
name: searchDebount,
text_search: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
})
......
......@@ -119,7 +119,7 @@ const SimpleForm = (props) => {
<Grid xs={6} sm={6} item>
<SelectValidator
variant={'outlined'}
label={'Thuộc chức năng *'}
label={'Thuộc loại sản phẩm *'}
className="mb-4 w-full"
value={type_id || ''}
displayEmpty
......
......@@ -12,24 +12,31 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next'
import { dropdownProductType } from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null)
const [changeActive, setChangeActive] = useState(1)
const searchDebount = useDebounce(txtSearch, 1000)
const [status, setStatus] = useState()
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const [type, setType] = useState()
const [listType, setListType] = useState([])
const history = useHistory()
const { t } = useTranslation()
const [data, setData] = useState([])
const [permissions, setPermissions] = useState([])
useEffect(() => {
getListType()
}, [])
const handeChangeActive = async (id, status_id) => {
props.showLoading()
const res = await changeStatusProduct({ id, status_id })
const res = await changeStatusProduct({ idGuid: id, status_id })
props.hideLoading()
if (res.data.code == 200) {
getData()
......@@ -46,9 +53,11 @@ const ToolNotificate = (props) => {
const getData = async () => {
props.showLoading()
const res = await getListProduct({
name: searchDebount,
code: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
status,
type_id: type,
})
props.hideLoading()
......@@ -75,7 +84,7 @@ const ToolNotificate = (props) => {
useEffect(() => {
getData()
}, [txtSearch, pageIndex])
}, [searchDebount, pageIndex, status, type])
const removeItem = async (id) => {
props.showLoading()
......@@ -98,6 +107,21 @@ const ToolNotificate = (props) => {
}
}
const getListType = async () => {
const res = await dropdownProductType({})
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.map((e) => {
return { name: e.type_name, value: e.id, ...e }
})
setListType(newList)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
return (
<ToolUserView
data={data}
......@@ -112,6 +136,11 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
permissions={permissions}
status={status}
setStatus={setStatus}
listType={listType}
type={type}
setType={setType}
/>
)
}
......
......@@ -127,7 +127,7 @@ const SimpleForm = (props) => {
<Grid xs={6} sm={6} item>
<SelectValidator
variant={'outlined'}
label={'Thuộc chức năng *'}
label={'Thuộc loại sản phẩm *'}
className="mb-4 w-full"
value={type_id || ''}
disabled
......
......@@ -32,6 +32,11 @@ function CustomerView(props) {
pageIndex,
totalRecords,
permissions,
status,
setStatus,
listType,
type,
setType,
} = props
const { user } = useAuth()
const handleChange = (event) => {
......@@ -61,11 +66,20 @@ function CustomerView(props) {
container
spacing={3}
>
<Grid item lg={3} md={3} sm={6} xs={6}>
<Grid
container
spacing={3}
item
lg={8}
md={8}
sm={8}
xs={8}
>
<Grid item lg={4} md={4} sm={4} xs={4}>
<TextField
variant="outlined"
className="w-full"
label="Tên sản phẩm"
label="Tìm kiếm"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
......@@ -74,6 +88,68 @@ function CustomerView(props) {
}}
/>
</Grid>
<Grid item lg={4} md={4} sm={4} xs={4}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Loi sn phm
</InputLabel>
<Select
label="Loại sản phẩm"
value={type}
onChange={(e) => setType(e.target.value)}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{listType.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
<Grid item lg={4} md={4} sm={4} xs={4}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Trng thái
</InputLabel>
<Select
label="Trạng thái"
value={status}
onChange={(e) => setStatus(e.target.value)}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{[
{
id: 1,
name: 'Hoạt động',
},
{
id: 2,
name: 'Khoá',
},
].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
</Grid>
{checkRole(user, '/product/create') ? (
<Link to="/product/create">
<Button
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment