-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: change firebase api syntax to typescript
- Loading branch information
1 parent
277fc50
commit 963576a
Showing
4 changed files
with
199 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {firebaseConfig} from '$lib/firebaseConfig' | ||
import {initializeApp} from 'firebase/app' | ||
import {Firestore, getFirestore, collection, addDoc} from 'firebase/firestore' | ||
|
||
let firebaseApp | ||
let db: Firestore | ||
|
||
if (!firebaseApp) { | ||
firebaseApp = initializeApp(firebaseConfig) | ||
} | ||
|
||
// Initialize Firestore | ||
db = getFirestore() | ||
|
||
interface FormData { | ||
name: string | ||
email: string | ||
occupation: string | ||
work: string | ||
message: string | ||
} | ||
|
||
export const saveFormData = async (formData: FormData) => { | ||
try { | ||
const collectionRef = collection(db, 'registrant') | ||
await addDoc(collectionRef, formData) | ||
console.log('Form data saved to Firestore') | ||
} catch (error) { | ||
console.error('Error saving form data to Firestore:', error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.