瀏覽代碼

perubahan di otp

yazid138 3 年之前
父節點
當前提交
6700fa0ad3
共有 1 個文件被更改,包括 15 次插入7 次删除
  1. 15 7
      pages/laporan/new/index.js

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

@@ -170,7 +170,7 @@ class App extends Component {
 		}
 	};
 
-	createLaporan = async (token, kode = "") => {
+	createLaporan = async (token, kode = "", toastid = null) => {
 		const data = this.state.data;
 		const formdata = new FormData();
 		formdata.append("pt_id", data.pt_id);
@@ -185,13 +185,14 @@ class App extends Component {
 			});
 		}
 
-		const toastid = toast.loading("Please wait...");
+		let toastid2 = toastid;
+		if (!toastid) toastid2 = toast.loading("Please wait...");
 		const success = await createLaporanPublic(token, formdata);
 		if (!success) {
-			toast.update(toastid, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
+			toast.update(toastid2, { render: "All is not good", type: "error", isLoading: false, autoClose: true, closeButton: true });
 			this.setState({ error: "Kode verifikasi tidak valid" });
 		} else {
-			toast.update(toastid, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
+			toast.update(toastid2, { render: "All is good", type: "success", isLoading: false, autoClose: true, closeButton: true });
 			this.toggleModal();
 			Router.push("/laporan/new");
 		}
@@ -255,11 +256,17 @@ 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">
@@ -421,10 +428,11 @@ class App extends Component {
 								<Button
 									color="info"
 									onClick={async () => {
-										await this.createLaporan(this.state.token);
+										this.toggleModal();
+										this.setState({ error: "", kode: "" });
 									}}
 								>
-									Tidak memiliki Kode Verifikasi
+									Kembali
 								</Button>
 								<Button
 									color="primary"