|  |  |  | 
|---|
|  |  |  | </DialogContent> | 
|---|
|  |  |  | <DialogActions> | 
|---|
|  |  |  | <Toolbar sx={{ width: '100%', justifyContent: 'end' }} > | 
|---|
|  |  |  | <GenerateTaskButton record={[record?.id]} dataSource={data} /> | 
|---|
|  |  |  | <GenerateTaskButton record={record?.id} dataSource={data} setOpen={setOpen}/> | 
|---|
|  |  |  | </Toolbar> | 
|---|
|  |  |  | </DialogActions> | 
|---|
|  |  |  | </Dialog> | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | export default ItemToTaskModal; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | const GenerateTaskButton = (record, dataSource) => { | 
|---|
|  |  |  | const GenerateTaskButton = (record) => { | 
|---|
|  |  |  | const refresh = useRefresh(); | 
|---|
|  |  |  | const notify = useNotify(); | 
|---|
|  |  |  | const redirect = useRedirect(); | 
|---|
|  |  |  | const translate = useTranslate(); | 
|---|
|  |  |  | const { locs, setLocs } = useState([]); | 
|---|
|  |  |  | const generateTask = async () => { | 
|---|
|  |  |  | const res = await request.post(`/wave/public/task`, { wave: record, waveItem: dataSource }); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | redirect("/task") | 
|---|
|  |  |  | record?.dataSource.map(item => { | 
|---|
|  |  |  | const loc = JSON.parse(item.stockLocs); | 
|---|
|  |  |  | if (loc != undefined && loc.length > 0) { | 
|---|
|  |  |  | setLocs(...loc) | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }) | 
|---|
|  |  |  | if (locs == undefined || locs.length < 1) { | 
|---|
|  |  |  | notify(translate('request.error.stock')) | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | const res = await request.post(`/wave/public/task`, { wave: record?.record, waveItem: record?.dataSource }); | 
|---|
|  |  |  | if (res?.data?.code === 200) { | 
|---|
|  |  |  | record.setOpen(false) | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | redirect("/task") | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | notify(res.data.msg); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | refresh(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (<Button variant="contained" label={"ra.action.save"} onClick={generateTask}></Button>) | 
|---|
|  |  |  | } | 
|---|