Commit 29ffc9df authored by muhammad ridwan's avatar muhammad ridwan

Merge branch 'ENV-DEV-CR-CAFRM' into 'ENV-DEPLOYMENT'

Env dev cr cafrm

See merge request !1589
parents b6567423 3c445104
......@@ -8,7 +8,6 @@ import ReactTooltip from 'react-tooltip';
import api from '../../api';
import PropagateLoader from "react-spinners/PropagateLoader"
import TableDocument from "./TableDocument";
import PopUpKonfirmasi from "../DocumentManagement/PopUpKonfirmasi";
import CreateCarfmDoc from "./CreateCarfmDoc";
const Alert = withStyles({})((props) => <MuiAlert elevation={6} variant="filled" {...props} />);
......@@ -198,53 +197,18 @@ export default class CarfmDocument extends Component {
})
}
async createUploadDocument() {
this.setState({ visibleCreate: false, konfirmasi: false })
const formData = this.state.formData
formData.append("documentId", this.state.docId)
formData.append("updated", 1)
this.setState({ loading: true })
await api.create().updateDocument(formData).then(response => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.status === "success") {
this.getDataDocument(this.state.settingID, this.state.menuName)
this.setState({ konfirmasi: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success', visibleCreate: false, loading: false })
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
}, 1000);
}
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
async createDocument(payload) { //upload apinya disini
this.setState({ loading: true })
await api.create().uploadCarfmDocument(payload).then(response => {
// console.log(response)
if (response.data) {
if (response.ok) {
if (response.data.message === "The Document Already Exists in The System, Do You Want to Overwrite It?") {
this.setState({ konfirmasi: true, formData: payload, docId: response.data.data.document_id, loading: false })
}
else if (response.data.message === "Data was Saved Successfully") {
this.getDataCarfm('create')
if (response.data.message === "Data was Saved Successfully") {
this.setState({ visibleCreate: false, loading: false, alert: true, messageAlert: response.data.message, tipeAlert: 'success'})
this.getDataCarfm('create')
}
else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
this.setState({ visibleCreate: false, alert: true, messageAlert: response.data.message, tipeAlert: 'warning', loading: false }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
setTimeout(() => {
localStorage.removeItem(Constant.TOKEN)
......@@ -254,10 +218,10 @@ export default class CarfmDocument extends Component {
})
}
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
this.setState({ visibleCreate: false, alert: true, messageAlert: response.data.message, tipeAlert: 'error', loading: false })
}
} else {
this.setState({ alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
this.setState({ visibleCreate: false, alert: true, messageAlert: response.problem, tipeAlert: 'error', loading: false })
}
})
}
......@@ -359,19 +323,12 @@ export default class CarfmDocument extends Component {
)}
</div>
{this.state.konfirmasi && (
<PopUpKonfirmasi
onClickClosePopUp={() => this.setState({ konfirmasi: false })}
uploadDocId={this.createUploadDocument.bind(this)}
/>
)}
{this.state.visibleCreate && (
<CreateCarfmDoc
onClickClose={() => this.setState({ visibleCreate: false })}
// getDataDocument={this.getDataDocument.bind(this)}
createDocument={this.createDocument.bind(this)}
handleLoading={this.handleLoading.bind(this)}
allsubcoCreate={this.state.btnadd}
submenu_id={this.state.submenu_id}
/>
)}
......
......@@ -19,7 +19,6 @@ export default class CreateCarfmDoc extends Component {
super(props)
this.state = {
perusahaan: null,
perusahaanData: null,
getPerusahaan: null,
errorPerusahaan: false,
msgErrorPerusahaan: '',
......@@ -44,12 +43,11 @@ export default class CreateCarfmDoc extends Component {
tipeAlert: '',
messageAlert: '',
fileType: '',
konfirmasi: false,
docId: '',
sizeUpload: "1",
disabledPeriode: false,
menuName: null,
saveDisable: false
saveDisable: false,
submitVal: 0
}
}
......@@ -111,10 +109,10 @@ export default class CreateCarfmDoc extends Component {
// company_name: 'Default'
// })
let typeProps = {
options: typeData.sort((a, b) => a.company_name - b.company_name),
options: typeData.sort((a, b) => a.company_name.localeCompare(b.company_name)),
getOptionLabel: (option) => option.company_name,
};
this.setState({ perusahaan: typeProps, perusahaanData: response.data.data })
this.setState({ perusahaan: typeProps}, () => console.log(this.state.perusahaan))
} else {
this.setState({ alert: true, messageAlert: response.data.message, tipeAlert: 'warning' }, () => {
if (response.data.message.includes("Someone Logged In") || response.data.message.includes("Token Expired")) {
......@@ -252,30 +250,6 @@ export default class CreateCarfmDoc extends Component {
}
validasi() {
if (this.state.disabledPeriode === true) {
if (R.isNil(this.state.file)) {
this.setState({ alert: true, messageAlert: 'File Cannot be Empty', tipeAlert: 'warning', saveDisable: false })
} else {
const formData = new FormData();
formData.append("file", this.state.file);
formData.append("companyId", 1);
formData.append("submenuId", this.props.submenu_id);
formData.append("description", this.state.description);
formData.append("extension", this.state.fileType);
formData.append("documentPeriode", null);
formData.append("documentMonth", null);
this.setState({ formData }, () => {
this.props.createDocument(this.state.formData)
})
var object = {};
formData.forEach(function (value, key) {
object[key] = value;
});
var json = JSON.stringify(object);
// console.log(object)
}
} else {
if (R.isNil(this.state.getPerusahaan)) {
this.setState({ errorPerusahaan: true, msgErrorPerusahaan: 'Company Cannot be Empty', saveDisable: false })
}else if (R.isNil(this.state.periode)) {
......@@ -285,7 +259,7 @@ export default class CreateCarfmDoc extends Component {
}
else if (R.isNil(this.state.file)) {
this.setState({ alert: true, messageAlert: 'File Cannot be Empty', tipeAlert: 'warning', saveDisable: false })
} else {
} else if(this.state.submitVal === 1) {
const formData = new FormData();
formData.append("file", this.state.file);
formData.append("companyId", this.state.getPerusahaan.company_id);
......@@ -298,7 +272,6 @@ export default class CreateCarfmDoc extends Component {
this.props.createDocument(this.state.formData, )
})
}
}
this.props.handleLoading(0)
}
......@@ -343,7 +316,6 @@ export default class CreateCarfmDoc extends Component {
</div>
<div className="grid grid-2x grid-mobile-none gap-15px" style={{ paddingLeft: 20, paddingRight: 20, paddingTop: 20 }}>
{this.state.disabledPeriode === false ?
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
......@@ -363,7 +335,6 @@ export default class CreateCarfmDoc extends Component {
/>
</div>
</div>
: true}
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5, marginTop: "1.2em" }}>
......@@ -379,7 +350,6 @@ export default class CreateCarfmDoc extends Component {
</div>
</div>
{this.state.disabledPeriode === false ?
<div className="column-1">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
......@@ -400,8 +370,7 @@ export default class CreateCarfmDoc extends Component {
/>
</div>
</div>
: true}
{this.state.disabledPeriode === false ?
<div className="column-2">
<div style={{ padding: 10, borderRadius: 5 }}>
<Autocomplete
......@@ -422,7 +391,6 @@ export default class CreateCarfmDoc extends Component {
/>
</div>
</div>
: true}
</div>
<div style={{ paddingLeft: 30, paddingRight: 30, paddingTop: 10 }}>
<UploadFile
......@@ -491,10 +459,12 @@ export default class CreateCarfmDoc extends Component {
type="button"
onClick={() =>
{
this.props.handleLoading(1);
this.setState({
saveDisable: true
});
saveDisable: true,
submitVal : this.state.submitVal + 1
}, console.log());
this.props.handleLoading(1);
setTimeout(() => {
this.validasi()
console.log("vlidasi " + this.validasi());
......
......@@ -44,7 +44,6 @@ export default class CreateManagementDoc extends Component {
tipeAlert: '',
messageAlert: '',
fileType: '',
konfirmasi: false,
docId: '',
sizeUpload: "1",
disabledPeriode: false
......
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