Commit f006fbb8 by tdgiang

update code

parent d4e780bb
...@@ -14,7 +14,7 @@ import ProductRoutes from './views/product/ProductRouters' ...@@ -14,7 +14,7 @@ import ProductRoutes from './views/product/ProductRouters'
import TransactionRouters from './views/Transaction/TransactionRouters' import TransactionRouters from './views/Transaction/TransactionRouters'
import FeeRouters from './views/Fee/FeeRouters' import FeeRouters from './views/Fee/FeeRouters'
import MerchantRoutes from './views/Merchant/MerchantRoutes' import MerchantRoutes from './views/Merchant/MerchantRoutes'
import GasStationRoutes from './views/GasStation/GasStationRoutes'
const redirectRoute = [ const redirectRoute = [
{ {
path: '/', path: '/',
...@@ -30,6 +30,7 @@ const errorRoute = [ ...@@ -30,6 +30,7 @@ const errorRoute = [
] ]
const routes = [ const routes = [
...GasStationRoutes,
...MerchantRoutes, ...MerchantRoutes,
...FeeRouters, ...FeeRouters,
...TransactionRouters, ...TransactionRouters,
......
...@@ -30,3 +30,33 @@ export const changeStatusMerchant = async (body) => ...@@ -30,3 +30,33 @@ export const changeStatusMerchant = async (body) =>
PostData(url.changeStatusMerchant, body) PostData(url.changeStatusMerchant, body)
.then((res) => res) .then((res) => res)
.catch((err) => null) .catch((err) => null)
//
export const getListGasStation = async (body) =>
PostData(url.urlGetListGasStation, body)
.then((res) => res)
.catch((err) => null)
export const createGasStation = async (body) =>
PostData(url.urlCreateGasStation, body)
.then((res) => res)
.catch((err) => null)
export const updateGasStation = async (body) =>
PostData(url.urlUpdateGasStation, body)
.then((res) => res)
.catch((err) => null)
export const detailGasStation = async (id, body) =>
GetURL(`${url.urlDetailGasStation}/${id}`, body)
.then((res) => res)
.catch((err) => null)
export const deleteGasStation = async (body) =>
PostData(url.urlDeleteGasStation, body)
.then((res) => res)
.catch((err) => null)
export const changeStatusGasStation = async (body) =>
PostData(url.changeStatusGasStation, body)
.then((res) => res)
.catch((err) => null)
...@@ -71,6 +71,15 @@ export default { ...@@ -71,6 +71,15 @@ export default {
urlDetailMerchant: `${root}/merchant`, urlDetailMerchant: `${root}/merchant`,
changeStatusMerchant: `${root}/merchant/changeStatus`, changeStatusMerchant: `${root}/merchant/changeStatus`,
//Gas-Station
urlGetListGasStation: `${root}/merchantstore/list`,
urlCreateGasStation: `${root}/merchantstore/savedata`,
urlUpdateGasStation: `${root}/merchantstore/savedata`,
urlDeleteGasStation: `${root}/merchantstore/delete`,
urlDetailGasStation: `${root}/merchantstore`,
changeStatusGasStation: `${root}/merchantstore/changeStatus`,
//Log //Log
logAuth: `${root}/logging/listLogin`, logAuth: `${root}/logging/listLogin`,
logApi: `${root}/logging/listCallApi`, logApi: `${root}/logging/listCallApi`,
......
...@@ -143,7 +143,7 @@ export const navigationsAdmin = [ ...@@ -143,7 +143,7 @@ export const navigationsAdmin = [
{ {
name: 'Quản lý cây xăng', name: 'Quản lý cây xăng',
path: '/gas-stations', path: '/gas-station',
icon: 'local_gas_station', icon: 'local_gas_station',
id: 'GAS_STATION', id: 'GAS_STATION',
hide: false, hide: false,
......
import React, { useState, useEffect } from 'react'
import {
ValidatorForm,
TextValidator,
SelectValidator,
} from 'react-material-ui-form-validator'
import { Button, Grid, MenuItem, 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 } from 'app/config/Function'
import { connect } from 'react-redux'
import { dropdownMerchant } from 'app/apis/Functions/dropdown'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const history = useHistory()
const [listDrop, setListDrop] = useState([])
useEffect(() => {
getData()
}, [])
const getData = async () => {
props.showLoading()
const res = await dropdownMerchant({})
props.hideLoading()
if (res.data.code == 200 && res.data.data) {
const newList = res.data.data.map((e) => {
return { ...e, name: e.merchant_name }
})
setListDrop(newList)
} else if (res.data.code == 401) {
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error('Lấy giữ liệu thất bại !', {
theme: 'colored',
})
}
}
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await createFunction({
...newValue,
status: 1,
is_default: true,
})
props.hideLoading()
if (res.data.code == 200) {
history.push('/gas-station')
if (res.data.code == 200) {
toast.success('Tạo hành động thành công!', {
theme: 'colored',
})
}
} else {
toast.error('Tạo hành động thất bại!', {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const handleDateChange = (date) => {
setState({ ...state, date })
}
const { store_name, address, merchan_id } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách cây xăng',
path: '/gas-station',
},
{ name: 'Thêm mới cây xăng' },
]}
/>
</div>
<SimpleCard>
<ValidatorForm onSubmit={handleSubmit} onError={() => null}>
<Grid container spacing={3}>
<Grid xs={6} sm={6} item>
<SelectValidator
variant={'outlined'}
label={'Thuộc pháp nhân *'}
className="mb-4 w-full"
value={merchan_id || ''}
displayEmpty
name="merchan_id"
onChange={handleChange}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
>
{listDrop.map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</SelectValidator>
</Grid>
<Grid item lg={6} md={6} sm={12} xs={12}>
<TextValidator
variant="outlined"
className="mb-4 w-full"
label="Tên cây xăng *"
onChange={handleChange}
type="text"
name="store_name"
value={store_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="Địa chỉ *"
onChange={handleChange}
type="text"
name="address"
value={address || ''}
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 cây xăng *"
onChange={handleChange}
type="text"
name="store_name"
value={store_name || ''}
validators={['required']}
errorMessages={[
'Không được để trống trường này',
]}
/>
</Grid> */}
<Grid
item
container
lg={12}
md={12}
sm={12}
xs={12}
justify="space-between"
style={{
padding: 10,
borderRadius: 5,
}}
>
<Typography variant="h6">
Thông tin tr xăng
</Typography>
<Grid
item
container
lg={12}
md={12}
sm={12}
xs={12}
justify="space-between"
>
<div>
<Typography>
S lượng vòi mi tr:1
</Typography>
<Typography>S lượng tr:3</Typography>
</div>
<Typography variant="h6">
Thêm tr
</Typography>
</Grid>
<Grid
style={{
border: '1px solid #B9B9B9',
borderRadius: 5,
padding: 10,
marginTop: 10,
}}
lg={12}
md={12}
sm={12}
xs={12}
>
<Grid lg={12} md={12} sm={12} xs={12}>
<div
style={{
alignItems: 'center',
justifyContent: 'space-between',
display: 'flex',
}}
>
<Typography variant="h6">
TR 1
</Typography>
<Typography variant="h6">
Xoá tr
</Typography>
</div>
</Grid>
</Grid>
</Grid>
</Grid>
<Grid
style={{
marginTop: 40,
}}
container
justify={'flex-end'}
>
<Link to="gas-station">
<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 from 'react'
const GasStationRoutes = [
{
path: '/gas-station/create',
component: React.lazy(() => import('./Create')),
},
{
path: '/gas-station/update',
component: React.lazy(() => import('./Update')),
},
{
path: '/gas-station',
component: React.lazy(() => import('./Index')),
},
]
export default GasStationRoutes
import React, { useState, useEffect } from 'react'
import ToolUserView from './View'
import {
getListGasStation,
deleteGasStation,
changeStatusGasStation,
} from 'app/apis/Functions/merchant'
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'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const searchDebount = useDebounce(txtSearch, 1000)
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 changeStatusGasStation({ 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('Thay đổi trạng thái thất bại!', {
theme: 'colored',
})
}
}
const getData = async () => {
props.showLoading()
const res = await getListGasStation({
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 {
// enqueueSnackbar('Error!', { variant: 'error' })
}
}
useEffect(() => {
getData()
}, [searchDebount, pageIndex])
const removeItem = async (id) => {
props.showLoading()
const res = await deleteGasStation({ 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('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}
permissions={permissions}
/>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
ToolNotificate
)
import React, { useState } from 'react'
import {
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableContainer,
TablePagination,
TableRow,
IconButton,
MenuItem,
Select,
Modal,
Fade,
Grid,
Backdrop,
Link,
Button,
Tooltip,
Icon,
} from '@material-ui/core'
import EditIcon from '@material-ui/icons/Edit'
import DeleteIcon from '@material-ui/icons/Delete'
import colors from 'app/assets/Color'
import useStyles from 'app/styles/Table'
import { Breadcrumb, SimpleCard } from 'app/components'
import DialogTransition from 'app/components/dialog/DialogTransition'
import { useHistory } from 'react-router-dom'
import useAuth from 'app/hooks/useAuth'
import { checkRole } from 'app/config/Function'
const columns = [
{
id: 'index',
label: 'STT',
align: 'center',
minWidth: 50,
},
{
id: 'store_name',
label: 'Tên cây xăng',
align: 'left',
minWidth: 'auto',
},
{
id: 'address',
label: 'Địa chỉ',
align: 'left',
minWidth: 'auto',
},
{
id: 'merchant_name',
label: 'Thuộc pháp nhân',
align: 'left',
minWidth: 'auto',
},
{
id: 'store_owner',
label: 'Người đại diện',
align: 'left',
minWidth: 'auto',
},
{
id: 'email',
label: 'Email',
align: 'left',
minWidth: 'auto',
},
{
id: 'phone',
label: 'Số điện thoại',
align: 'left',
minWidth: 'auto',
},
]
function TableList(props) {
const {
data,
handeChangeActive,
removeItem,
changeActive,
setChangeActive,
setPageIndex,
setPageSize,
pageIndex,
totalRecords,
permissions,
} = props
const classes = useStyles()
let history = useHistory()
const [selected, setSelected] = useState({
name: '',
id: '',
title: '',
content: '',
})
const [open, setOpen] = React.useState(false)
const { user } = useAuth()
const handleChangePage = (event, newPage) => {
setPageIndex(newPage)
}
const handleChangeRowsPerPage = (event) => {
setPageSize(event.target.value)
}
const handleClose = () => {
setOpen(false)
}
return (
<Paper className={classes.root}>
<TableContainer className={classes.container}>
<Table stickyHeader aria-label="sticky table">
<TableHead>
<TableRow>
{columns.map((column) => (
<TableCell
key={column.id}
align={'center'}
style={{
width: column.minWidth,
backgroundColor: colors.headerTable,
}}
>
{column.label}
</TableCell>
))}
<TableCell
style={{
backgroundColor: colors.headerTable,
width: 125,
}}
>
Trạng thái
</TableCell>
<TableCell
style={{
textAlign: 'center',
backgroundColor: colors.headerTable,
width: 120,
}}
>
Hành động
</TableCell>
</TableRow>
</TableHead>
<TableBody className={classes.columnTable}>
{data.map((row) => {
return (
<TableRow
hover
role="checkbox"
tabIndex={-1}
key={row.code}
>
{columns.map((column) => {
const imageUrl = row[column.id]
return (
<TableCell
key={column.id}
align={column.align}
>
{column.format ? (
<img
src={column.format(
imageUrl
)}
className={
classes.image
}
/>
) : (
imageUrl
)}
</TableCell>
)
})}
<TableCell className={classes.border}>
<Select
variant={'outlined'}
labelId="demo-simple-select-placeholder-label-label"
id="demo-simple-select-placeholder-label"
onChange={(e) =>
handeChangeActive(
row.id,
e.target.value
)
}
displayEmpty
defaultValue={row.status}
className={classes.formControl}
>
<MenuItem value={1}>
Hot động
</MenuItem>
<MenuItem value={2}>Khóa</MenuItem>
</Select>
</TableCell>
<TableCell>
{checkRole(user, '/function/delete') ? (
<Tooltip title="Xoá">
<IconButton
onClick={() => {
setSelected({
...row,
title: 'Xóa cây xăng',
content: `Bạn có muốn xóa cây xăng ${row.name} hay không?`,
})
setOpen(true)
}}
className={classes.button}
aria-label="Delete"
>
<Icon color="error">
delete
</Icon>
</IconButton>
</Tooltip>
) : null}
{checkRole(
user,
'/gas-station/update'
) ? (
<Tooltip title="Cập nhật">
<IconButton
onClick={() => {
history.push({
pathname:
'/gas-station/update',
state: row.id,
})
}}
className={classes.button}
aria-label="edit"
>
<Icon color="primary">
edit
</Icon>
</IconButton>
</Tooltip>
) : null}
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</TableContainer>
<DialogTransition
data={selected}
open={open}
handleClose={handleClose}
onAgree={() => {
removeItem(selected.id)
handleClose()
}}
/>
<TablePagination
component="div"
page={pageIndex}
count={totalRecords}
rowsPerPage={10}
rowsPerPageOptions={[]}
onChangePage={handleChangePage}
onChangeRowsPerPage={handleChangeRowsPerPage}
/>
</Paper>
)
}
export default TableList
import React, { useState, useEffect } from 'react'
import { ValidatorForm, TextValidator } from 'react-material-ui-form-validator'
import { Button, Grid } from '@material-ui/core'
import { detailFunction, updateFunction } 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 } from 'app/config/Function'
import { connect } from 'react-redux'
import localStorageService from 'app/services/localStorageService'
const SimpleForm = (props) => {
const [state, setState] = useState({})
const history = useHistory()
const location = useLocation()
useEffect(() => {
getData()
}, [])
const getData = async () => {
props.showLoading()
const res = await detailFunction(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('Lấy thông tin bản ghi thất bại!', {
theme: 'colored',
})
}
}
const handleSubmit = async (event) => {
const newValue = trimObject(state)
props.showLoading()
const res = await updateFunction({
...newValue,
status: 1,
is_default: true,
})
props.hideLoading()
if (res.data.code == 200) {
history.push('/gas-station')
if (res.data.code == 200) {
toast.success('Cập nhật hành động thành công!', {
theme: 'colored',
})
}
} else {
toast.error('Cập nhật hành động thất bại!', {
theme: 'colored',
})
}
}
const handleChange = (event) => {
event.persist()
setState({
...state,
[event.target.name]: event.target.value,
})
}
const handleDateChange = (date) => {
setState({ ...state, date })
}
const { description, name, code, url } = state
return (
<div className="m-sm-30">
<div className="mb-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'Danh sách cây xăng',
path: '/gas-station',
},
{ name: 'Cập nhật cây xă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 cây xăng *"
onChange={handleChange}
type="text"
name="name"
value={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ã code *"
onChange={handleChange}
type="text"
name="code"
value={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="Đường dẫn *"
onChange={handleChange}
type="text"
name="url"
value={url || ''}
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'}>
<Link to="gas-station">
<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 {
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 cây xăng',
path: '/gas-station',
},
]}
/>
</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="Tên cây xăng"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</Grid>
{checkRole(user, '/gas-station/create') ? (
<Link to="/gas-station/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
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