Commit 6898a96c by tdgiang

update code

parent 0bf0a395
import React from 'react'
import Button from '@material-ui/core/Button'
import Dialog from '@material-ui/core/Dialog'
import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent'
import DialogContentText from '@material-ui/core/DialogContentText'
import DialogTitle from '@material-ui/core/DialogTitle'
import Slide from '@material-ui/core/Slide'
const Transition = React.forwardRef(function Transition(props, ref) {
return <Slide direction="up" ref={ref} {...props} />
})
export default function AlertDialogSlide(props) {
const { open, handleClose, data, onAgree } = props
return (
<Dialog
open={open}
maxWidth={'sm'}
fullWidth={true}
TransitionComponent={Transition}
keepMounted
onClose={handleClose}
aria-labelledby="alert-dialog-slide-title"
aria-describedby="alert-dialog-slide-description"
>
<DialogTitle id="alert-dialog-slide-title">
Lý do từ chối
</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-slide-description">
{data?.reason}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="primary">
Quay lại
</Button>
<Button
onClick={() => {
handleClose()
}}
color="primary"
>
Đồng ý
</Button>
</DialogActions>
</Dialog>
)
}
...@@ -29,6 +29,7 @@ import DialogTransition from 'app/components/dialog/DialogTransition' ...@@ -29,6 +29,7 @@ import DialogTransition from 'app/components/dialog/DialogTransition'
import { useHistory } from 'react-router-dom' import { useHistory } from 'react-router-dom'
import useAuth from 'app/hooks/useAuth' import useAuth from 'app/hooks/useAuth'
import { checkRole } from 'app/config/Function' import { checkRole } from 'app/config/Function'
import DialogReason from 'app/components/dialog/DialogReason'
const columns = [ const columns = [
{ {
...@@ -120,6 +121,8 @@ function TableList(props) { ...@@ -120,6 +121,8 @@ function TableList(props) {
content: '', content: '',
}) })
const [open, setOpen] = React.useState(false) const [open, setOpen] = React.useState(false)
const [openReason, setOpenReason] = useState(false)
const { user } = useAuth() const { user } = useAuth()
const handleChangePage = (event, newPage) => { const handleChangePage = (event, newPage) => {
setPageIndex(newPage) setPageIndex(newPage)
...@@ -340,6 +343,28 @@ function TableList(props) { ...@@ -340,6 +343,28 @@ function TableList(props) {
</Icon> </Icon>
</IconButton> </IconButton>
</Tooltip> </Tooltip>
{row.status == 4 && (
<Tooltip title="Lý do từ chối ">
<IconButton
onClick={() => {
setSelected({
...row,
})
setOpenReason(true)
}}
className={classes.button}
aria-label="edit"
>
<Icon
style={{
color: '#FF9500',
}}
>
info
</Icon>
</IconButton>
</Tooltip>
)}
</TableCell> </TableCell>
</TableRow> </TableRow>
) )
...@@ -357,6 +382,17 @@ function TableList(props) { ...@@ -357,6 +382,17 @@ function TableList(props) {
}} }}
/> />
<DialogReason
data={selected}
open={openReason}
handleClose={() => {
setOpenReason(false)
}}
onAgree={() => {
handleClose()
}}
/>
<TablePagination <TablePagination
component="div" component="div"
page={pageIndex} page={pageIndex}
......
...@@ -35,7 +35,7 @@ import TableContainer from '@material-ui/core/TableContainer' ...@@ -35,7 +35,7 @@ import TableContainer from '@material-ui/core/TableContainer'
import TableHead from '@material-ui/core/TableHead' import TableHead from '@material-ui/core/TableHead'
import TableRow from '@material-ui/core/TableRow' import TableRow from '@material-ui/core/TableRow'
import Paper from '@material-ui/core/Paper' import Paper from '@material-ui/core/Paper'
import { convertDate } from 'app/config/Function'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import AcceptStore from 'app/components/dialog/AcceptStore' import AcceptStore from 'app/components/dialog/AcceptStore'
import RejectStore from 'app/components/dialog/RejectStore' import RejectStore from 'app/components/dialog/RejectStore'
...@@ -169,7 +169,7 @@ const SimpleForm = (props) => { ...@@ -169,7 +169,7 @@ const SimpleForm = (props) => {
toast.success( toast.success(
`${ `${
status == 4 ? 'Từ chối phê duyệt' : 'Phê duyệt' status == 4 ? 'Từ chối phê duyệt' : 'Phê duyệt'
} trụ xăng thành công`, } cây xăng thành công`,
{ {
theme: 'colored', theme: 'colored',
} }
...@@ -187,6 +187,48 @@ const SimpleForm = (props) => { ...@@ -187,6 +187,48 @@ const SimpleForm = (props) => {
} }
} }
const acceptStoreSub = async (forever, date) => {
setOpenAccpet(false)
props.showLoading()
const res = await changeStatusStore({
id: location.state,
status_id: 1,
expired: forever ? null : convertDate(date),
})
props.hideLoading()
if (res.data.code == 200) {
toast.success(`${'Phê duyệt'} cây xăng thành công`, {
theme: 'colored',
})
history.push('/gas-station')
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const rejectStoreSub = async (reason) => {
setOpenReject(false)
props.showLoading()
const res = await changeStatusStore({
id: location.state,
status_id: 4,
reason: reason,
})
props.hideLoading()
if (res.data.code == 200) {
toast.success(`${'Từ chối'} cây xăng thành công`, {
theme: 'colored',
})
history.push('/gas-station')
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const { const {
store_name, store_name,
province_id, province_id,
...@@ -574,8 +616,8 @@ const SimpleForm = (props) => { ...@@ -574,8 +616,8 @@ const SimpleForm = (props) => {
handleClose={() => { handleClose={() => {
setOpenAccpet(false) setOpenAccpet(false)
}} }}
onAgree={() => { onAgree={(forever, date) => {
changeSatusStore(1) acceptStoreSub(forever, date)
}} }}
/> />
...@@ -584,8 +626,8 @@ const SimpleForm = (props) => { ...@@ -584,8 +626,8 @@ const SimpleForm = (props) => {
handleClose={() => { handleClose={() => {
setOpenReject(false) setOpenReject(false)
}} }}
onAgree={() => { onAgree={(reason) => {
changeSatusStore(4) rejectStoreSub(reason)
}} }}
/> />
</Grid> </Grid>
......
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