Commit b43ab868 by tdgiang

update code

parent 1ca9425a
......@@ -19,6 +19,8 @@ import ListRequestRoutes from './views/ListRequest/routes'
import SignUp from './views/SignUp/routes'
import InvoiceSupplier from './views/InvoiceSupplier/routes'
import Package from './views/package/routers'
import NccRouter from './views/Ncc/router'
import LandingpageRouter from './views/landingpage/router'
const redirectRoute = [
{
......@@ -35,6 +37,8 @@ const errorRoute = [
]
const routes = [
...LandingpageRouter,
...NccRouter,
...Package,
...InvoiceSupplier,
...SignUp,
......
/* eslint-disable handle-callback-err */
import { PostData, GetURL } from '../helpers'
import url from '../url'
export const getListPackageFunction = async (body) =>
PostData(url.urlGetListPackageFunction, body)
.then((res) => res)
.catch((err) => null)
export const createPackageFunction = async (body) =>
PostData(url.urlCreatePackageFunction, body)
.then((res) => res)
.catch((err) => null)
export const updatePackageFunction = async (body) =>
PostData(url.urlUpdatePackageFunction, body)
.then((res) => res)
.catch((err) => null)
export const detailPackageFunction = async (id, body) =>
GetURL(`${url.urlDetailPackageFunction}/${id}`, body)
.then((res) => res)
.catch((err) => null)
export const deletePackageFunction = async (body) =>
PostData(url.urlDeletePackageFunction, body)
.then((res) => res)
.catch((err) => null)
export const changeStatusPackageFunction = async (body) =>
PostData(url.changeStatusPackageFunction, body)
.then((res) => res)
.catch((err) => null)
/* eslint-disable handle-callback-err */
import { PostData, GetURL } from '../helpers'
import url from '../url'
export const getListSupplier = async (body) =>
PostData(url.urlGetListSupplier, body)
.then((res) => res)
.catch((err) => null)
export const createSupplier = async (body) =>
PostData(url.urlCreateSupplier, body)
.then((res) => res)
.catch((err) => null)
export const updateSupplier = async (body) =>
PostData(url.urlUpdateSupplier, body)
.then((res) => res)
.catch((err) => null)
export const detailSupplier = async (id, body) =>
GetURL(`${url.urlDetailSupplier}/${id}`, body)
.then((res) => res)
.catch((err) => null)
export const deleteSupplier = async (body) =>
PostData(url.urlDeleteSupplier, body)
.then((res) => res)
.catch((err) => null)
export const changeStatusSupplier = async (body) =>
PostData(url.changeStatusSupplier, body)
.then((res) => res)
.catch((err) => null)
......@@ -95,6 +95,14 @@ export default {
urlDetailInvoiceSupp: `${root}/supplierInvoice`,
changeStatusInvoiceSupp: `${root}/supplierInvoice/changeStatus`,
//supplier
urlGetListSupplier: `${root}/supplierconstruction/paging`,
urlCreateSupplier: `${root}/supplierconstruction/create`,
urlUpdateSupplier: `${root}/supplierconstruction/update`,
urlDeleteSupplier: `${root}/supplierconstruction/delete`,
urlDetailSupplier: `${root}/supplierconstruction`,
changeStatusSupplier: `${root}/supplierconstruction/changeStatus`,
//Log
logAuth: `${root}/logging/listLogin`,
logApi: `${root}/logging/listCallApi`,
......@@ -108,6 +116,28 @@ export default {
updateStatusRequest: `${root}/customerCare/changeStatus`,
detailCustomerCare: `${root}/customerCare`,
//landingpage
urlGetListPackage: `${root}/package/list`,
urlCreatePackage: `${root}/package/create`,
urlUpdatePackage: `${root}/package/update`,
urlDeletePackage: `${root}/package/delete`,
urlDetailPackage: `${root}/package`,
changeStatusPackage: `${root}/package/changeStatus`,
urlGetListPackageFunction: `${root}/functionpk/paging`,
urlCreatePackageFunction: `${root}/functionpk/create`,
urlUpdatePackageFunction: `${root}/functionpk/update`,
urlDeletePackageFunction: `${root}/functionpk/delete`,
urlDetailPackageFunction: `${root}/functionpk`,
changeStatusPackageFunction: `${root}/functionpk/changeStatus`,
urlGetListPriceProduct: `${root}/construction/list`,
urlCreatePriceProduct: `${root}/construction/create`,
urlUpdatePriceProduct: `${root}/construction/update`,
urlDeletePriceProduct: `${root}/construction/delete`,
urlDetailPriceProduct: `${root}/construction`,
changeStatusPriceProduct: `${root}/construction/changeStatus`,
//dropdown
dropdownFuntions: `${root}/dropdown/function`,
dropdownPermission: `${root}/function/getFunctionTree`,
......
......@@ -276,6 +276,13 @@ export const navigationsAdmin = [
hide: false,
id: 'GROUP_ROLE',
},
{
name: 'NCC thiết bị',
iconText: 'IV',
path: '/ncc',
hide: false,
id: 'INVOICE',
},
{
name: 'NCC hoá đơn',
......
import React, { useState, useEffect } from 'react'
import {
ValidatorForm,
TextValidator,
SelectValidator,
} from 'react-material-ui-form-validator'
import {
Button,
Grid,
MenuItem,
FormControlLabel,
Checkbox,
Typography,
} from '@material-ui/core'
import { createFunction } from 'app/apis/Functions/function'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components'
import { Link, useHistory, useLocation } from 'react-router-dom'
import { trimObject, encryString, convertDate } from 'app/config/Function'
import { connect } from 'react-redux'
import { KeyboardDatePicker } from '@material-ui/pickers'
import {
dropdownDepartment,
dropdownUserGroup,
dropdownStore,
} from 'app/apis/Functions/dropdown'
import PickerImage from 'app/components/Input/PickerImage'
import { createSupplier } from 'app/apis/Functions/supplier'
import { useTranslation } from 'react-i18next'
import useAuth from 'app/hooks/useAuth'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const [listDrop, setListDrop] = useState([])
const [listAction, setListAction] = useState([])
const { user } = useAuth()
const { t } = useTranslation()
console.log('user', user)
const history = useHistory()
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await createSupplier({
...newValue,
status: 1,
})
console.log(res)
props.hideLoading()
if (res.data.code == 200) {
history.push('/ncc')
if (res.data.code == 200) {
toast.success('Tạo nhân viên thành công!', {
theme: 'colored',
})
}
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const { supp_code, supp_name, phone, email, address } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách nhà cung cấp thiết bị',
path: '/ncc',
},
{ name: 'Thêm mới' },
]}
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<Grid container spacing={3}>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mã nhà cung cấp *"
onChange={handleChange}
type="text"
name="supp_code"
value={supp_code || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Tên nhà cung cấp *"
onChange={handleChange}
type="text"
name="supp_name"
value={supp_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Số điện thoại *"
onChange={handleChange}
type="text"
name="phone"
value={phone || ''}
validators={[
'required',
'isNumber',
'minStringLength:10',
'maxStringLength:15',
]}
errorMessages={[
'Không được để trống trường này',
'Trường này phải nhập số ',
'Số điện thoại phải có ít nhất 10 chữ số',
'Số điện thoại nhiều nhất chỉ có 15 chữ số',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Email *"
onChange={handleChange}
type="text"
name="email"
value={email || ''}
validators={['required', 'isEmail']}
errorMessages={[
'Không được để trống trường này',
'Email không hợp lệ',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Địa chỉ"
onChange={handleChange}
type="text"
name="address"
value={address || ''}
/>
</Grid>
</Grid>
<Grid container justify={'flex-end'}>
<Link to="/ncc">
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {}}
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
type="submit"
>
<span className="capitalize">Thêm mi</span>
</Button>
</Grid>
</ValidatorForm>
</SimpleCard>
</div>
</div>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
SimpleForm
)
import React, { useState, useEffect } from 'react'
import ToolUserView from './View'
import {
getListSupplier,
deleteSupplier,
changeStatusSupplier,
} from 'app/apis/Functions/supplier'
import { useHistory } from 'react-router-dom'
import KEY from 'app/assets/Key'
import { connect } from 'react-redux'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import useAuth from 'app/hooks/useAuth'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null)
const [changeActive, setChangeActive] = useState(1)
const searchDebount = useDebounce(txtSearch, 1000)
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const [status, setStatus] = useState()
const [listDrop, setListDrop] = useState([])
const [store, setStore] = useState()
const history = useHistory()
const [listGroup, setListGroup] = useState([])
const [group, setGroup] = useState()
const { user } = useAuth()
const [data, setData] = useState([])
const handeChangeActive = async (idGuid, status_id) => {
props.showLoading()
const res = await changeStatusSupplier({ idGuid, status_id })
props.hideLoading()
if (res.data.code == 200) {
getData()
toast.success('Thay đổi trạng thái thành công!', {
theme: 'colored',
})
} else {
toast.error('Thay đổi trạng thái thất bại!', {
theme: 'colored',
})
}
}
console.log('user', user)
const getData = async (isInit) => {
props.showLoading()
let res
if (isInit) {
setPageIndex(0)
res = await getListSupplier({
fuel_name: searchDebount,
page_no: 0,
page_size: pageSize,
status,
})
} else {
res = await getListSupplier({
fuel_name: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
status,
})
}
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.data.map((e, i) => {
return { ...e, index: i + 1 + pageIndex * pageSize }
})
setData(newList)
setTotalRecord(res.data.data.total_elements)
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
// enqueueSnackbar('Error!', { variant: 'error' })
}
}
useEffect(() => {
getData(false)
}, [pageIndex])
useEffect(() => {
getData(true)
}, [searchDebount, status, store, group])
const removeItem = async (idGuid) => {
props.showLoading()
const res = await deleteSupplier({ idGuid })
props.hideLoading()
if (res.data.code == 200) {
getData(true)
toast.success('Xoá bản ghi thành công!', {
theme: 'colored',
})
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error('Xoá bản ghi thất bại!', {
theme: 'colored',
})
}
}
return (
<ToolUserView
data={data}
removeItem={removeItem}
setTxtSearch={setTxtSearch}
setActiveSeleted={setActiveSeleted}
pageIndex={pageIndex}
changeActive={changeActive}
setChangeActive={setChangeActive}
setPageIndex={setPageIndex}
activeSelected={activeSelected}
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
status={status}
setStatus={setStatus}
listDrop={listDrop}
store={store}
setStore={setStore}
listGroup={listGroup}
group={group}
setGroup={setGroup}
/>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
ToolNotificate
)
import React, { useState, useEffect } from 'react'
import {
ValidatorForm,
TextValidator,
SelectValidator,
} from 'react-material-ui-form-validator'
import {
Button,
Grid,
MenuItem,
FormControlLabel,
Checkbox,
Typography,
} from '@material-ui/core'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components'
import { Link, useHistory, useLocation } from 'react-router-dom'
import {
trimObject,
encryString,
convertDate,
convertTimeApi,
} from 'app/config/Function'
import { connect } from 'react-redux'
import { detailSupplier, updateSupplier } from 'app/apis/Functions/supplier'
import { useTranslation } from 'react-i18next'
import useAuth from 'app/hooks/useAuth'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const location = useLocation()
const [image, setImage] = useState()
const { user } = useAuth()
const [date, setDate] = useState(null)
const { t } = useTranslation()
useEffect(() => {
getDataDefault()
}, [])
const history = useHistory()
const getDataDefault = async () => {
props.showLoading()
try {
const res = await detailSupplier(location.state, {})
setState(res.data.data)
} catch (err) {
toast.error(t(err), {
theme: 'colored',
})
}
props.hideLoading()
}
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await updateSupplier({
...newValue,
})
console.log(res)
props.hideLoading()
if (res.data.code == 200) {
history.push('/ncc')
if (res.data.code == 200) {
toast.success('Cập nhật nhân viên thành công!', {
theme: 'colored',
})
}
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const { supp_code, supp_name, phone, email, address } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách nhà cung cấp thiết bị',
path: '/ncc',
},
{ name: 'Cập nhật' },
]}
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<Grid container spacing={3}>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mã nhà cung cấp *"
onChange={handleChange}
type="text"
name="supp_code"
disabled={true}
value={supp_code || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Tên nhà cung cấp *"
onChange={handleChange}
type="text"
name="supp_name"
value={supp_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Số điện thoại *"
onChange={handleChange}
type="text"
name="phone"
value={phone || ''}
validators={[
'required',
'isNumber',
'minStringLength:10',
'maxStringLength:15',
]}
errorMessages={[
'Không được để trống trường này',
'Trường này phải nhập số ',
'Số điện thoại phải có ít nhất 10 chữ số',
'Số điện thoại nhiều nhất chỉ có 15 chữ số',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Email *"
onChange={handleChange}
type="text"
name="email"
value={email || ''}
validators={['required', 'isEmail']}
errorMessages={[
'Không được để trống trường này',
'Email không hợp lệ',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Địa chỉ"
onChange={handleChange}
type="text"
name="address"
value={address || ''}
/>
</Grid>
</Grid>
<Grid
style={{ marginTop: 20 }}
container
justify={'flex-end'}
>
<Link to="/ncc">
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {}}
>
<span className="capitalize">Quay li</span>
</Button>
</Link>
<Button
color="primary"
variant="contained"
type="submit"
>
<span className="capitalize">Cp nht</span>
</Button>
</Grid>
</ValidatorForm>
</SimpleCard>
</div>
</div>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
SimpleForm
)
import React, { Fragment, useState, useEffect } from 'react'
import {
TextField,
Icon,
Button,
StepLabel,
Step,
Stepper,
Grid,
FormControl,
InputLabel,
Select,
MenuItem,
} from '@material-ui/core'
import Table from './Table'
import { Breadcrumb } from 'app/components'
import { Link } from 'react-router-dom'
import { Autocomplete, createFilterOptions } from '@material-ui/lab'
import useAuth from 'app/hooks/useAuth'
import { checkRole } from 'app/config/Function'
function CustomerView(props) {
const [age, setAge] = React.useState('')
const {
data,
updateItem,
removeItem,
setTxtSearch,
changeActive,
setChangeActive,
handeChangeActive,
setPageIndex,
pageIndex,
totalRecords,
status,
setStatus,
store,
setStore,
listDrop,
listGroup,
group,
setGroup,
} = props
const handleChange = (event) => {
setAge(event.target.value)
}
const { user } = useAuth()
return (
<Fragment>
<div className="m-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{ name: 'Danh sách nhà cung cấp', path: '/ncc' },
]}
/>
</div>
<Grid
style={{
padding: 10,
marginBottom: 20,
}}
justify={'space-between'}
alignItems={'center'}
container
spacing={3}
>
<Grid
spacing={3}
container
item
lg={8}
md={8}
sm={8}
xs={8}
>
<Grid item lg={3} md={3} sm={3} xs={3}>
<TextField
variant="outlined"
className="w-full"
label="Nhập từ khoá"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</Grid>
<Grid item lg={3} md={3} sm={3} xs={3}>
<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, '/ncc/create') ? (
<Link to="/ncc/create">
<Button
variant="contained"
className={'bg-light-primary'}
>
<span className={'text-primary'}>Thêm mi</span>
</Button>
</Link>
) : null}
</Grid>
<Table
data={data}
changeActive={changeActive}
setChangeActive={setChangeActive}
handeChangeActive={handeChangeActive}
updateItem={updateItem}
removeItem={removeItem}
pageIndex={pageIndex}
setPageIndex={setPageIndex}
totalRecords={totalRecords}
/>
</div>
</Fragment>
)
}
export default CustomerView
import React from 'react'
const Routes = [
{
path: '/ncc/create',
component: React.lazy(() => import('./Create')),
},
{
path: '/ncc/update',
component: React.lazy(() => import('./Update')),
},
{
path: '/ncc',
component: React.lazy(() => import('./Index')),
},
]
export default Routes
import React, { useState, useEffect } from 'react'
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator'
import { Button, Grid } from '@material-ui/core'
import { createPackageFunction } from 'app/apis/Functions/landingpage'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components'
import { Link, useHistory, useLocation } from 'react-router-dom'
import { trimObject } from 'app/config/Function'
import { connect } from 'react-redux'
import { useTranslation } from 'react-i18next'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const { t } = useTranslation()
const history = useHistory()
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await createPackageFunction({
...newValue,
status: 1,
})
props.hideLoading()
if (res.data.code == 200) {
history.push('/package-function')
if (res.data.code == 200) {
toast.success('Tạo chức năng gói thành công!', {
theme: 'colored',
})
}
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const handleDateChange = (date) => {
setState({ ...state, date })
}
const { description, func_name } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách chức năng gói',
path: '/package-function',
},
{ name: 'Thêm mới' },
]}
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<Grid container spacing={3}>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Tên chức năng *"
onChange={handleChange}
type="text"
name="func_name"
value={func_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mô tả"
onChange={handleChange}
type="text"
name="description"
value={description || ''}
// validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
</Grid>
<Grid container justify={'flex-end'}>
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {
history.goBack()
}}
>
<span className="capitalize">Quay li</span>
</Button>
<Button
color="primary"
variant="contained"
type="submit"
>
<span className="capitalize">Thêm mi</span>
</Button>
</Grid>
</ValidatorForm>
</SimpleCard>
</div>
</div>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
SimpleForm
)
import React, { useState, useEffect } from 'react'
import ToolUserView from './View'
import {
getListPackageFunction,
deletePackageFunction,
changeStatusPackageFunction,
} from 'app/apis/Functions/landingpage'
import { useHistory } from 'react-router-dom'
import KEY from '../../../assets/Key'
import { connect } from 'react-redux'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const searchDebount = useDebounce(txtSearch, 1000)
const { t } = useTranslation()
const [activeSelected, setActiveSeleted] = useState(null)
const [changeActive, setChangeActive] = useState(1)
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const history = useHistory()
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 handeChangeActive = async (id, status_id) => {
props.showLoading()
const res = await changeStatusPackageFunction({ idGuid: id, status_id })
props.hideLoading()
if (res.data.code == 200) {
getData()
toast.success('Thay đổi trạng thái thành công!', {
theme: 'colored',
})
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const getData = async (isInit) => {
props.showLoading()
let res
if (isInit) {
setPageIndex(0)
res = await getListPackageFunction({
func_name: searchDebount,
page_no: 0,
page_size: pageSize,
})
} else {
res = await getListPackageFunction({
func_name: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
})
}
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
console.log(res.data)
const newList = res.data.data.data.map((e, i) => {
return { ...e, index: i + 1 + pageIndex * pageSize }
})
setData(newList)
setTotalRecord(res.data.data.total_elements)
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
useEffect(() => {
getData(true)
}, [searchDebount])
useEffect(() => {
getData(false)
}, [pageIndex])
const removeItem = async (id) => {
props.showLoading()
const res = await deletePackageFunction({ idGuid: id })
props.hideLoading()
if (res.data.code == 200) {
getData()
toast.success('Xoá bản ghi thành công!', {
theme: 'colored',
})
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
return (
<ToolUserView
data={data}
removeItem={removeItem}
setTxtSearch={setTxtSearch}
setActiveSeleted={setActiveSeleted}
pageIndex={pageIndex}
changeActive={changeActive}
setChangeActive={setChangeActive}
setPageIndex={setPageIndex}
activeSelected={activeSelected}
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
permissions={permissions}
/>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
ToolNotificate
)
import React, { useState, useEffect } from 'react'
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator'
import { Button, Grid } from '@material-ui/core'
import {
detailPackageFunction,
updatePackageFunction,
} from 'app/apis/Functions/landingpage'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import { Breadcrumb, SimpleCard } from 'app/components'
import { Link, useHistory, useLocation } from 'react-router-dom'
import { trimObject } from 'app/config/Function'
import { connect } from 'react-redux'
import localStorageService from 'app/services/localStorageService'
import { useTranslation } from 'react-i18next'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const history = useHistory()
const location = useLocation()
const { t } = useTranslation()
useEffect(() => {
getData()
}, [])
const getData = async () => {
props.showLoading()
const res = await detailPackageFunction(location.state, {})
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
setState(res.data.data)
} else if (res.data.code == 401) {
localStorageService.removeToken()
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await updatePackageFunction({
...newValue,
})
props.hideLoading()
if (res.data.code == 200) {
history.push('/package-function')
if (res.data.code == 200) {
toast.success('Cập nhật chức năng thành công!', {
theme: 'colored',
})
}
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const handleDateChange = (date) => {
setState({ ...state, date })
}
const { description, func_name } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách chức năng gói',
path: '/package-function',
},
{ name: 'Cập nhật chức năng' },
]}
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<Grid container spacing={3}>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Tên chức năng *"
onChange={handleChange}
type="text"
name="func_name"
value={func_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Mô tả "
onChange={handleChange}
type="text"
name="description"
value={description || ''}
/>
</Grid>
</Grid>
<Grid container justify={'flex-end'}>
<Button
style={{
marginRight: 20,
}}
color="inherit"
variant="contained"
onClick={() => {
history.goBack()
}}
>
<span className="capitalize">Quay li</span>
</Button>
<Button
color="primary"
variant="contained"
type="submit"
>
<span className="capitalize">Cp nht</span>
</Button>
</Grid>
</ValidatorForm>
</SimpleCard>
</div>
</div>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
SimpleForm
)
import React, { Fragment, useState, useEffect } from 'react'
import {
TextField,
Icon,
Button,
StepLabel,
Step,
Stepper,
Grid,
FormControl,
InputLabel,
Select,
MenuItem,
} from '@material-ui/core'
import Table from './Table'
import { Breadcrumb } from 'app/components'
import { Link } from 'react-router-dom'
import { Autocomplete, createFilterOptions } from '@material-ui/lab'
import useAuth from 'app/hooks/useAuth'
import { checkRole } from 'app/config/Function'
function CustomerView(props) {
const {
data,
updateItem,
removeItem,
setTxtSearch,
changeActive,
setChangeActive,
handeChangeActive,
setPageIndex,
pageIndex,
totalRecords,
permissions,
} = props
const [age, setAge] = React.useState('')
const { user } = useAuth()
const handleChange = (event) => {
setAge(event.target.value)
}
return (
<Fragment>
<div className="m-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách chức năng gói',
path: '/package-function',
},
]}
/>
</div>
<Grid
style={{
padding: 10,
marginBottom: 20,
}}
justify={'space-between'}
alignItems={'center'}
container
spacing={3}
>
<Grid item lg={3} md={3} sm={6} xs={6}>
<TextField
variant="outlined"
className="w-full"
label="Nhập từ khoá"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</Grid>
{checkRole(user, '/package-function/create') ? (
<Link to="/package-function/create">
<Button
variant="contained"
className={'bg-light-primary'}
>
<span className={'text-primary'}>Thêm mi</span>
</Button>
</Link>
) : null}
</Grid>
<Table
data={data}
changeActive={changeActive}
setChangeActive={setChangeActive}
handeChangeActive={handeChangeActive}
updateItem={updateItem}
removeItem={removeItem}
pageIndex={pageIndex}
setPageIndex={setPageIndex}
totalRecords={totalRecords}
permissions={permissions}
/>
</div>
</Fragment>
)
}
export default CustomerView
import React from 'react'
const Routes = [
{
path: '/package-function/create',
component: React.lazy(() => import('./function/Create')),
},
{
path: '/package-function/update',
component: React.lazy(() => import('./function/Update')),
},
{
path: '/package-function',
component: React.lazy(() => import('./function/Index')),
},
]
export default Routes
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