Commit 6a1f19b5 by tdgiang

update code

parent be49e123
...@@ -12,6 +12,10 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction' ...@@ -12,6 +12,10 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce' import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import {
dropdownDepartment,
dropdownUserGroup,
} from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => { const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('') const [txtSearch, setTxtSearch] = useState('')
...@@ -21,29 +25,21 @@ const ToolNotificate = (props) => { ...@@ -21,29 +25,21 @@ const ToolNotificate = (props) => {
const [pageIndex, setPageIndex] = useState(0) const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10) const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0) const [totalRecords, setTotalRecord] = useState(0)
const [status, setStatus] = useState()
const history = useHistory() const history = useHistory()
const { t } = useTranslation() const { t } = useTranslation()
const [data, setData] = useState([]) const [data, setData] = useState([])
const [permissions, setPermissions] = useState([]) const [permissions, setPermissions] = useState([])
// useEffect(() => { const [role, setRole] = useState()
// getListPermission(); const [listRole, setListRole] = useState([])
// }, []);
// const getListPermission = () => { useEffect(() => {
// let temp = localStorage.getItem(KEY.LISTPATH); getUserGroup()
// 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 handeChangeActive = async (id, status_id) => { const handeChangeActive = async (id, status_id) => {
props.showLoading() props.showLoading()
const res = await changeStatusEmployee({ id, status_id }) const res = await changeStatusEmployee({ id: id, status_id })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { if (res.data.code == 200) {
getData() getData()
...@@ -64,6 +60,8 @@ const ToolNotificate = (props) => { ...@@ -64,6 +60,8 @@ const ToolNotificate = (props) => {
full_name: searchDebount, full_name: searchDebount,
page_no: pageIndex + 1, page_no: pageIndex + 1,
page_size: pageSize, page_size: pageSize,
status,
user_group_id: role,
}) })
props.hideLoading() props.hideLoading()
if (res.data.code == 200 && res.data.data) { if (res.data.code == 200 && res.data.data) {
...@@ -87,7 +85,7 @@ const ToolNotificate = (props) => { ...@@ -87,7 +85,7 @@ const ToolNotificate = (props) => {
useEffect(() => { useEffect(() => {
getData() getData()
}, [searchDebount, pageIndex]) }, [searchDebount, pageIndex, status, role])
const removeItem = async (id) => { const removeItem = async (id) => {
props.showLoading() props.showLoading()
...@@ -110,6 +108,22 @@ const ToolNotificate = (props) => { ...@@ -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 ( return (
<ToolUserView <ToolUserView
data={data} data={data}
...@@ -124,6 +138,11 @@ const ToolNotificate = (props) => { ...@@ -124,6 +138,11 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive} handeChangeActive={handeChangeActive}
totalRecords={totalRecords} totalRecords={totalRecords}
permissions={permissions} permissions={permissions}
status={status}
setStatus={setStatus}
role={role}
setRole={setRole}
listRole={listRole}
/> />
) )
} }
......
...@@ -55,12 +55,12 @@ const columns = [ ...@@ -55,12 +55,12 @@ const columns = [
align: 'left', align: 'left',
minWidth: 'auto', minWidth: 'auto',
}, },
// { {
// id: 'phone', id: 'user_group_name',
// label: 'Điện thoại', label: 'Vai trò',
// align: 'left', align: 'left',
// minWidth: 'auto', minWidth: 'auto',
// }, },
] ]
function TableList(props) { function TableList(props) {
......
...@@ -32,6 +32,11 @@ function CustomerView(props) { ...@@ -32,6 +32,11 @@ function CustomerView(props) {
pageIndex, pageIndex,
totalRecords, totalRecords,
permissions, permissions,
status,
setStatus,
role,
setRole,
listRole,
} = props } = props
const handleChange = (event) => { const handleChange = (event) => {
setAge(event.target.value) setAge(event.target.value)
...@@ -59,18 +64,87 @@ function CustomerView(props) { ...@@ -59,18 +64,87 @@ function CustomerView(props) {
container container
spacing={3} spacing={3}
> >
<Grid item lg={3} md={3} sm={6} xs={6}> <Grid
<TextField container
variant="outlined" spacing={3}
className="w-full" item
label="Tên thành viên" lg={8}
onChange={(e) => { md={8}
const text = e.target.value sm={8}
setTimeout(() => { xs={8}
setTxtSearch(text) >
}, 1000) <Grid item lg={4} md={4} sm={4} xs={4}>
}} <TextField
/> variant="outlined"
className="w-full"
label="Tên thành viên"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</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> </Grid>
{checkRole(user, '/employee/create') ? ( {checkRole(user, '/employee/create') ? (
<Link to="/employee/create"> <Link to="/employee/create">
......
...@@ -27,7 +27,7 @@ const SimpleForm = (props) => { ...@@ -27,7 +27,7 @@ const SimpleForm = (props) => {
if (res.data.code == 200) { if (res.data.code == 200) {
history.push('/function') history.push('/function')
if (res.data.code == 200) { 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', theme: 'colored',
}) })
} }
......
...@@ -51,7 +51,7 @@ const SimpleForm = (props) => { ...@@ -51,7 +51,7 @@ const SimpleForm = (props) => {
if (res.data.code == 200) { if (res.data.code == 200) {
history.push('/function') history.push('/function')
if (res.data.code == 200) { 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', theme: 'colored',
}) })
} }
......
...@@ -49,6 +49,7 @@ const columns = [ ...@@ -49,6 +49,7 @@ const columns = [
align: 'left', align: 'left',
minWidth: 'auto', minWidth: 'auto',
}, },
{ {
id: 'date_created', id: 'date_created',
label: 'Ngày tạo', label: 'Ngày tạo',
...@@ -56,8 +57,8 @@ const columns = [ ...@@ -56,8 +57,8 @@ const columns = [
minWidth: 'auto', minWidth: 'auto',
}, },
{ {
id: 'date_created', id: 'date_updated',
label: 'Ngày tạo', label: 'Ngày cập nhật',
align: 'left', align: 'left',
minWidth: 'auto', minWidth: 'auto',
}, },
......
...@@ -12,6 +12,8 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction' ...@@ -12,6 +12,8 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce' import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { getDropFunction } from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => { const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('') const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null) const [activeSelected, setActiveSeleted] = useState(null)
...@@ -21,12 +23,18 @@ const ToolNotificate = (props) => { ...@@ -21,12 +23,18 @@ const ToolNotificate = (props) => {
const [pageIndex, setPageIndex] = useState(0) const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10) const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0) const [totalRecords, setTotalRecord] = useState(0)
const [listFunction, setListFunction] = useState([])
const [function_id, setFunction] = useState()
const history = useHistory() const history = useHistory()
const [data, setData] = useState([]) const [data, setData] = useState([])
const [permissions, setPermissions] = useState([]) const [permissions, setPermissions] = useState([])
useEffect(() => {
getDropDown()
}, [])
const handeChangeActive = async (id, status_id) => { const handeChangeActive = async (id, status_id) => {
props.showLoading() props.showLoading()
const res = await changeStatusAction({ id, status_id }) const res = await changeStatusAction({ id, status_id })
...@@ -49,6 +57,7 @@ const ToolNotificate = (props) => { ...@@ -49,6 +57,7 @@ const ToolNotificate = (props) => {
name: searchDebount, name: searchDebount,
page_no: pageIndex + 1, page_no: pageIndex + 1,
page_size: pageSize, page_size: pageSize,
function_id,
}) })
props.hideLoading() props.hideLoading()
...@@ -75,7 +84,7 @@ const ToolNotificate = (props) => { ...@@ -75,7 +84,7 @@ const ToolNotificate = (props) => {
useEffect(() => { useEffect(() => {
getData() getData()
}, [txtSearch, pageIndex]) }, [searchDebount, pageIndex, function_id])
const removeItem = async (id) => { const removeItem = async (id) => {
props.showLoading() props.showLoading()
...@@ -98,6 +107,19 @@ const ToolNotificate = (props) => { ...@@ -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 ( return (
<ToolUserView <ToolUserView
data={data} data={data}
...@@ -112,6 +134,9 @@ const ToolNotificate = (props) => { ...@@ -112,6 +134,9 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive} handeChangeActive={handeChangeActive}
totalRecords={totalRecords} totalRecords={totalRecords}
permissions={permissions} permissions={permissions}
function_id={function_id}
setFunction={setFunction}
listFunction={listFunction}
/> />
) )
} }
......
...@@ -36,19 +36,26 @@ const columns = [ ...@@ -36,19 +36,26 @@ const columns = [
align: 'center', align: 'center',
minWidth: 50, minWidth: 50,
}, },
{
id: 'code',
label: 'Mã code',
align: 'left',
minWidth: 'auto',
},
{ {
id: 'name', id: 'name',
label: 'Tên chức năng', label: 'Tên hành động',
align: 'left', align: 'left',
minWidth: 'auto', minWidth: 'auto',
}, },
{ {
id: 'code', id: 'function_name',
label: 'Mã code', label: 'Thuộc chức năng',
align: 'left', align: 'left',
minWidth: 'auto', minWidth: 'auto',
}, },
{ {
id: 'url', id: 'url',
label: 'Đường dẫn', label: 'Đường dẫn',
......
...@@ -32,6 +32,9 @@ function CustomerView(props) { ...@@ -32,6 +32,9 @@ function CustomerView(props) {
pageIndex, pageIndex,
totalRecords, totalRecords,
permissions, permissions,
function_id,
setFunction,
listFunction,
} = props } = props
const { user } = useAuth() const { user } = useAuth()
const handleChange = (event) => { const handleChange = (event) => {
...@@ -61,18 +64,56 @@ function CustomerView(props) { ...@@ -61,18 +64,56 @@ function CustomerView(props) {
container container
spacing={3} spacing={3}
> >
<Grid item lg={3} md={3} sm={6} xs={6}> <Grid
<TextField container
variant="outlined" item
className="w-full" spacing={3}
label="Tên hành động" lg={8}
onChange={(e) => { md={8}
const text = e.target.value sm={8}
setTimeout(() => { xs={8}
setTxtSearch(text) >
}, 1000) <Grid item lg={4} md={4} sm={6} xs={6}>
}} <TextField
/> variant="outlined"
className="w-full"
label="Tên hành động"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</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> </Grid>
{checkRole(user, '/role/create') ? ( {checkRole(user, '/role/create') ? (
<Link to="/role/create"> <Link to="/role/create">
......
...@@ -47,7 +47,7 @@ const ToolNotificate = (props) => { ...@@ -47,7 +47,7 @@ const ToolNotificate = (props) => {
const getData = async () => { const getData = async () => {
props.showLoading() props.showLoading()
const res = await getListMerchants({ const res = await getListMerchants({
name: searchDebount, text_search: searchDebount,
page_no: pageIndex + 1, page_no: pageIndex + 1,
page_size: pageSize, page_size: pageSize,
}) })
......
...@@ -119,7 +119,7 @@ const SimpleForm = (props) => { ...@@ -119,7 +119,7 @@ const SimpleForm = (props) => {
<Grid xs={6} sm={6} item> <Grid xs={6} sm={6} item>
<SelectValidator <SelectValidator
variant={'outlined'} variant={'outlined'}
label={'Thuộc chức năng *'} label={'Thuộc loại sản phẩm *'}
className="mb-4 w-full" className="mb-4 w-full"
value={type_id || ''} value={type_id || ''}
displayEmpty displayEmpty
......
...@@ -12,24 +12,31 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction' ...@@ -12,24 +12,31 @@ import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce' import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { dropdownProductType } from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => { const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('') const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null) const [activeSelected, setActiveSeleted] = useState(null)
const [changeActive, setChangeActive] = useState(1) const [changeActive, setChangeActive] = useState(1)
const searchDebount = useDebounce(txtSearch, 1000) const searchDebount = useDebounce(txtSearch, 1000)
const [status, setStatus] = useState()
const [pageIndex, setPageIndex] = useState(0) const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10) const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0) const [totalRecords, setTotalRecord] = useState(0)
const [type, setType] = useState()
const [listType, setListType] = useState([])
const history = useHistory() const history = useHistory()
const { t } = useTranslation() const { t } = useTranslation()
const [data, setData] = useState([]) const [data, setData] = useState([])
const [permissions, setPermissions] = useState([]) const [permissions, setPermissions] = useState([])
useEffect(() => {
getListType()
}, [])
const handeChangeActive = async (id, status_id) => { const handeChangeActive = async (id, status_id) => {
props.showLoading() props.showLoading()
const res = await changeStatusProduct({ id, status_id }) const res = await changeStatusProduct({ idGuid: id, status_id })
props.hideLoading() props.hideLoading()
if (res.data.code == 200) { if (res.data.code == 200) {
getData() getData()
...@@ -46,9 +53,11 @@ const ToolNotificate = (props) => { ...@@ -46,9 +53,11 @@ const ToolNotificate = (props) => {
const getData = async () => { const getData = async () => {
props.showLoading() props.showLoading()
const res = await getListProduct({ const res = await getListProduct({
name: searchDebount, code: searchDebount,
page_no: pageIndex + 1, page_no: pageIndex + 1,
page_size: pageSize, page_size: pageSize,
status,
type_id: type,
}) })
props.hideLoading() props.hideLoading()
...@@ -75,7 +84,7 @@ const ToolNotificate = (props) => { ...@@ -75,7 +84,7 @@ const ToolNotificate = (props) => {
useEffect(() => { useEffect(() => {
getData() getData()
}, [txtSearch, pageIndex]) }, [searchDebount, pageIndex, status, type])
const removeItem = async (id) => { const removeItem = async (id) => {
props.showLoading() props.showLoading()
...@@ -98,6 +107,21 @@ const ToolNotificate = (props) => { ...@@ -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 ( return (
<ToolUserView <ToolUserView
data={data} data={data}
...@@ -112,6 +136,11 @@ const ToolNotificate = (props) => { ...@@ -112,6 +136,11 @@ const ToolNotificate = (props) => {
handeChangeActive={handeChangeActive} handeChangeActive={handeChangeActive}
totalRecords={totalRecords} totalRecords={totalRecords}
permissions={permissions} permissions={permissions}
status={status}
setStatus={setStatus}
listType={listType}
type={type}
setType={setType}
/> />
) )
} }
......
...@@ -127,7 +127,7 @@ const SimpleForm = (props) => { ...@@ -127,7 +127,7 @@ const SimpleForm = (props) => {
<Grid xs={6} sm={6} item> <Grid xs={6} sm={6} item>
<SelectValidator <SelectValidator
variant={'outlined'} variant={'outlined'}
label={'Thuộc chức năng *'} label={'Thuộc loại sản phẩm *'}
className="mb-4 w-full" className="mb-4 w-full"
value={type_id || ''} value={type_id || ''}
disabled disabled
......
...@@ -32,6 +32,11 @@ function CustomerView(props) { ...@@ -32,6 +32,11 @@ function CustomerView(props) {
pageIndex, pageIndex,
totalRecords, totalRecords,
permissions, permissions,
status,
setStatus,
listType,
type,
setType,
} = props } = props
const { user } = useAuth() const { user } = useAuth()
const handleChange = (event) => { const handleChange = (event) => {
...@@ -61,19 +66,90 @@ function CustomerView(props) { ...@@ -61,19 +66,90 @@ function CustomerView(props) {
container container
spacing={3} spacing={3}
> >
<Grid item lg={3} md={3} sm={6} xs={6}> <Grid
<TextField container
variant="outlined" spacing={3}
className="w-full" item
label="Tên sản phẩm" lg={8}
onChange={(e) => { md={8}
const text = e.target.value sm={8}
setTimeout(() => { xs={8}
setTxtSearch(text) >
}, 1000) <Grid item lg={4} md={4} sm={4} xs={4}>
}} <TextField
/> variant="outlined"
className="w-full"
label="Tìm kiếm"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</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> </Grid>
{checkRole(user, '/product/create') ? ( {checkRole(user, '/product/create') ? (
<Link to="/product/create"> <Link to="/product/create">
<Button <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