| | |
| | | import DialogCloseButton from "../components/DialogCloseButton"; |
| | | import { format } from 'date-fns'; |
| | | import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew'; |
| | | import request from '@/utils/request'; |
| | | |
| | | const MissionResend = ({ open, id }) => { |
| | | const redirect = useRedirect(); |
| | |
| | | </Box> |
| | | )} |
| | | |
| | | <ActionTable actionIds={record?.actionIds} /> |
| | | |
| | | <ActionTable actionIds={record?.actionIds} currCode={record.currCode} handleClose={handleClose} /> |
| | | </Box> |
| | | </Box> |
| | | </Stack> |
| | |
| | | |
| | | const headCells = [ |
| | | { |
| | | id: 'name', |
| | | id: 'actionType', |
| | | numeric: false, |
| | | disablePadding: true, |
| | | label: 'Dessert (100g serving)', |
| | | label: 'table.field.action.actionType', |
| | | }, |
| | | { |
| | | id: 'calories', |
| | | id: 'code', |
| | | numeric: true, |
| | | disablePadding: false, |
| | | label: 'Calories', |
| | | label: 'table.field.action.code', |
| | | }, |
| | | { |
| | | id: 'fat', |
| | | id: 'taskId', |
| | | numeric: true, |
| | | disablePadding: false, |
| | | label: 'Fat (g)', |
| | | label: 'table.field.action.taskId', |
| | | }, |
| | | { |
| | | id: 'carbs', |
| | | id: 'val', |
| | | numeric: true, |
| | | disablePadding: false, |
| | | label: 'Carbs (g)', |
| | | label: 'table.field.action.val', |
| | | }, |
| | | { |
| | | id: 'protein', |
| | | id: 'params', |
| | | numeric: true, |
| | | disablePadding: false, |
| | | label: 'Protein (g)', |
| | | label: 'table.field.action.params', |
| | | }, |
| | | ]; |
| | | |
| | | const ActionTable = ({ actionIds }) => { |
| | | const ActionTable = ({ actionIds, currCode, handleClose }) => { |
| | | const dataProvider = useDataProvider(); |
| | | const translate = useTranslate(); |
| | | const notify = useNotify(); |
| | | const [actions, setActions] = useState([]); |
| | | const [selected, setSelected] = React.useState([]); |
| | | |
| | |
| | | dataProvider.getMany('action', { ids: actionIds }).then(res => { |
| | | if (res.data?.length > 0) { |
| | | setActions(res.data); |
| | | |
| | | // init selected |
| | | const indexOfCurrCode = res.data.findIndex(item => item.code === currCode); |
| | | if (indexOfCurrCode !== -1) { |
| | | const selectedIds = res.data.slice(indexOfCurrCode).map(item => item.id); |
| | | setSelected(selectedIds); |
| | | } |
| | | } |
| | | }) |
| | | } |
| | |
| | | setSelected(newSelected); |
| | | }; |
| | | |
| | | const resendSubmit = () => { |
| | | if (!!selected?.length) { |
| | | request.post("/mission/resend", selected.map(id => ({ id }))).then(res => { |
| | | const { code, msg, data } = res.data; |
| | | if (code === 200) { |
| | | notify(msg || 'common.response.success', { type: 'success', messageArgs: { _: msg } }); |
| | | handleClose(); |
| | | } else { |
| | | notify(msg || 'common.response.fail', { type: 'error', messageArgs: { _: msg } }); |
| | | } |
| | | }).catch(error => { |
| | | notify(error.message || 'common.response.fail', { type: 'error', messageArgs: { _: error.message } }); |
| | | }) |
| | | } |
| | | } |
| | | |
| | | return ( |
| | | <> |
| | | <Box sx={{ width: '100%' }}> |
| | | <Paper sx={{ width: '100%', mb: 2 }}> |
| | | <Paper sx={{ |
| | | width: '100%', |
| | | mb: 2, |
| | | }}> |
| | | <Toolbar |
| | | sx={[ |
| | | { |
| | | pl: { sm: 2 }, |
| | | pr: { xs: 1, sm: 1 }, |
| | | minHeight: '52.5px !important', |
| | | }, |
| | | selected.length > 0 && { |
| | | bgcolor: (theme) => |
| | |
| | | variant="subtitle1" |
| | | component="div" |
| | | > |
| | | {selected.length} selected |
| | | {selected.length} {translate('common.action.selected')} |
| | | </Typography> |
| | | ) : ( |
| | | <Typography |
| | | sx={{ flex: '1 1 100%' }} |
| | | variant="h6" |
| | | variant="subtitle1" |
| | | id="tableTitle" |
| | | component="div" |
| | | > |
| | | Actions |
| | | {translate('table.field.mission.actions')} |
| | | </Typography> |
| | | )} |
| | | {selected.length > 0 && ( |
| | | <Tooltip title="Delete"> |
| | | <IconButton> |
| | | <Button |
| | | onClick={() => { |
| | | alert('clicked'); |
| | | }} |
| | | > |
| | | ss |
| | | </Button> |
| | | </IconButton> |
| | | <Tooltip title="Resend"> |
| | | <Button |
| | | onClick={resendSubmit} |
| | | > |
| | | {translate('ra.action.confirm')} |
| | | </Button> |
| | | </Tooltip> |
| | | )} |
| | | </Toolbar> |
| | |
| | | align={headCell.numeric ? 'right' : 'left'} |
| | | padding={headCell.disablePadding ? 'none' : 'normal'} |
| | | > |
| | | {headCell.label} |
| | | {translate(headCell.label)} |
| | | </TableCell> |
| | | ))} |
| | | </TableRow> |
| | |
| | | scope="row" |
| | | padding="none" |
| | | > |
| | | {row.name} |
| | | [ {row.priority} ] |
| | | |
| | | {row.actionType$} |
| | | </TableCell> |
| | | <TableCell align="right">{row.calories}</TableCell> |
| | | <TableCell align="right">{row.fat}</TableCell> |
| | | <TableCell align="right">{row.carbs}</TableCell> |
| | | <TableCell align="right">{row.protein}</TableCell> |
| | | <TableCell align="right">{row.code}</TableCell> |
| | | <TableCell align="right">{row.taskId$}</TableCell> |
| | | <TableCell align="right">{row.val}</TableCell> |
| | | <TableCell align="right">{row.params}</TableCell> |
| | | </TableRow> |
| | | ); |
| | | })} |