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