-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckStatus.js
95 lines (95 loc) · 2.93 KB
/
checkStatus.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const api_url = "https://covid-slot-alert.herokuapp.com/";
const api_del = "https://covid-slot-alert.herokuapp.com/delete/";
const phoneNumber = document.getElementById("validation");
phoneNumber.addEventListener("submit", phoneValidation);
function phoneValidation(e) {
e.preventDefault();
const forPhoneRegx = /[6-9]\d{9}/;
const phone = document.getElementById("ph_num").value;
if (phone == "") {
document.getElementById("phoneNumError").innerHTML =
"**please enter your registered phone number";
return false;
} else {
document.getElementById("phoneNumError").innerHTML = "";
}
if (isNaN(phone)) {
document.getElementById("phoneNumError").innerHTML =
"**please enter your valid phone number,characters are not allowed";
return false;
}
if (phone.length > 10 || phone.length < 10) {
document.getElementById("phoneNumError").innerHTML =
"**please enter your valid phone number";
return false;
}
if (phone.match(forPhoneRegx)) {
document.getElementById("phoneNumError").innerHTML = "";
} else {
document.getElementById("phoneNumError").innerHTML =
"**please enter your valid phone number";
return false;
}
phoneCheck(phone);
}
function phoneCheck(phone) {
let getData = "";
fetch(api_url + `search/${phone}`)
.then((Response) => {
return Response.json();
})
.then((data) => {
console.log(data);
if (data.data.length == 0) {
window.location.replace("/errorMassege.html");
} else {
let elements = data.data[0];
let populateData = `<div class="dataBox" >
<table>
<tr>
<th>name</th>
<th>phone</th>
<th>pin</th>
<th>date</th>
</tr>
<tr class="data">
<td>${elements.name}</td>
<td>${elements.phone}</td>
<td>${elements.pin}</td>
<td>${elements.date}</td>
</tr>
</table>
<br><br>
<input class="btn2" type="button" name="reload id="reload" value="check another" onclick="reload()" />
<input class="btn2" type="button" name="delete" id="del" value="Delete Record" onclick="confermDeleteData()" />
</div>
</div>`;
getData = getData + populateData;
document.getElementById("renderField").innerHTML = getData;
}
});
}
function reload() {
window.location.reload();
}
function confermDeleteData() {
var showDiv = document.getElementById("conButton");
showDiv.classList.remove("conferm");
}
function deleteData() {
const ph = document.getElementById("ph_num").value;
fetch(api_del + `${ph}`)
.then((Response) => {
return Response.json();
})
.then((data) => {
console.log(data);
if (data.msg.includes("deleted")) {
window.location.replace("/deleteMsg.html");
}
});
}
function noDeleteData() {
var showDiv = document.getElementById("conButton");
showDiv.classList.add("conferm");
}