feat: implement review submission functionality and update reviews API
This commit is contained in:
1007
src/App.tsx
1007
src/App.tsx
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,20 @@
|
|||||||
import { db } from '../firebase';
|
import { db } from '../firebase';
|
||||||
import { collection, getDocs, addDoc, Timestamp } from 'firebase/firestore';
|
import { collection, getDocs, addDoc } from 'firebase/firestore';
|
||||||
|
|
||||||
export type Review = {
|
export type Review = {
|
||||||
id?: string;
|
|
||||||
name: string;
|
name: string;
|
||||||
message: string;
|
|
||||||
rating: number;
|
rating: number;
|
||||||
createdAt?: Timestamp;
|
position: string;
|
||||||
|
text: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const reviewsCollection = collection(db, 'reviews');
|
const reviewsCollection = collection(db, 'reviews');
|
||||||
|
|
||||||
export async function fetchReviews(): Promise<Review[]> {
|
export async function fetchReviews(): Promise<Review[]> {
|
||||||
const snapshot = await getDocs(reviewsCollection);
|
const snapshot = await getDocs(reviewsCollection);
|
||||||
return snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() } as Review));
|
return snapshot.docs.map(doc => doc.data() as Review);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addReview(review: Omit<Review, 'id' | 'createdAt'>): Promise<void> {
|
export async function addReview(review: Review): Promise<void> {
|
||||||
await addDoc(reviewsCollection, {
|
await addDoc(reviewsCollection, review);
|
||||||
...review,
|
|
||||||
createdAt: Timestamp.now(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user