yazid138 vor 3 Jahren
Ursprung
Commit
7efe8c8aee
1 geänderte Dateien mit 7 neuen und 15 gelöschten Zeilen
  1. 7 15
      pages/laporan/new/index.js

+ 7 - 15
pages/laporan/new/index.js

@@ -170,7 +170,7 @@ class App extends Component {
 		}
 	};
 
-	createLaporan = async (token, kode = "", toastid = null) => {
+	createLaporan = async (token, kode = "") => {
 		const data = this.state.data;
 		const formdata = new FormData();
 		formdata.append("pt_id", data.pt_id);
@@ -185,14 +185,13 @@ class App extends Component {
 			});
 		}
 
-		let toastid2 = toastid;
-		if (!toastid) toastid2 = toast.loading("Please wait...");
+		const toastid = toast.loading("Please wait...");
 		const success = await createLaporanPublic(token, formdata);
 		if (!success) {
-			toast.update(toastid2, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
+			toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
 			this.setState({ error: "Kode verifikasi tidak valid" });
 		} else {
-			toast.update(toastid2, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
+			toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
 			this.toggleModal();
 			Router.push("/laporan/new");
 		}
@@ -256,17 +255,11 @@ class App extends Component {
 										}}
 										validationSchema={laporanSchema}
 										onSubmit={async (data) => {
+											this.toggleModal();
 											this.setState({ data, no_hp: data.no_hp });
-											const toastid = toast.loading("Please wait...");
 											const user = await this.createUser(data);
 											const token = user.data.token;
 											this.setState({ user, token });
-											if (user.data.no_hp_aktif) {
-												toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
-												this.toggleModal();
-											} else {
-												await this.createLaporan(token, null, toastid);
-											}
 										}}
 									>
 										<Form className="form-horizontal">
@@ -439,11 +432,10 @@ class App extends Component {
 								<Button
 									color="info"
 									onClick={async () => {
-										this.toggleModal();
-										this.setState({ error: "", kode: "" });
+										await this.createLaporan(this.state.token);
 									}}
 								>
-									Kembali
+									Buat Laporan Tanpa Kode Verifikasi
 								</Button>
 								<Button
 									color="primary"