-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (62 loc) · 2.04 KB
/
Copy pathscript.js
File metadata and controls
71 lines (62 loc) · 2.04 KB
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
const SUPABASE_URL = "https://jerapstpkycmtaiuoovl.supabase.co";
const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImplcmFwc3Rwa3ljbXRhaXVvb3ZsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjU2NDIxMDcsImV4cCI6MjA4MTIxODEwN30.7WPqEF1JXnFlyLClbNE0Sko47AdPqwj9mGVzcNTBSBs";
const supabaseClient = supabase.createClient(
SUPABASE_URL,
SUPABASE_ANON_KEY
);
async function submitForm() {
const name = document.getElementById("name").value.trim();
const phone = document.getElementById("phone").value.trim();
const college = document.getElementById("college").value.trim();
const airport = document.getElementById("airport").value;
const flight = document.getElementById("flight").value.trim();
const date = document.getElementById("date").value;
const share = document.getElementById("share").checked;
const resultDiv = document.getElementById("result");
if (!name || !phone || !airport || !date) {
alert("Please fill all required fields");
return;
}
// Save user
await supabaseClient.from("flight_users").insert([{
name,
phone,
college,
airport,
destination: "Hyderabad",
flight_number: flight || null,
travel_date: date,
share_contact: share
}]);
// Fetch matching users (only opt-in)
const { data, error } = await supabaseClient
.from("flight_users")
.select("name, phone, college")
.eq("airport", airport)
.eq("travel_date", date)
.eq("share_contact", true);
if (error) {
alert("Error fetching data");
return;
}
resultDiv.innerHTML = `
<strong>${data.length} people on your flight</strong>
<div>
${data.map(u => `
<div class="user">
<strong>${u.name}</strong>
${u.college ? `<br/>🎓 ${u.college}` : ""}
<br/>
<a
href="https://wa.me/${u.phone}"
target="_blank"
class="whatsapp-btn"
>
💬 Message on WhatsApp
</a>
</div>
`).join("")}
</div>
`;
resultDiv.classList.remove("hidden");
}