11document . addEventListener ( "DOMContentLoaded" , async ( ) => {
22 const SUPABASE_URL = "https://cvkxtsvgnynxexmemfuy.supabase.co" ;
33 const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImN2a3h0c3ZnbnlueGV4bWVtZnV5Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njc0MjE2NTEsImV4cCI6MjA4Mjk5NzY1MX0.2mys8Cc-ucJ1uLThEGJubeDEg1TvfIAkW-xFsR4ecq4" ;
4+
45 const supabase = window . supabase . createClient ( SUPABASE_URL , SUPABASE_ANON_KEY ) ;
56
67 const form = document . getElementById ( "applyForm" ) ;
@@ -27,15 +28,19 @@ document.addEventListener("DOMContentLoaded", async () => {
2728 const resume = document . getElementById ( "resume" ) . files [ 0 ] ;
2829 const filePath = `${ jobId } /${ Date . now ( ) } _${ resume . name } ` ;
2930
30- // 1. Upload to Storage
31- const { error : uploadError } = await supabase . storage . from ( "resumes" ) . upload ( filePath , resume ) ;
31+ // 1. Upload to Storage - MUST match your dashboard name "RESUMES"
32+ const { error : uploadError } = await supabase . storage . from ( "RESUMES" ) . upload ( filePath , resume ) ;
33+
3234 if ( uploadError ) {
33- messageBox . textContent = "❌ Upload failed." ;
35+ console . error ( "Upload Error:" , uploadError ) ;
36+ messageBox . textContent = "❌ Upload failed: " + uploadError . message ;
3437 return ;
3538 }
3639
37- // 2. Get URL & Insert to Candidates Table
38- const { data : urlData } = supabase . storage . from ( "resumes" ) . getPublicUrl ( filePath ) ;
40+ // 2. Get Public URL
41+ const { data : urlData } = supabase . storage . from ( "RESUMES" ) . getPublicUrl ( filePath ) ;
42+
43+ // 3. Insert to Candidates Table
3944 const { error : insertError } = await supabase . from ( "candidates" ) . insert ( {
4045 full_name : document . getElementById ( "name" ) . value ,
4146 email : document . getElementById ( "email" ) . value ,
@@ -45,9 +50,10 @@ document.addEventListener("DOMContentLoaded", async () => {
4550 } ) ;
4651
4752 if ( insertError ) {
48- messageBox . textContent = "❌ Database Error." ;
53+ console . error ( "DB Error:" , insertError ) ;
54+ messageBox . textContent = "❌ Database Error: " + insertError . message ;
4955 } else {
50- messageBox . textContent = "✅ Success!" ;
56+ messageBox . textContent = "✅ Success! Application submitted. " ;
5157 form . reset ( ) ;
5258 }
5359 } ) ;
0 commit comments