AiraBilqis
9 months ago
2 changed files with 103 additions and 104 deletions
@ -1,96 +1,96 @@
|
||||
import React, { useEffect, useState } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; |
||||
import axios from "../../../const/interceptorApi"; |
||||
import { DOCUMENT_ADD, FOLDER_DOCUMENT_PROYEK_ADD } from '../../../const/ApiConst'; |
||||
import 'antd/dist/antd.css'; |
||||
import { NotificationManager } from 'react-notifications'; |
||||
|
||||
const DialogRequestFolder = ({ openDialog, closeDialog, toggleDialog, idTask, parentIdNewFolder }) => { |
||||
const token = localStorage.getItem("token") |
||||
const HEADER = { |
||||
headers: { |
||||
"Content-Type": "application/json", |
||||
"Authorization": `Bearer ${token}` |
||||
} |
||||
} |
||||
const [id, setId] = useState(0) |
||||
const [folderName, setFolderName] = useState('') |
||||
|
||||
|
||||
const handleClearData = () => { |
||||
setId(0) |
||||
setFolderName('') |
||||
} |
||||
|
||||
useEffect(() => { |
||||
handleClearData() |
||||
}, [openDialog]) |
||||
|
||||
const handleSave = () => { |
||||
saveFolder() |
||||
handleClearData() |
||||
} |
||||
|
||||
const saveFolder = async () => { |
||||
|
||||
|
||||
|
||||
|
||||
let payload = { |
||||
"proyek_id": idTask, |
||||
"name_folder": folderName |
||||
} |
||||
|
||||
if (parentIdNewFolder > 0) { |
||||
payload.parent_id = parentIdNewFolder |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(FOLDER_DOCUMENT_PROYEK_ADD, payload, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
NotificationManager.success('Success create folder!!', 'Success'); |
||||
closeDialog("upload"); |
||||
} else { |
||||
NotificationManager.error('Failed to create folder!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
closeDialog('cancel') |
||||
handleClearData() |
||||
} |
||||
|
||||
const renderForm = () => { |
||||
return ( |
||||
<Form> |
||||
<FormGroup> |
||||
<Label className="capitalize">Folder Name</Label> |
||||
<Input type="text" onChange={(e) => setFolderName(e.target.value)} /> |
||||
</FormGroup> |
||||
</Form> |
||||
) |
||||
} |
||||
|
||||
|
||||
return ( |
||||
<> |
||||
<Modal isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize" toggle={closeDialog}>Create New Folder</ModalHeader> |
||||
<ModalBody> |
||||
{renderForm()} |
||||
</ModalBody> |
||||
<ModalFooter> |
||||
<Button color="primary" onClick={() => handleSave()}>Save</Button>{' '} |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Cancel</Button> |
||||
</ModalFooter> |
||||
</Modal> |
||||
</> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogRequestFolder; |
||||
import React, { useEffect, useState } from 'react' |
||||
import { Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'; |
||||
import { Button, Form, FormGroup, Label, Input, Col, Row } from 'reactstrap'; |
||||
import axios from "../../../const/interceptorApi"; |
||||
import { FOLDER_DOCUMENT_PROYEK_ADD } from '../../../const/ApiConst'; |
||||
import 'antd/dist/antd.css'; |
||||
import { NotificationManager } from 'react-notifications'; |
||||
|
||||
const DialogRequestFolder = ({ openDialog, closeDialog, toggleDialog, idTask, parentIdNewFolder }) => { |
||||
const token = localStorage.getItem("token") |
||||
const HEADER = { |
||||
headers: { |
||||
"Content-Type": "application/json", |
||||
"Authorization": `Bearer ${token}` |
||||
} |
||||
} |
||||
const [id, setId] = useState(0) |
||||
const [folderName, setFolderName] = useState('') |
||||
|
||||
|
||||
const handleClearData = () => { |
||||
setId(0) |
||||
setFolderName('') |
||||
} |
||||
|
||||
useEffect(() => { |
||||
handleClearData() |
||||
}, [openDialog]) |
||||
|
||||
const handleSave = () => { |
||||
saveFolder() |
||||
handleClearData() |
||||
} |
||||
|
||||
const saveFolder = async () => { |
||||
|
||||
|
||||
|
||||
|
||||
let payload = { |
||||
"proyek_id": idTask, |
||||
"name_folder": folderName |
||||
} |
||||
|
||||
if (parentIdNewFolder > 0) { |
||||
payload.parent_id = parentIdNewFolder |
||||
} |
||||
|
||||
const result = await axios |
||||
.post(FOLDER_DOCUMENT_PROYEK_ADD, payload, HEADER) |
||||
.then(res => res) |
||||
.catch((error) => error.response); |
||||
|
||||
if (result && result.data && result.data.code == 200) { |
||||
NotificationManager.success('Success create folder!!', 'Success'); |
||||
closeDialog("upload"); |
||||
} else { |
||||
NotificationManager.error('Failed to create folder!!', 'Failed'); |
||||
} |
||||
} |
||||
|
||||
const handleCancel = () => { |
||||
closeDialog('cancel') |
||||
handleClearData() |
||||
} |
||||
|
||||
const renderForm = () => { |
||||
return ( |
||||
<Form> |
||||
<FormGroup> |
||||
<Label className="capitalize">Folder Name</Label> |
||||
<Input type="text" onChange={(e) => setFolderName(e.target.value)} /> |
||||
</FormGroup> |
||||
</Form> |
||||
) |
||||
} |
||||
|
||||
|
||||
return ( |
||||
<> |
||||
<Modal isOpen={openDialog} toggle={toggleDialog}> |
||||
<ModalHeader className="capitalize" toggle={closeDialog}>Create New Folder</ModalHeader> |
||||
<ModalBody> |
||||
{renderForm()} |
||||
</ModalBody> |
||||
<ModalFooter> |
||||
<Button color="primary" onClick={() => handleSave()}>Save</Button>{' '} |
||||
<Button className="capitalize" color="secondary" onClick={() => handleCancel()}>Cancel</Button> |
||||
</ModalFooter> |
||||
</Modal> |
||||
</> |
||||
) |
||||
|
||||
} |
||||
|
||||
export default DialogRequestFolder; |
||||
|
Loading…
Reference in new issue